Posted By : Mohd
Solana, with its high throughput and low transaction costs, has emerged as a prominent blockchain for developing decentralized applications using Solana blockchain development services. The Solana Program Library (SPL) facilitates the creation of various tokens, from fungible to non-fungible assets. In this blog, we will explore how to create SPL tokens on Solana using JavaScript.
Follow the instructions below to create your own SPL tokens on Solana:
Create a new Node.js project for creating your spl-token by running the following commands in your terminal:
mkdir solana-spl-token
cd solana-spl-token
npm init -y
You may also like | Creating a Staking Smart Contract on Solana using Anchor
Install the necessary npm packages for interacting with the Solana blockchain
npm install @solana/web3.js @solana/spl-token bs58
Connect to a solana cluster.
const connection = new Connection(
'https://api.devnet.solana.com',
'confirmed'
);
Add your wallet's secret key which will be used to create the token and pay for the network and transaction costs (your wallet needs to have SOL for the network fees).
const privateKey = "˜';
const walletKeypair = Keypair.fromSecretKey(
new Uint8Array(bs58.decode(privateKey))
);
Create a new SPL token using the "createMint" function provided by @solana/spl-token library. We are setting the mint authority and freeze authority of the token to the wallet whose secret key is used above.
const mint = await createMint(
connection,
walletKeypair, // payer
walletKeypair.publicKey, // mint authority
walletKeypair.publicKey, // freeze authority
9 // Decimals for the token
);
Run this command and execute the code to create your SPL token:
node createToken.js
Below is the output:
SPL Token created successfully!
Token Public Key: Ej1vq1r1y6ChmqX4fLri4ZJKG32RQzc3CiHYcPWZDL6Z
Also, Read | What Makes Solana Blockchain Development Stand Out
You have successfully created SPL tokens on the Solana blockchain. This guide serves as a starting point, and you can further customize your token creation script based on your project requirements. You can find the whole code for this blog post here.
If you are looking to develop dAapps, NFT, or deFi projects on Solana blockchain, our solana developers can assist you with the most efficient development services.
December 2, 2024 at 08:06 pm
Your comment is awaiting moderation.