0

我们有一笔交易将 SOL 和 NFT 从钱包所有者转移到我们的钱包。交易包含简单的指令:

  1. Token.createAssociatedTokenAccountInstruction
    Conditionnal,取决于目的地(我们的钱包)
  2. Token.createTransferInstruction 从所有者的令牌帐户转移到我们的令牌帐户。
  3. SystemProgram.transfer SOL 传输。

这是转账代码(spl-token v0.1.8)

let createTransferInstructions = async function (mint, from, to, cluster) {
    let connection = new Connection(cluster, "confirmed")

    const mintPublicKey  = new PublicKey(mint);
    const ownerPublicKey = new PublicKey(from);
    const destPublicKey  = new PublicKey(to);
    

    // GET SOURCE ASSOCIATED ACCOUNT
    const associatedSourceTokenAddr = await Token.getAssociatedTokenAddress(
        ASSOCIATED_TOKEN_PROGRAM_ID,
        TOKEN_PROGRAM_ID,
        mintPublicKey,
        ownerPublicKey
    );
    
    // GET DESTINATION ASSOCIATED ACCOUNT
    const associatedDestinationTokenAddr = await Token.getAssociatedTokenAddress(
        ASSOCIATED_TOKEN_PROGRAM_ID,
        TOKEN_PROGRAM_ID,
        mintPublicKey,
        destPublicKey
    );

    const receiverAccount = await connection.getAccountInfo(associatedDestinationTokenAddr);

    const instructions = [];

    if (receiverAccount === null)
        instructions.push(
            Token.createAssociatedTokenAccountInstruction(
                ASSOCIATED_TOKEN_PROGRAM_ID,
                TOKEN_PROGRAM_ID,
                mintPublicKey,
                associatedDestinationTokenAddr,
                destPublicKey,
                ownerPublicKey
            )
        )

    instructions.push(
        Token.createTransferInstruction(
            TOKEN_PROGRAM_ID,
            associatedSourceTokenAddr,
            associatedDestinationTokenAddr,
            ownerPublicKey,
            [],
            1
        )
    );

    return instructions;
}

这是交易代码:

var transaction = new this.solana.Transaction({
   feePayer: new this.solana.PublicKey(from),
   recentBlockhash: await blockhashObj.blockhash
});

for (let transferInstruction of transferInstructions) {
   transaction.add(transferInstruction);
}

transaction.add(this.solana.SystemProgram.transfer({
   fromPubkey: new this.solana.PublicKey(this.provider.publicKey),
   toPubkey: new this.solana.PublicKey(farm.address),
   lamports: 10000000 
}));

所有者必须使用他们的钱包(phantom、solflare 等)验证交易。
对于大多数 NFT,一切都很好。

一些 NFT 所有者抱怨无法在钱包上验证交易,错误消息表明无法确认交易。

但是,NFT 可以通过钱包界面成功转移,可以在市场上上市等。即使将 NFT 转移到另一个钱包,上述交易也可以完美运行。

我想知道这是否与关联的令牌帐户有关?如果是这样,解决方案是什么?

4

0 回答 0