web3/web3.js

Transaction has been reverted by the EVM: out of funds

Closed this issue · 1 comments

Expected behavior

  1. Create a New Draft Transaction

    • Define the transaction details, such as recipient address, value, gas price, and gas limit.
  2. Sign the Transaction

    • Use private key to sign the transaction.
  3. Send the Signed Transaction

    • Submit the signed transaction to the blockchain network for processing and get receipt hash.

Actual behavior

After sending the signed transaction, I got the return TransactionRevertInstructionError: Transaction has been reverted by the EVM.

Steps to reproduce the behavior

async function sendTransaction(privateKey, senderAddress) {
  const nonce = await web3.eth.getTransactionCount(senderAddress, "latest");

  let balance = await web3.eth.getBalance(senderAddress);
  console.log("Balance", typeof balance, balance);

  const gasPrice = await web3.eth.getGasPrice();
  console.log("\nGas Price", typeof gasPrice, gasPrice);
  console.log(web3.utils.fromWei(gasPrice, "gwei"), bigIntToHex(gasPrice));

  const gasPriceInWei = web3.utils.fromWei(gasPrice, "gwei");
  console.log("Gas Price from gwei", typeof gasPriceInWei, gasPriceInWei);

  let txDraft = {
    from: senderAddress,
    value: "0x0",
    data: "0x",
    to: config.MAIN_ADDRESS,
    chainId: config.CHAIN_ID,
    nonce: parseInt(nonce, 10),
  };

  txDraft.gasPrice = bigIntToHex(gasPrice);
  console.log(txDraft);

  let gasLimit = await web3.eth.estimateGas(txDraft);
  console.log("\nGas Limit", typeof gasLimit, gasLimit, bigIntToHex(gasLimit));
  console.log(txDraft);

  txDraft.value = "0x16345785d8a0000"; // trying with small amount
  console.log(txDraft);

  gasLimit = await web3.eth.estimateGas(txDraft);
  console.log("\nGas Limit", typeof gasLimit, gasLimit, bigIntToHex(gasLimit));

  txDraft.gasLimit = bigIntToHex(gasLimit);
  console.log(txDraft);

  const signedTx = await web3.eth.accounts.signTransaction(txDraft, privateKey);
  console.log(signedTx);

  const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);

  if (!receipt) {
    return;
  }
  return receipt;
}

It will return the draft transaction like this.

{
  from: '0x4d9aE1c1D541bE930093233500c72752BD46e2Db',
  value: '0x16345785d8a0000',
  data: '0x',
  to: '0xAa6CA7993a94477A0BF44188475ffe562a606F04',
  chainId: 23294,
  nonce: 18,
  gasPrice: '0x174876e800',
  gasLimit: '0x1edbaa'
}

Logs

TransactionRevertInstructionError: Transaction has been reverted by the EVM
    at file:///L:/Learning/Crypto/Others/balance-sender-evm/node_modules/web3-eth/lib/esm/utils/get_transaction_error.js:45:21
    at Generator.next (<anonymous>)
    at file:///L:/Learning/Crypto/Others/balance-sender-evm/node_modules/web3-eth/lib/esm/utils/get_transaction_error.js:23:71
    at new Promise (<anonymous>)
    at __awaiter (file:///L:/Learning/Crypto/Others/balance-sender-evm/node_modules/web3-eth/lib/esm/utils/get_transaction_error.js:19:12)
    at getTransactionError (file:///L:/Learning/Crypto/Others/balance-sender-evm/node_modules/web3-eth/lib/esm/utils/get_transaction_error.js:30:12)
    at SendTxHelper.<anonymous> (file:///L:/Learning/Crypto/Others/balance-sender-evm/node_modules/web3-eth/lib/esm/utils/send_tx_helper.js:76:33)
    at Generator.next (<anonymous>)
    at fulfilled (file:///L:/Learning/Crypto/Others/balance-sender-evm/node_modules/web3-eth/lib/esm/utils/send_tx_helper.js:4:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: undefined,
  reason: 'execution failed: out of funds',
  signature: undefined,
  receipt: undefined,
  data: undefined,
  code: 402
}

But when I try with an undefined value (0), it will succeed.
image
I'm sorry for many logs because I just wanna make sure, I don't miss anything.

Environment

  • Npm v10.8.2
  • NodeJS v22.6.0
  • web3.js ^4.15.0
  • OS Windows 10 Home Single Language 22H2
  • Device Asus ROG GL503VD

Hey @imacrosid, there is the failure reason displayed in your logs:

reason: 'execution failed: out of funds'

It works with a value of 0 because no funds are being sent in that case. As far as I can tell, everything is functioning as expected. 😁