Equivalent code in JS
-
Create a new cli wallet
solana-keygen new -
Set the RPC url
solana config set --url https://api.devnet.solana.com -
Create an empty JS file
npm init -ytouch index.js -
Install dependencies
npm install @solana/web3.js @solana/spl-token -
Write a function to airdrop yourself some solana
const {Connection, LAMPORTS_PER_SOL, clusterApiUrl, PublicKey} = require('@solana/web3.js');const connection = new Connection(clusterApiUrl('devnet'));async function airdrop(publicKey, amount) {const airdropSignature = await connection.requestAirdrop(new PublicKey(publicKey), amount);await connection.confirmTransaction({signature: airdropSignature})}airdrop("GokppTzVZi2LT1MSTWoEprM4YLDPy7wQ478Rm3r77yEw", LAMPORTS_PER_SOL).then(signature => {console.log('Airdrop signature:', signature);}); -
Check your balance
solana balance -
Create token mint
const { createMint } = require('@solana/spl-token');const { Keypair, Connection, clusterApiUrl, TOKEN_PROGRAM_ID } = require('@solana/web3.js');const payer = Keypair.fromSecretKey(Uint8Array.from([102,144,169,42,220,87,99,85,100,128,197,17,41,234,250,84,87,98,161,74,15,249,83,6,120,159,135,22,46,164,204,141,234,217,146,214,61,187,254,97,124,111,61,29,54,110,245,186,11,253,11,127,213,20,73,8,25,201,22,107,4,75,26,120]));const mintAthority = payer;const connection = new Connection(clusterApiUrl('devnet'));async function createMintForToken(payer, mintAuthority) {const mint = await createMint(connection,payer,mintAuthority,null,6,TOKEN_PROGRAM_ID);console.log('Mint created at', mint.toBase58());return mint;}async function main() {const mint = await createMintForToken(payer, mintAthority.publicKey);}main(); -
Verify token mint on chain
-
Check the token on solana fm https://solana.fm/address/ChNkv9iW5pZJ1YAsNswC2CrdMUkFJBUbRWinjdLvKpXA/transactions?cluster=devnet-solana
-
Use the
getAccountInfo
to see thedata
andlamports
in the account
-
-
Create an associated token account, mint some tokens
const { createMint, getOrCreateAssociatedTokenAccount, mintTo } = require('@solana/spl-token');const { Keypair, Connection, clusterApiUrl, TOKEN_PROGRAM_ID, PublicKey } = require('@solana/web3.js');const payer = Keypair.fromSecretKey(Uint8Array.from([102,144,169,42,220,87,99,85,100,128,197,17,41,234,250,84,87,98,161,74,15,249,83,6,120,159,135,22,46,164,204,141,234,217,146,214,61,187,254,97,124,111,61,29,54,110,245,186,11,253,11,127,213,20,73,8,25,201,22,107,4,75,26,120]));const mintAthority = payer;const connection = new Connection(clusterApiUrl('devnet'));async function createMintForToken(payer, mintAuthority) {const mint = await createMint(connection,payer,mintAuthority,null,6,TOKEN_PROGRAM_ID);console.log('Mint created at', mint.toBase58());return mint;}async function mintNewTokens(mint, to, amount) {const tokenAccount = await getOrCreateAssociatedTokenAccount(connection,payer,mint,new PublicKey(to));console.log('Token account created at', tokenAccount.address.toBase58());await mintTo(connection,payer,mint,tokenAccount.address,payer,amount)console.log('Minted', amount, 'tokens to', tokenAccount.address.toBase58());}async function main() {const mint = await createMintForToken(payer, mintAthority.publicKey);await mintNewTokens(mint, mintAthority.publicKey, 100);}main(); -
Check your balances in the explorer
-
Import the token in Phantom and see the balances