Search code examples
ethereumtrufflehardhat

Estimate gas in ETH from an approve contract


I woudlike to estimateGas after an approve contract :

WETH = weth.address;
USDC = usdc.address;

await usdc.approve(addr1, addr2).estimateGas;

When I try this I have this error :

TypeError: usdt.approve(...).estimateGas is not a function

Solution

  • Truffle uses different syntax. You need to pass the function params to the estimateGas(), not to the approve() function.

    await usdc.approve.estimateGas(addr1, addr2);
    

    Docs: http://trufflesuite.com/docs/truffle/getting-started/interacting-with-your-contracts#special-methods-on-truffle-contract-objects

    Note: Your code defines usdc and then the error message states usdt. I'm assuming that's just a typo while creating the question, unrelated to the original issue.