facebook

A Complete Guide on How to Create SPL Tokens on Solana

Posted By : Mohd

Jan 04, 2024

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.

 

SPL Token Development

 

Prerequisites:

 

  • Node.js and npm: Ensure that you have Node.js and npm installed on your machine.
  • Solana Wallet: You'll need a Solana wallet to interact with the blockchain. Example - Phantom.
  • Code Editor: Choose a code editor of your choice. Example - VS Code.

 

Getting Started:

 

Follow the instructions below to create your own SPL tokens on Solana:

 

  • Initialize a Node.js Project: 


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 Required Packages: 


Install the necessary npm packages for interacting with the Solana blockchain

 

npm install @solana/web3.js @solana/spl-token bs58

 

  • Write token creation script:


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

 

Conclusion:

 

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. 

Leave a

Comment

Name is required

Invalid Name

Comment is required

Recaptcha is required.

blog-detail

December 2, 2024 at 08:06 pm

Your comment is awaiting moderation.

By using this site, you allow our use of cookies. For more information on the cookies we use and how to delete or block them, please read our cookie notice.

Chat with Us
Telegram Button
Youtube Button

Contact Us

Oodles | Blockchain Development Company

Name is required

Please enter a valid Name

Please enter a valid Phone Number

Please remove URL from text