我正在尝试调用 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)
在 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)
| 归档时间: |
|
| 查看次数: |
9424 次 |
| 最近记录: |