【发布时间】:2022-08-24 01:31:47
【问题描述】:
我正在学习如何在 Solana 的区块链上编程,但是我被卡住了……
我正在尝试运行此代码
import web3 = require(\'@solana/web3.js\');
const connection = new web3.Connection(web3.clusterApiUrl(\"devnet\"));
const key: Uint8Array = Uint8Array.from([10,120,79,226,98,171,155,229,251,24,251,52,63,137,153,185,225,17,178,76,68,30,12,227,44,21,185,250,30,103,169,167,130,84,37,163,36,71,217,34,1,45,246,144,207,196,155,167,108,57,114,39,142,246,59,169,109,97,182,246,227,57,26,123]);
const programId = new web3.PublicKey(\"9mkRQSS5a25cKuYPnvDQFEGA5aKHkauVHf6SmiTASvqp\");
console.log(\'hello\');
async function main() {
// Create signer
const signer: web3.Keypair = web3.Keypair.fromSecretKey(key);
// Verify balance
await connection.getBalance(signer.publicKey).then(balance => {
console.log(\"SOL: \", balance / web3.LAMPORTS_PER_SOL);
})
// To call our Solana program we need to collect a
// series of instructions into a transaction
const transaction: web3.Transaction = new web3.Transaction().add(
new web3.TransactionInstruction({
keys: [],
programId
})
);
await web3
.sendAndConfirmTransaction(connection, transaction, [signer])
.then((sig) => {
console.log(\"sig: {}\", sig);
});
}
main()
我有这个错误
/home/zen/solana_test/cli/node_modules/@solana/web3.js/src/connection.ts:3689
throw new SendTransactionError(
^
SendTransactionError: failed to send transaction: invalid transaction: index out of bounds
at Connection.sendEncodedTransaction (/home/zen/solana_test/cli/node_modules/@solana/web3.js/src/connection.ts:3689:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Connection.sendRawTransaction (/home/zen/solana_test/cli/node_modules/@solana/web3.js/src/connection.ts:3649:20)
at async Connection.sendTransaction (/home/zen/solana_test/cli/node_modules/@solana/web3.js/src/connection.ts:3637:12)
at async Object.sendAndConfirmTransaction (/home/zen/solana_test/cli/node_modules/@solana/web3.js/src/util/send-and-confirm-transaction.ts:29:21)
at async main (/home/zen/solana_test/cli/index.ts:41:5) {
logs: undefined
}
我要做的就是发送这个交易并通过分析终端中的solana log 9mkRQSS5a25cKuYPnvDQFEGA5aKHkauVHf6SmiTASvqp 来查看它是否有效。
我错过了什么?
标签: typescript solana solana-web3js