Receiving "Phantom - RPC Error: Transaction creation failed" while building solana escrow with @solana/web3.js
Receiving "Phantom - RPC Error: Transaction creation failed" while building solana escrow with @solana/web3.js
我正在尝试复制 https://github.com/dboures/solana-random-number-betting-game
虽然当我尝试启动我的托管时,我收到以下错误:
Phantom - RPC Error: Transaction creation failed.
Uncaught (in promise) {code: -32003, message: 'Transaction creation failed.'}
我正在使用带有 Solana RPC 的 Phantom 钱包。
const transaction = new Transaction({ feePayer: initializerKey })
let recentBlockHash = await connection.getLatestBlockhash();
transaction.recentBlockhash = await recentBlockHash.blockhash;
const tempTokenAccount = Keypair.generate();
// Create Temp Token X Account
transaction.add(
SystemProgram.createAccount({
programId: TOKEN_PROGRAM_ID,
fromPubkey: initializerKey,
newAccountPubkey: tempTokenAccount.publicKey,
space: AccountLayout.span,
lamports: await connection.getMinimumBalanceForRentExemption(AccountLayout.span )
})
);
const { signature } = await wallet.signAndSendTransaction(transaction);
let txid = await connection.confirmTransaction(signature);
console.log(txid);
您正在尝试创建一个帐户,但未使用该帐户的密钥对进行签名以证明所有权。
您必须像这样将密钥对添加为签名者:
await wallet.signAndSendTransaction(transaction, {signers: [tempTokenAccount]})
我能够使用以下代码解决我的问题:
const signed = await wallet.request({
method: "signTransaction",
params: {
message: bs58.encode(transaction.serializeMessage())
}
});
const signature = bs58.decode(signed.signature)
transaction.addSignature(initializerKey, signature);
transaction.partialSign(...[tempTokenAccount]);
await connection.sendRawTransaction(transaction.serialize())
而不是:
await wallet.signAndSendTransaction(transaction, {signers: [tempTokenAccount]})
基本上,一开始我使用一个简单的函数来执行上述所有步骤,但是,由于某种原因,它无法正常工作并抛出所遇到的错误。当我使用此故障代码时,它起作用了!错误的原因对我来说仍然是个谜。
谢谢。
我正在尝试复制 https://github.com/dboures/solana-random-number-betting-game 虽然当我尝试启动我的托管时,我收到以下错误:
Phantom - RPC Error: Transaction creation failed.
Uncaught (in promise) {code: -32003, message: 'Transaction creation failed.'}
我正在使用带有 Solana RPC 的 Phantom 钱包。
const transaction = new Transaction({ feePayer: initializerKey })
let recentBlockHash = await connection.getLatestBlockhash();
transaction.recentBlockhash = await recentBlockHash.blockhash;
const tempTokenAccount = Keypair.generate();
// Create Temp Token X Account
transaction.add(
SystemProgram.createAccount({
programId: TOKEN_PROGRAM_ID,
fromPubkey: initializerKey,
newAccountPubkey: tempTokenAccount.publicKey,
space: AccountLayout.span,
lamports: await connection.getMinimumBalanceForRentExemption(AccountLayout.span )
})
);
const { signature } = await wallet.signAndSendTransaction(transaction);
let txid = await connection.confirmTransaction(signature);
console.log(txid);
您正在尝试创建一个帐户,但未使用该帐户的密钥对进行签名以证明所有权。
您必须像这样将密钥对添加为签名者:
await wallet.signAndSendTransaction(transaction, {signers: [tempTokenAccount]})
我能够使用以下代码解决我的问题:
const signed = await wallet.request({
method: "signTransaction",
params: {
message: bs58.encode(transaction.serializeMessage())
}
});
const signature = bs58.decode(signed.signature)
transaction.addSignature(initializerKey, signature);
transaction.partialSign(...[tempTokenAccount]);
await connection.sendRawTransaction(transaction.serialize())
而不是:
await wallet.signAndSendTransaction(transaction, {signers: [tempTokenAccount]})
基本上,一开始我使用一个简单的函数来执行上述所有步骤,但是,由于某种原因,它无法正常工作并抛出所遇到的错误。当我使用此故障代码时,它起作用了!错误的原因对我来说仍然是个谜。
谢谢。