我想从幻影钱包中签一个用户的事务,然后通过web3.js发送事务,但是在成功地签署了事务后,web3js库函数sendRawTransaction()给了控制台中的错误消息
const signedTransaction = await window.solana.signTransaction(transaction);
const signature = await connection.sendRawTransaction(signedTransaction.serialize());
await connection.confirmTransaction(signature);发布于 2022-07-01 15:31:12
如果您查看sendTransaction的实现,您将看到它在签署、序列化和发送之前向事务添加了一个块哈希。如果没有块哈希,您将得到错误Blockhash not found。因此,相反,您需要这样做:
const latestBlockhash = await connection.getLatestBlockhash();
transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
transaction.recentBlockhash = latestBlockhash.blockhash;
const signedTransaction = await window.solana.signTransaction(transaction);
const signature = await connection.sendRawTransaction(signedTransaction.serialize());
await connection.confirmTransaction(signature);sendTransaction在https://github.com/solana-labs/solana/blob/3fcdc45092b969baeb7273de6596399d98277366/web3.js/src/connection.ts#L4389上的全面实现
https://stackoverflow.com/questions/72791740
复制相似问题