1

I minted an NFT from a Candy Machine, and I want to transfer it to another wallet, but I'm not sure how to generate the Token object in order to do a transfer.

import { Keypair, Connection, clusterApiUrl, PublicKey } from '@solana/web3.js';
import splToken from "@solana/spl-token";

const connection = new Connection(clusterApiUrl('devnet')); 
const secretKey = new Uint8Array([...])
const fromWallet = Keypair.fromSecretKey(secretKey);

var myToken = new splToken.Token(
    connection,
    publicKey, // What address do I use here?
    TOKEN_METADATA_PROGRAM_ID,
    fromWallet
);

I keep getting this error, and I'm not sure what public key I'm supposed to use. I assumed it's the address of the token, but nothing I try works.

TypeError: Cannot read properties of undefined (reading 'Token')
Berry Blue
  • 15,330
  • 18
  • 62
  • 113

1 Answers1

1

I suspect this is a versionning issue. Recent versions of @solana/spl-token don't have the Token class anymore.

You can use the createTransferInstruction instruction directly https://github.com/solana-labs/solana-program-library/blob/master/token/js/src/instructions/transfer.ts#L35

dr497
  • 474
  • 2
  • 3