Solana 中“签名验证失败”是什么意思?

Eva*_*rad 7 javascript solana

我正在尝试调用 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]
);
Run Code Online (Sandbox Code Playgroud)

Eva*_*rad 8

在 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!
);
Run Code Online (Sandbox Code Playgroud)

如果您使用的是钱包连接库,例如@solana/wallet-adapter-react,您没有signer,但您仍然会拥有您生成的帐户的任何密钥对:

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!
);
Run Code Online (Sandbox Code Playgroud)

  • 我对这句话给予 +1:“在 Solana 中,您需要传入签名者的密钥对以及您正在创建的帐户的密钥对” (2认同)