Nicholas Laverty
Nicholas Laverty

Reputation: 39

Transferring SPL Token using @Solana\web3.js

I am trying to transfer SPL tokens and am getting the error from the function mintToken.getOrCreateAssociatedAccountInfo(wallet.publicKey);

Error: Invalid seeds, address must fall off the curve

My wallet variable a an AnchorWallet

ToWallet is obtained via:

var toWallet = anchor.web3.Keypair.fromSecretKey(DEMO_TO_WALLET);

 try {
    if (wallet) {
      const mintPublicKey = new anchor.web3.PublicKey("Token address");    
      const mintToken = new Token(
        props.connection,
        mintPublicKey,
        TOKEN_PROGRAM_ID,
        toWallet 
      );

      const fromTokenAccount = await mintToken.getOrCreateAssociatedAccountInfo(
        wallet.publicKey
      );
    
      const destPublicKey = new anchor.web3.PublicKey(toWallet);
    
      // Get the derived address of the destination wallet which will hold the custom token
      const associatedDestinationTokenAddr = await Token.getAssociatedTokenAddress(
        mintToken.associatedProgramId,
        mintToken.programId,
        mintPublicKey,
        destPublicKey
      );
    
      const receiverAccount = await props.connection.getAccountInfo(associatedDestinationTokenAddr);
            
      const instructions: anchor.web3.TransactionInstruction[] = [];  
    
      if (receiverAccount === null) {
    
        instructions.push(
          Token.createAssociatedTokenAccountInstruction(
            mintToken.associatedProgramId,
            mintToken.programId,
            mintPublicKey,
            associatedDestinationTokenAddr,
            destPublicKey,
            wallet.publicKey
          )
        )
    
      }
      
      instructions.push(
        Token.createTransferInstruction(
          TOKEN_PROGRAM_ID,
          fromTokenAccount.address,
          associatedDestinationTokenAddr,
          wallet.publicKey,
          [],
          1
        )
      );
    
      const transaction = new anchor.web3.Transaction().add(...instructions);
      transaction.feePayer = wallet.publicKey;
      transaction.recentBlockhash = (await props.connection.getRecentBlockhash()).blockhash;
      
      const transactionSignature = await props.connection.sendRawTransaction(
        transaction.serialize(),
        { skipPreflight: true }
      );
    
      await props.connection.confirmTransaction(transactionSignature);

Upvotes: 1

Views: 3260

Answers (1)

rainbowemoji
rainbowemoji

Reputation: 188

Please ensure that wallet.publicKey contains valid value.

console.log(wallet.publicKey);//I think this might be an empty string.

const fromTokenAccount = await mintToken.getOrCreateAssociatedAccountInfo(
        wallet.publicKey
      );

Upvotes: 1

Related Questions