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 in token transfer #7287

Open
bh717 opened this issue Sep 25, 2024 · 5 comments
Open

Transaction has been reverted by the EVM in token transfer #7287

bh717 opened this issue Sep 25, 2024 · 5 comments
Labels
4.x 4.0 related

Comments

@bh717
Copy link

bh717 commented Sep 25, 2024

`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

@danforbes
Copy link
Contributor

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

@lasse717
Copy link

@danforbes
Copy link
Contributor

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?

@mconnelly8 mconnelly8 added the 4.x 4.0 related label Oct 1, 2024
@luu-alex
Copy link
Contributor

luu-alex commented Oct 1, 2024

Whats the error?

@mconnelly8
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related
Projects
None yet
Development

No branches or pull requests

5 participants