什么是 Solana 中的“签名验证失败”?
Posted
技术标签:
【中文标题】什么是 Solana 中的“签名验证失败”?【英文标题】:What is "Signature Verification Failed" in Solana? 【发布时间】:2022-01-21 04:05:40 【问题描述】:我正在尝试调用 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]
);
【问题讨论】:
【参考方案1】:在 Solana 中,您需要传入 两个签名者的密钥对,和您正在创建的帐户的密钥对。
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
,但您仍将拥有您生成的任何帐户密钥对:
const sendTransaction = useWallet();
const anotherKeypair = Keypair.generate();
const signature = await sendTransaction(transaction, connection,
signers: [anotherKeypair] // You probably want to pass in the keypair here!
);
【讨论】:
我给这句话+1:In Solana, you need to pass in both the keypairs of the signer, and the keypairs of the accounts you're creating
以上是关于什么是 Solana 中的“签名验证失败”?的主要内容,如果未能解决你的问题,请参考以下文章