helius-labs / helius-sdk

132 stars 39 forks source link

[BUG POSSIBLE] Unable to get compute unit when simulating transaction for sendSmartTransaction #110

Closed hassanshafique closed 1 month ago

hassanshafique commented 3 months ago

Getting error during getComputeUnit during sendSmartTransaction: Error

Error: Error fetching compute units for the instructions provided
    at RpcClient.<anonymous> (/path/to/project/node_modules/helius-sdk/dist/src/RpcClient.js:576:23)
    at Generator.throw (<anonymous>)
    at rejected (/path/to/project/node_modules/helius-sdk/dist/src/RpcClient.js:6:65)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Simulation error: {
  "InsufficientFundsForRent": {
    "account_index": 1
  }
}

Although the transaction still goes smoothly with success in the blockchain!

Steps to reproduce this unexpected error/warning

const lamportsToSend = /* Lompart To Send */;
const fromWallet = /* Wallet Object */;
const feePayerWallet = /* Wallet Object */;

const recipientPublicKey = new PublicKey(/* Recipient Public Key */);

const instructions = [
    SystemProgram.transfer({
        fromPubkey: fromWallet.publicKey,
        toPubkey: recipientPublicKey,
        lamports: lamportsToSend,
    })
];

const signers = [
    feePayerWallet,
    fromWallet
];

try {
    const transactionSignature = await helius.rpc.sendSmartTransaction(instructions, signers, [], { feePayer: feePayerWallet, skipPreflight: false });
    ...
} catch (error) {
    console.log(error);
}
0xIchigo commented 3 months ago

gm! Have you double-checked the accounts in this transaction? The InsufficientFundsForRent error is thrown when a transaction results in an account with insufficient funds for rent. This could also be an issue with how solana/web3.js handles simulations because the transaction still goes through

hassanshafique commented 3 months ago

Have you double-checked the accounts in this transaction? The InsufficientFundsForRent error is thrown when a transaction results in an account with insufficient funds for rent.

Yes, I have double checked it. The funds are correctly transferred from payer to receiver with feePayer paying the gas fee. This error happens during simulation only. So, maybe it uses the default 1000 compute units. Strange thing is that even with error, the transaction still goes!?

0xIchigo commented 1 month ago

gm @hassanshafique! Are you still encountering this issue? It seems like this happens when sending to new or uninitialized accounts. So, the simulation fails due to rent-exemption checks, but the actual transaction still succeeds because the account gets funded properly

0xIchigo commented 1 month ago

I'm going to go ahead and close this issue, as it seems to be an error on your end with the inputs you've provided rather than an SDK issue. I recommend checking out the Solana Stack Exchange if this issue persists! And, of course, if you have any SDK issues, please feel free to open another issue or reach out to our support on Discord!