我正在尝试调用 Solana 程序,当我运行 sendAndConfirmTransaction
时,它给了我Signature Verification Failed
,我不知道为什么。
const {sendAndConfirmTransaction, clusterApiUrl, Connection} = require("@solana/web3.js");
let signer = Keypair.generate();
let anotherKeypair = Keypair.generate();
let transaction = someInstruction(signer, anotherKeypair);
let connection = new Connection(clusterApiUrl('testnet'));
sendAndConfirmTransaction(
connection,
transaction,
[signer]
);
最佳答案
在 Solana 中,您需要传入签名者的 key 对和您正在创建的帐户的 key 对。
const {sendAndConfirmTransaction, clusterApiUrl, Connection} = require("@solana/web3.js");
let signer = Keypair.generate();
let anotherKeypair = Keypair.generate();
let transaction = someInstruction(signer, anotherKeypair);
let connection = new Connection(clusterApiUrl('testnet'));
sendAndConfirmTransaction(
connection,
transaction,
[signer, anotherKeypair] // <-- If you made the keypair, you probably want it here!
);
如果您使用的是钱包连接库,例如 @solana/wallet-adapter-react
,您没有 signer
,但您仍将拥有您生成的任何帐户 key 对:const { sendTransaction } = useWallet();
const anotherKeypair = Keypair.generate();
const signature = await sendTransaction(transaction, connection, {
signers: [anotherKeypair] // You probably want to pass in the keypair here!
});
关于javascript - Solana 中的 "Signature Verification Failed"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70406575/