Best Practices for Constraining ETH Amounts in Functions (Equivalent to ERC20 bound Usage) #88
-
We have this snippet code from the lesson 5: T-Swap: function depositYeildERC20(uint256 _amount) public {
uint256 amount = bound(_amount, 0, yeildERC20.balanceOf(owner));
vm.startPrank(owner);
yeildERC20.approve(address(handlerStatefulFuzzCatches), amount);
handlerStatefulFuzzCatches.depositToken(yeildERC20, amount);
vm.stopPrank();
} In the context of the Is there a recommended or best practice method to limit the amount sent with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @rasyidred, good question. When working with ETH, one technique to limit the amount sent with Here's an example, limiting the amount of ETH sent: function depositETH() public payable {
require(msg.value >= 0.1 ether && msg.value <= 1 ether, "Amount must be 0.1 - 1 ETH");
// continue function
} |
Beta Was this translation helpful? Give feedback.
Hi @rasyidred, good question.
When working with ETH, one technique to limit the amount sent with
msg.value
in a function is by usingrequire()
.Here's an example, limiting the amount of ETH sent: