0

I'm trying to estimate gas required to transfer usdt using Infura node but always receive gas required exceeds allowance (12451164) or always failing transaction error. I have tried both using web3 and post (via axios) and both return same error.

Axios attempt:

export const estimateUsdtGas: EstimateGasType = async ({ web3 }, to, amount, wallet) => {
  const contract = new web3.eth.Contract(USDT_ABI, USDT_CONTRACT_ADDRESS)
  const gasPrice = await getGasPrice()
  const data = await contract.methods.transfer(to, '1').encodeABI()
  const body = {
    jsonrpc: '2.0',
    method: 'eth_estimateGas',
    params: [{
      value: web3.utils.numberToHex(0),
      gasPrice: web3.utils.numberToHex(gasPrice),
      to: USDT_CONTRACT_ADDRESS,
      from: wallet.address,
      data
    }],
    id: '1'
  }
  await axios.post(process.env.NODE_URL, body).then(res => {
    console.log(res.data)
    return res.data
  })
}

returns

{
 jsonrpc: '2.0',
 id: '122',
 error: {
   code: -32000,
   message: 'gas required exceeds allowance (12451164) or always failing transaction'
 }
}

web3 approach:

export const estimateUsdtGas: EstimateGasType = async ({ web3 }, to, amount) => {
  const contract = new web3.eth.Contract(USDT_ABI, USDT_CONTRACT_ADDRESS)
  return contract.methods.transfer(to, amount).estimateGas()
}

throws:

Error: Returned error: gas required exceeds allowance (12475588) or always failing transaction

USDT_ABI and contact address are correct, since if I hardcode gasLimit I am able to transfer.

  • That error states that the tx will fail if executed. Does wallet.address have tokens in the account? And is the correct network being used? – Shane Fontaine Oct 17 at 15:54
  • Get rid of the await in const data = await contract.methods.transfer(to, '1').encodeABI(). – goodvibration Oct 17 at 16:18
  • @ShaneFontaine wallet.address is a string with a public address. The network is correct. @goodvibration removing await has no impact, despite it is correct to remove it as encodeABI does not return a promise. – Vallo Oct 17 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.