in this contract will the floating point work,
pragma solidity ^0.8.7;
// SPDX-License-Identifier: GPL-3.0
contract AB {
address payable b= payable(xx);
uint amount= 0.1 ether;
function Optimizer( uint256 _amount )public payable{
_amount=msg.value;
require(amount >=0.1 ether,"transfer amount to low");
b.transfer(msg.value);
}
}
Best Answer
yes, you used the
ether
keyword with a floating point correctly. In Remix your0.1 ether
line didn't cause any warnings or errors.If you create a test function that returns
0.1 ether
, you can see that it really returns100000000000000000
:If you put this WEI value into an Ethereum unit converter, you can see the number's equivalent in GWEI and ETH:
A more refined version of your contract that uses
msg.value
correctly as opposed to your_amount
uint, custom errors as opposed to your hard-coded require, andcall
instead oftransfer
for sending the ETH: