1

Hello i need to write a program that transfer token from my wallet to another wallet i wrote here is code

const {clusterApiUrl, Connection, Keypair, LAMPORTS_PER_SOL, PublicKey} =  require('@solana/web3.js');
const  {createMint, getOrCreateAssociatedTokenAccount, mintTo, transfer} = require('@solana/spl-token');
const bs58 = require("bs58");
(async () => {
    // Connect to cluster
    const connection = new Connection(clusterApiUrl('devnet'), 'confirmed');
    const DEMO_WALLET_SECRET_KEY = new bs58.decode("<My Private Key>");

    const fromWallet =  Keypair.fromSecretKey(DEMO_WALLET_SECRET_KEY);;
     
    const toWallet = new PublicKey('<Destination Wallet Address>');

    // Create new token mint
   
    const mint = new PublicKey('<My Mint Account Address');
   
   // Get the token account of the fromWallet address, and if it does not exist, create it
        const fromTokenAccount = await getOrCreateAssociatedTokenAccount(
            connection,
            fromWallet,
            mint,
            fromWallet.publicKey
        );
    console.log(fromTokenAccount);
    //     // Get the token account of the toWallet address, and if it does not exist, create it
        const toTokenAccount = await getOrCreateAssociatedTokenAccount(connection, fromWallet, mint, toWallet);
    
    
        // Transfer the new token to the "toTokenAccount" we just created
        signature = await transfer(
            connection,
            fromWallet,
            fromTokenAccount.address,
            toTokenAccount.address,
            fromWallet.publicKey,
            100000000
        );
    })();

it works fine but for a coin that i made according to this document

and it doesn't works for coin i made according to official document !
when i use mint address of that coin i get bellow error enter image description here

please help me and tell my why i have this problem because i would like to make my token according to official document,thanks.

1 Answer 1

1

The Official guide that you provided uses the Token extensions program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA to mint the token.

Change the programId where neccessary to point to it TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA

e.g in the transfer TX

   let signature = await transfer(
            connection,
            fromWallet,
            fromTokenAccount.address,
            toTokenAccount.address,
            fromWallet.publicKey,
            100000000,
            [],
            {},
            new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
        );

and the get or create function

let toTokenAccount = await (
        await getOrCreateAssociatedTokenAccount(
            conn,
            signer,
            mint,
            signer.publicKey,
            false,
            "finalized",
            {},
            new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
        )
    ).address;
3
  • i added but still have that problem
    – Hich
    Commented Jun 24 at 17:55
  • and i get error from fromTokenAccount not transfer
    – Hich
    Commented Jun 24 at 18:10
  • I fond out know error is from both
    – Hich
    Commented Jun 24 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.