Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction has been reverted by the EVM: out of funds #7393

Closed
imacrosid opened this issue Nov 16, 2024 · 1 comment
Closed

Transaction has been reverted by the EVM: out of funds #7393

imacrosid opened this issue Nov 16, 2024 · 1 comment

Comments

@imacrosid
Copy link

imacrosid commented Nov 16, 2024

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
@imacrosid imacrosid changed the title Transaction has been reverted by the EVM without any error information Transaction has been reverted by the EVM: out of funds Nov 16, 2024
@imacrosid imacrosid changed the title Transaction has been reverted by the EVM: out of funds Switch to ethers it's easier to use, sorry :( Nov 17, 2024
@imacrosid imacrosid closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2024
@krzysu
Copy link
Contributor

krzysu commented Nov 18, 2024

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. 😁

@mconnelly8 mconnelly8 changed the title Switch to ethers it's easier to use, sorry :( Transaction has been reverted by the EVM: out of funds Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants