Posted By : Vishal
Introduction: Stellar is a decentralized open-source blockchain network that provides a platform for the exchange of currencies over the globe. On Stellar Network you can build banking applications, mobile wallets, and any other application that involves transactions. Some of the important components of Stellar Network are as follows.
API Horizon: It is a RESTful API server through which applications can connect to the Stellar Network. Horizon provides API through which can be used by developers to connect to the Network directly. Currently, Stellar.org provide the JavaScript, Go, and Java SDKs to connect with Horizon, also some other SDKs are maintained by the community like Ruby, Python, and C#.
Stellar Core: It is the backbone of Network. Every Horizon connects to the core behind the scenes. Complete Network is the collection of Core some are connected with Horizon while others are used to provide reliability to the Network. All the complex tasks are handled by these COREs.
Assets: Network can be used to hold any currency like BTC, Ether, Dollar, etc. Any asset can be traded with another asset. All the assets have asset type and issuer. Any account on Stellar can issue an asset and these accounts are called Anchors.
There are various SDKs provided by Stellar in this blog we will JS SDK to create an account and create transaction. This SDK can be used on browser or Node.JS
Step 1: Install SDK and require it in Application.
// Run in project directory inside the terminal
sudo npm i stellar-sdk
// Require it in Application.
var StellarSdk = require("stellar-sdk");
const fetch = require('node-fetch');
var server = new StellarSdk.Server("https://horizon-testnet.stellar.org"); //To connect with test horizon
Step 2: Create account on Stellar. Unlike other blockchains you need to maintain some minimum balance on the account i.e. 2 Lumens.
const pair = StellarSdk.Keypair.random();
pair.secret();
pair.publicKey();
// After create key pair fund them with some Lumens
(async function main() {
try {
const response = await fetch(
`https://friendbot.stellar.org?addr=${encodeURIComponent(
pair.publicKey(),
)}`,
);
const responseJSON = await response.json();
console.log("SUCCESS! You have a new account :)\n");
server.loadAccount(pair.publicKey()).then(function(sucess){console.log("Success ",sucess)
console.log("Public key: "+pair.publicKey()+" Secret: "+pair.secret());
}).catch(error=>{console.log("error",error)});
} catch (e) {
console.error("ERROR!", e);
}
})();
Step 3: Send Transaction on Stellar.
Conclusion: In this blog, we get the overview of the Stellar blockchain and get a hand on it Js SDK how it can be used in Application.
September 8, 2024 at 02:27 am
Your comment is awaiting moderation.