Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Solana SPL Token JavaScript library mint function

const web3 =  require('@solana/web3.js');
const splToken = require('@solana/spl-token');

(async () => {

    //create connection to devnet
    const connection = new web3.Connection(web3.clusterApiUrl("devnet"));

    //generate keypair and airdrop 1000000000 Lamports (1 SOL)
    const myKeypair = web3.Keypair.generate();
    await connection.requestAirdrop(myKeypair.publicKey, 1000000000);

    console.log('solana public address: ' + myKeypair.publicKey.toBase58());

    //set timeout to account for airdrop finalization
    let mint;
    var myToken
    setTimeout(async function(){ 

        //create mint
        mint = await splToken.Token.createMint(connection, myKeypair, myKeypair.publicKey, null, 9, splToken.TOKEN_PROGRAM_ID)

        console.log('mint public address: ' + mint.publicKey.toBase58());

        //get the token accont of this solana address, if it does not exist, create it
        myToken = await mint.getOrCreateAssociatedAccountInfo(
            myKeypair.publicKey
        )

        console.log('token public address: ' + myToken.address.toBase58());

        //minting 100 new tokens to the token address we just created
        await mint.mintTo(myToken.address, myKeypair.publicKey, [], 1000000000);

        console.log('done');

    }, 20000);

})();
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to get 4 columns with masonryjs 
Javascript :: how do i make http post in nodejs without third party 
Javascript :: koa wildcard route 
Javascript :: upload image in react next js authentication 
Javascript :: Uncaught TypeError: document.getElementsByClassName(...).style is undefined 
Javascript :: desctructuring in react with aliases 
Javascript :: automatic color change 
Javascript :: change teh value of a slider p5js 
Javascript :: How To Start Any Program In Background Using Vbscript 
Javascript :: promtail +verbose 
Javascript :: Subhasis Just search 
Javascript :: showing error for few seconds react 
Javascript :: Using Intl.NumberFormat() to Print JavaScript Number Format with Commas 
Javascript :: Block Alignment Toolbar Using ES5 in Wordpress 
Javascript :: How to get element margin in React 
Javascript :: Async functions and execution order 
Javascript :: isFinite(): returns true if the number is not Infinity or -Infinity 
Javascript :: Parents, Children & Siblings 
Javascript :: //testing 
Javascript :: easyui datagrid scrollto 
Javascript :: Javascripttrepeat 
Javascript :: {"javascript error: Invalid or unexpected token c# selenium 
Javascript :: does script defer keep order 
Javascript :: react Update a label when rate moves 
Javascript :: AJAX XML - update new live data and prevent returning old chache data 
Javascript :: javascripts 
Javascript :: Webpack: How to compile, write on disk and serve static content (js/css/html/assets) using webpack-dev-server 
Javascript :: how to change a react link icon when you send the link as message in whatsapp 
Javascript :: VueJS - getting the last element of a split string array 
Javascript :: convert string or string array to object mongoose object id 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =