我正在尝试将代币从一个 Solana 地址转移到另一个地址,虽然我能够提示数据,但金额始终为空白。
通过许多调整和更改,金额似乎保持为空。如果我不包括金额,则不会出现该行,但是当我这样做时,就不会显示任何金额。
function writeBigU_Int64LE(buf, value, offset, min, max) {
let lo = Number(value & BigInt('0xffffffff'))
buf[offset++] = lo
lo = lo >> 8
buf[offset++] = lo
lo = lo >> 8
buf[offset++] = lo
lo = lo >> 8
buf[offset++] = lo
let hi = Number((value >> BigInt(32)) & BigInt('0xffffffff'))
buf[offset++] = hi
hi = hi >> 8
buf[offset++] = hi
hi = hi >> 8
buf[offset++] = hi
hi = hi >> 8
buf[offset++] = hi
return offset
}
let AMOUNT = BigInt(1000)
const b = buffer.Buffer.alloc(10)
b.writeUInt8(3, 0)
writeBigU_Int64LE(b, AMOUNT, 1, BigInt(0), BigInt('0xffffffffffffffff'))
const instruction = new solanaWeb3.TransactionInstruction({
keys: [
{ pubkey: token, isSigner: false, isWritable: true },
{ pubkey: provider.publicKey, isSigner: false, isWritable: true },
{ pubkey: provider.publicKey, isSigner: true, isWritable: true },
],
programId : program_id,
data: b
});
let transaction = new solanaWeb3.Transaction()
transaction.add(instruction);
let { blockhash } = await connection.getRecentBlockhash();
transaction.recentBlockhash = blockhash;
transaction.feePayer = provider.publicKey;
let signed = await provider.signTransaction(transaction, connection);
console.log(signed);
let signature = await connection.sendRawTransaction(signed.serialize());
console.log(signature);
await connection.confirmTransaction(signature);