【问题标题】:What is "Signature Verification Failed" in Solana?什么是 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]
);

【问题讨论】:

    标签: javascript solana


    【解决方案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
    猜你喜欢
    • 2012-08-21
    • 2021-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 2013-10-28
    • 2020-11-02
    • 2016-01-13
    相关资源
    最近更新 更多