Ethers.js Transactions – What Does Curly Bracket Mean in Smart Contract Transaction?

ethers.jsjavascriptreact

await routerContract
        .addLiquidityETH(
          daiAddress,
          ethers.utils.parseEther(strDaiAmount),
          ethers.utils.parseEther(strDaiSlippage),
          ethers.utils.parseEther(strEthSlippage),
          signerAddress,
          Date.now() + 60000 * props.deadline,
          { value: ethers.utils.parseEther(strEthAmount) }
        )

The above is working code. I am writing this question for further understanding.

I am having trouble understanding the final parameter of my smart contract… { value: ethers.utils.parseEther(strEthAmount) }

I added the final parameter as the code was throwing errors and I saw a thread saying that you have to add this parameter so that ethers knows that I am making a transaction. As far as I understand, the parameter is only passing the ether amount.

Another resolution that I tried was putting a .send method for my transaction. But ethers does not recognize the .send method.

If anyone could help to clear my confusion or give some pointers, I would be very grateful. Thanks!

Best Answer

addLiquidityETH seems to be a payable function therefore it needed that parameter, those curly brackets indicate that this is info for the transaction and not part of the parameters expected by the function, that's how you indicate you are sending eth. It could also include gasLimit and other properties.

Related Topic