0

I'm using web3js to transfer money, but I'm not sure why I use some third party wallet like solflare. They only take 2-3 seconds to transfer money, but my own program takes 10 seconds to a minute, sometimes the transaction fails, and I added the priority fee correctly. Why does solflare only have 300 compute units, but mine need 3,000

Here's my code

const fromTokenAccount = await getOrCreateAssociatedTokenAccount( connection, wallet.payer, new PublicKey(coinToken), wallet.publicKey );

// 获取接收者的代币账户信息 const toTokenAccount = await getOrCreateAssociatedTokenAccount( connection, wallet.payer, new PublicKey(coinToken), binanceWalletPublicKey ); const transactionResponse = createTransferInstruction( fromTokenAccount.address, toTokenAccount.address, wallet.publicKey, number, // 转账数量,注意这里的单位依赖于代币的小数点位数 [], TOKEN_PROGRAM_ID, ) const computeUnits = await getSimulationComputeUnits(connection, [transactionResponse], wallet.publicKey, []) console.log("需要使用的计算单元", computeUnits) // 创建交易指令 const transaction = new Transaction() .add(transactionResponse) transaction.recentBlockhash = (await connection.getLatestBlockhash() ).blockhash; transaction.sign(wallet.payer);

const lastFeeEstimate = await getPriorityFeeEstimate("High", transaction) console.log("当前最高优先手续费", lastFeeEstimate) transaction.add( ComputeBudgetProgram.setComputeUnitPrice({ microLamports: lastFeeEstimate.priorityFeeEstimate+100 }) ).add( ComputeBudgetProgram.setComputeUnitLimit({ units: computeUnits!*1.05 }) )

console.log(new Date().toISOString(), ,"提交交易,正式开始转账")

// 签署并发送交易 const signature = await web3.sendAndConfirmTransaction( connection, transaction, [wallet.payer], { skipPreflight: true } ); console.log(new Date().toISOString(), '转账成功'); console.log('Transfer successful with signature:', signature);

1 Answer 1

1

The slower processing speeds and increased use of computing resources, in your Web3.js application compared to Solflare could be a result of how you structure your transactions the inclusion of skipPreflight; true to bypass checks at the expense of failure chances and potentially less efficient management of fees and network conditions. To enhance the speed of your transactions you might want to optimize how you construct transactions proactively handle checks to detect problems on and explore the methodologies used by Solflare for managing computing resources and network interactions. Experimenting with fee strategies could also play a role, in reducing transaction times and ensuring success rates consistently.

1
  • I'm a newbie, isn't that the way transactions are structured? That's what I saw in the solana documentation
    – 赵77
    Commented Apr 23 at 1:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.