Solana 中的 "Signature Verification Failed" 是什么?

What is "Signature Verification Failed" in 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]
);

在 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!
});

这对我有用。

tx.partialSign

let tx = new Transaction();
const anotherKeypair = Keypair.generate(); 

tx.recentBlockhash = (await connection.getRecentBlockhash()).blockhash;
tx.feePayer = new PublicKey(publicKeyStringfromWallet);
console.log(tx)

tx.partialSign(anotherKeypair) // THIS SIGNS for web3 keypair

const { signature } = await window.solana.signAndSendTransaction(tx); //THIS signs wallet keypair