-2

I am trying to make a trade using the following method. The contract is already deployed on the blockchain and makes dual swap using two dexes

    console.log('>>>>>>>>>>>>>>>>> Making Trade >>>>>>>>>>>>>>>>>>>>>>')
const tx = await attArb.connect(admin).duelDexTrade(router1,router2,token1,token2,amount,
                                            {   
                                            gasPrice: ethers.utils.parseUnits('200', 'gwei'), 
                                                gasLimit: 1000000 
                                            }
                                        )

The trouble is, when ever I specify gasPrice & gasLimit, transaction fails with the error:

Trade Failed. Error: transaction failed [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ]

it doesn't matter even if I specify one of them. But on block chain explorer, both gasPrice & gasLimit is set according to values I have passesd.

enter image description here

when both gasPrice & gasLimit is removed, the method works as intended. But I want to give it a high priority by defining a higher gas price. I am using ethers js and HH. What is wrong with this code or any specific reason this is happening?

DeFi
  • 77
  • 1
  • 8
  • 1
    are you sure it not the spelling mistake gasPrice: thers.utils.parseUnits('200', 'gwei'), you forgot "e" it should be ethers.utils.parseUnits('200', 'gwei')? – Muhammad Hassan Oct 08 '22 at 19:35
  • corrected. In the original code is ethers.utils.parseUnits('200','gwei') – DeFi Oct 09 '22 at 00:38

1 Answers1

1

The problem relates to asynchronous nature of js as I understand. I had a fs.appendFile() function, immediately after, where one of the parameters were undefined. The error was leading to the failure of the transaction as well.

A bit weird. But got it corrected. I am new to programming, any ideas are welcome.

DeFi
  • 77
  • 1
  • 8