Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

solana solana-Web3.js change for devnet lamports to production transaction

import * as web3 from "@solana/web3.js";
import * as splToken from "@solana/spl-token";

// Address: 9vpsmXhZYMpvhCKiVoX5U8b1iKpfwJaFpPEEXF7hRm9N
const DEMO_WALLET_SECRET_KEY = new Uint8Array([
  37, 21, 197, 185, 105, 201, 212, 148, 164, 108, 251, 159, 174, 252, 43, 246,
  225, 156, 38, 203, 99, 42, 244, 73, 252, 143, 34, 239, 15, 222, 217, 91, 132,
  167, 105, 60, 17, 211, 120, 243, 197, 99, 113, 34, 76, 127, 190, 18, 91, 246,
  121, 93, 189, 55, 165, 129, 196, 104, 25, 157, 209, 168, 165, 149,
]);
(async () => {
  // Connect to cluster
  var connection = new web3.Connection(web3.clusterApiUrl("devnet"));
  // Construct wallet keypairs
  var fromWallet = web3.Keypair.fromSecretKey(DEMO_WALLET_SECRET_KEY);
  var toWallet = web3.Keypair.generate();
  // Construct my token class
  var myMint = new web3.PublicKey("My Mint Public Address");
  var myToken = new splToken.Token(
    connection,
    myMint,
    splToken.TOKEN_PROGRAM_ID,
    fromWallet
  );
  // Create associated token accounts for my token if they don't exist yet
  var fromTokenAccount = await myToken.getOrCreateAssociatedAccountInfo(
    fromWallet.publicKey
  )
  var toTokenAccount = await myToken.getOrCreateAssociatedAccountInfo(
    toWallet.publicKey
  )
  // Add token transfer instructions to transaction
  var transaction = new web3.Transaction()
    .add(
      splToken.Token.createTransferInstruction(
        splToken.TOKEN_PROGRAM_ID,
        fromTokenAccount.address,
        toTokenAccount.address,
        fromWallet.publicKey,
        [],
        0
      )
    );
  // Sign transaction, broadcast, and confirm
  var signature = await web3.sendAndConfirmTransaction(
    connection,
    transaction,
    [fromWallet]
  );
  console.log("SIGNATURE", signature);
  console.log("SUCCESS");
})();
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to place text input cursor to start in react native 
Javascript :: filter syntax 
Javascript :: get moment from another moment 
Javascript :: cypher neo4j 
Javascript :: get form control value in angular 8 
Javascript :: props with ternary in react 
Javascript :: how to save js object to clipboard 
Javascript :: jquery: return true or false if the element is present in the DOM or not 
Javascript :: random height fallling object in js 
Javascript :: history go back js oneline 
Javascript :: @testing-library/react-native switch 
Javascript :: rebuild package-lock.json 
Javascript :: unexpected token useeffect react native 
Javascript :: how to add,delete,update property in javascript object 
Javascript :: add multiple parameters js 
Javascript :: Subscription field must return Async Iterable. Received: undefined. 
Javascript :: Merge Arrarys of Object of Any size 
Javascript :: browser console unhide element 
Javascript :: jQuery form upload 
Javascript :: Timestamp Format: 23.12.2015 08:34:50 
Javascript :: object.keys map 
Javascript :: hover inline css 
Javascript :: how to refrence schema in my mongoose schema with populate function 
Javascript :: dynamic copyright year JavaScript centre aligned 
Javascript :: shorten req.body. function 
Javascript :: jquery show div class 
Javascript :: kasthamandap college 
Javascript :: imleç 
Javascript :: how to create a tag object in jQuery 
Javascript :: How to Use the Return Keyword in a Function 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =