How to send Wei to payable function with ethers

How to send Wei to payable function with ethers

Manage alerts

Loading saved threads...

Shadq · External communityPost link
External question — Ethereum Stack Exchange Author: Shadq Original post: https://ethereum.stackexchange.com/questions/148747 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I want to send this function 1 wei using ethersJS while testing it on hardhat: modifier payFee() { bool sent = payable(address(this)).send(msg.value); require(sent, "Didn't receive fee."); _; } function executeTrade( address _tokenA, address _tokenB, uint _tokensFromFlashLoan, bool _startOnUniswap ) external payable payFee { uint balanceBefore = IERC20(_tokenA).balanceOf(_tokenA); bytes memory data = abi.encode( _startOnUniswap, _tokenA, _tokenB, _tokensFromFlashLoan, balanceBefore ); flashloan(_tokenA, _tokensFromFlashLoan, data); } When i test it on hardhat i do it like this: const options = { gasLimit: 3000000, value: ethers.utils.parseUnits("1.0", "wei"), }; trade = await contract.executeTrade( tokenA, tokenB, ethers.utils.parseEther("10.0"), false, options ); But the modifier reverts giving me an error saying that the function didn't receive the fee, is my method to send 1 WEI wrong? if you have any suggestion please reply it would be very helpful.
Quote
Report
Saxtheowl · External communityPost link
External answer — Ethereum Stack Exchange Author: Saxtheowl Original post: https://ethereum.stackexchange.com/a/148749 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. You are passing the options object as a parameter to the executeTrade but you should providing it as an optional object when calling the function. const options = { gasLimit: 3000000, value: ethers.utils.parseUnits("1.0", "wei"), }; trade = await contract.executeTrade( tokenA, tokenB, ethers.utils.parseEther("10.0"), false, { ...options } );
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Ethereum Stack Exchange Author: Shadq Source score (net votes, not local likes): 2 Original post: https://ethereum.stackexchange.com/questions/148747 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I want to send this function 1 wei using ethersJS while testing it on hardhat: modifier payFee() { bool sent = payable(address(this)).send(msg.value); require(sent, "Didn't receive fee."); _; } function executeTrade( address _tokenA, address _tokenB, uint _tokensFromFlashLoan, bool _startOnUniswap ) external payable payFee { uint balanceBefore = IERC20(_tokenA).balanceOf(_tokenA); bytes memory data = abi.encode( _startOnUniswap, _tokenA, _tokenB, _tokensFromFlashLoan, balanceBefore ); flashloan(_tokenA, _tokensFromFlashLoan, data); } When i test it on hardhat i do it like this: const options = { gasLimit: 3000000, value: ethers.utils.parseUnits("1.0", "wei"), }; trade = await contract.executeTrade( tokenA, tokenB, ethers.utils.parseEther("10.0"), false, options ); But the modifier reverts giving me an error saying that the function didn't receive the fee, is my method to send 1 WEI wrong? if you have any suggestion please reply it would be very helpful.

Cancel quote

Checking account access…