web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

Transaction has been reverted by the EVM in token transfer

Open bh717 opened this issue 1 year ago • 5 comments

`try { let rpcUrl; if (network === "ETH") rpcUrl = process.env.MAINNET_INFURA_URL; else if (network === "BSC") rpcUrl = process.env.BSC_MAINNET_INFURA_URL; console.log("rpcUrl:", rpcUrl); const web3 = new Web3(rpcUrl); const account = web3.eth.accounts.privateKeyToAccount("0x" + privateKey); const fromAddress = account.address; const tokenContract = new web3.eth.Contract(tokenAbi, tokenAddress);

const nonce = await web3.eth.getTransactionCount(fromAddress, "latest");

const wallet = web3.eth.accounts.wallet.add("0x" + privateKey);

const gasLimit = await web3.eth.estimateGas({
  from: fromAddress,
  to: tokenAddress,
  data: tokenContract.methods.transfer(toAddress, amount).encodeABI(),
});

console.log("nonce, gasLimist:", nonce, gasLimit);
const tx = {
  from: fromAddress,
  to: tokenAddress,
  data: tokenContract.methods.transfer(toAddress, amount).encodeABI(),
  gasPrice: await web3.eth.getGasPrice(),
  gasLimit: gasLimit,
  nonce: nonce,
  chainId: network === "ETH" ? 1 : 56,
};
const signedTx = await web3.eth.accounts.signTransaction(tx, privateKey);
console.log("signedTx:", signedTx);
const receipt = await web3.eth.sendSignedTransaction(
  signedTx.rawTransaction
);

console.log(
  "Token transfer successful with hash:",
  receipt.transactionHash
);
return receipt;`

amount: 356981723430n This is my code and log of amount. I am getting Transaction has been reverted by the EVM in sendSignedTransaction. Plz help for solving my problem as soon as possible

bh717 avatar Sep 25 '24 23:09 bh717

Can you share the details of the contract you're trying to interact with?

danforbes avatar Sep 26 '24 12:09 danforbes

https://etherscan.io/address/0xd29da236dd4aac627346e1bba06a619e8c22d7c5 This is my token contract.

wonderBH717 avatar Sep 26 '24 12:09 wonderBH717

So you're interacting with the contract on Ethereum Mainnet? Are you certain that the from account has sufficient funds to transfer? What is the address of the from account?

danforbes avatar Sep 26 '24 12:09 danforbes

Whats the error?

luu-alex avatar Oct 01 '24 14:10 luu-alex

Hey @bh717, any additional information you can provide and answering the questions above? We'd like to look into this issue and resolve it for you.

mconnelly8 avatar Oct 14 '24 17:10 mconnelly8

Hey @bh717, since we haven’t heard back from you in the past month, it seems the issue is no longer affecting you. I’m closing this for now, but feel free to reopen it if you’d like to continue the discussion and you have more insights to share with us.

krzysu avatar Nov 15 '24 08:11 krzysu