I keep getting this error when i try to perform a static test call

async sellTestTransaction(tokenAmount, gwei) {
        const token = await Fetcher.fetchTokenData(chainId, this.address, provider);
        const weth = WETH[token.chainId];  
        const pair = await Fetcher.fetchPairData(token, weth, provider);
        const amountIn = ethers.utils.parseUnits(tokenAmount.toString(), token.decimals)
        const route = new Route([pair], token)
        const trade = new Trade(route, new TokenAmount(token, amountIn), TradeType.EXACT_INPUT)
        const slippage = new Percent("1", "100")
        const amountOutMin = toHex(trade.minimumAmountOut(slippage))
        const path = [token.address, weth.address]
        const to = this.signer.address
        const deadline = Math.floor(Date.now() / 1000) + 60 * 20
        const currentGas = await provider.getGasPrice()
        let gweiValue = ethers.utils.formatUnits(currentGas, 'gwei');
        if (gwei) {
            gweiValue += gwei
        gweiValue = Math.ceil(gweiValue)
        const gasPriceWei = ethers.utils.parseUnits(gweiValue.toString(), 'gwei');
        const tokenCA = new ethers.Contract(this.address, abi, this.signer)
        const approve = await tokenCA.callStatic.approve(UniSwapRouterAddress, amountIn)
        const tx = await this.uniswap.callStatic.swapExactTokensForETH(amountIn, amountOutMin, path, to, deadline, {gasPrice : gasPriceWei, gasLimit : 1000000})
        return tx
    at Logger.makeError (C:\Users\akith\OneDrive\Desktop\ShitCoinBot\server\node_modules\@ethersproject\logger\lib\index.js:238:21)
    at Logger.throwError (C:\Users\akith\OneDrive\Desktop\ShitCoinBot\server\node_modules\@ethersproject\logger\lib\index.js:247:20)
    at Interface.decodeFunctionResult (C:\Users\akith\OneDrive\Desktop\ShitCoinBot\server\node_modules\@ethersproject\abi\lib\interface.js:388:23)
    at Object.<anonymous> (C:\Users\akith\OneDrive\Desktop\ShitCoinBot\server\node_modules\@ethersproject\contracts\lib\index.js:395:56)
    at step (C:\Users\akith\OneDrive\Desktop\ShitCoinBot\server\node_modules\@ethersproject\contracts\lib\index.js:48:23)
    at Object.next (C:\Users\akith\OneDrive\Desktop\ShitCoinBot\server\node_modules\@ethersproject\contracts\lib\index.js:29:53)
    at fulfilled (C:\Users\akith\OneDrive\Desktop\ShitCoinBot\server\node_modules\@ethersproject\contracts\lib\index.js:20:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  reason: 'TransferHelper: TRANSFER_FROM_FAILED',
  method: 'swapExactTokensForETH(uint256,uint256,address[],address,uint256)',
  data: '0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000245472616e7366657248656c7065723a205452414e534645525f46524f4d5f4641494c454400000000000000000000000000000000000000000000000000000000',    
  errorArgs: [ 'TransferHelper: TRANSFER_FROM_FAILED' ],
  errorName: 'Error',
  errorSignature: 'Error(string)',
  address: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
  args: [
    BigNumber { _hex: '0x0ba43b7400', _isBigNumber: true },
  transaction: {
    data: '0x18cbafe50000000000000000000000000000000000000000000000000000000ba43b74000000000000000000000000000000000000000000000000000002cd034d886e1500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000009cd466930f011e32cc1ec854016612f28692eb610000000000000000000000000000000000000000000000000000000064d12dfe0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000e0a8ed732658832fac18141aa5ad3542e2eb503b000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
    to: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
    gasLimit: BigNumber { _hex: '0x0f4240', _isBigNumber: true },
    gasPrice: BigNumber { _hex: '0x06fc23ac00', _isBigNumber: true },
    from: '0x9cD466930f011e32cC1ec854016612f28692EB61'

I have tried to approve the token before the call and also without the call and it still doesnt work... Im running out of ideas.. I do have money for the gas. I obviously dont have the token amount because im trying to perform a "test" sell without using my money.. Not getting any luck though.

1 Answer 1


I obviously dont have the token amount

The call is failing because you don't have the available tokens.

Instead of testing on a live chain, consider forking the chain locally and running your tests against the fork. This way you can test without spending gas.

Another answer about how to fork a chain: Hardhat chain fork on the test rather than config file

  • If i fork the chain im still allowed to access all the tokens that get deployed on the main net? I'm trying to retrieve tax buy and sell tax information about tokens that launch. A lot of scanners and sites do it and i doubt they are paying gas to find out...
    – Guruu
    Commented Aug 8, 2023 at 17:50
  • You'll have to get a new fork each time you want to update your local chain to reflect the live chain. You could use whatever system is triggering a new coin to be detected to also cause a chain refresh.
    – Milk
    Commented Aug 8, 2023 at 19:22
  • Intresting... Im not sure how i can perform a new deploy of the fork each time using my base node server... got any guidance or tutorials for this? Right now i just set my provider like this... const provider = new ethers.providers.JsonRpcProvider(TestNet ? process.env.URL : process.env.LIVE_URL); Im not entirely sure how i'd be able to use constantly redeploy a fork each time a new pair is made.
    – Guruu
    Commented Aug 8, 2023 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.