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

标签 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]
);

最佳答案

在 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/

相关文章:

javascript - 组织对象以在需要时创建键和/或将不同的属性推送到值对数组

javascript - 带有属性的 $scope 表示未定义

javascript - 什么是用于创建程序可用于执行契约(Contract)付款的转账账户的 Solana 模式?

solana - 如何在 Solana 中查看合约代码?

macos - Solana 测试验证器 -- dyld : Library not loaded:/usr/local/opt/openssl@1. 1/lib/libssl.1.1.dylib

javascript - Radiobuttons ng-checked 默认情况下不显示 div 并且仅在 onclick 时起作用

javascript - 如何整理具有许多条件的 JavaScript 过滤函数?

JavaScript 使用 String 作为对象键的参数

typescript - 获取与 Solana 钱包地址关联的 Assets 列表

reactjs - 如何在 solana 中从 PDA 中提取 sol/lamports