Reverting problem #147
-
I'm following lesson 3 of the guide talking about when you send tokens to a smart contract, and how to get it to revert if not enough money is sent. But in my simulation, it doesn't seem to properly send the money back (to the original sender) when sending an invalid amount (below the minimum). Instead, the contract just keeps the money. In the guide it said to add the // SPDX-License-Identifier: MIT
//get funds from people
//withdraw funds
//set minimum usd value thanks to LINK
pragma solidity ^0.8.8;
contract FundMe {
uint256 public number;
function fund() public payable{
number = 5;
require(msg.value >= 1e18, "Sent a amount!?"); // 1e18=10*18=1000000000000000000 - measured in terms of wei
}
//function withdraw(){}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
If you send the value less than the required then your amount will not deduct only the gas charges will be deducted from the account. Suppose, in the require statement you need the value to be more than 1 ETH, and the total gas is 50000. Now when you click the fundMe function with the value <= 1 ETH, then this value will not be deducted from the account, only the gas price from calling the function will deduct, let's say now the gas will be remaining 40000 (example) and revert back to account. And like this example, if we have any computation (in this example, assigning a number a value of 5) then the gas cost for that also will be deducted. Hope it clears your query, if so please mark it answered! |
Beta Was this translation helpful? Give feedback.
@rileymross
If you send the value less than the required then your amount will not deduct only the gas charges will be deducted from the account.
Suppose, in the require statement you need the value to be more than 1 ETH, and the total gas is 50000.
Now when you click the fundMe function with the value <= 1 ETH, then this value will not be deducted from the account, only the gas price from calling the function will deduct, let's say now the gas will be remaining 40000 (example) and revert back to account.
And like this example, if we have any computation (in this example, assigning a number a value of 5) then the gas cost for that also will be deducted.
Hope it clears your query, if so pl…