0

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);



}

}

Rohan Nero
  • 1,562
  • 2
  • 7
  • 27
stofu
  • 93
  • 2
  • 12

2 Answers2

2

Yes. Also, there is no floating point numbers here, amount is an uint. ether in solidity means * 10 ^ 18, so your variable is effectively 10^17

Foxxxey
  • 4,307
  • 1
  • 6
  • 22
  • i deploy the contract on test net but its not sending eth and its also no meeting the condition of require(amount >=0.1 ether,"transfer amount to low"); – stofu Oct 10 '23 at 13:01
  • are you actually sending ether in the tx? Or just setting amount to 0.1 ether and hoping it will work? – Foxxxey Oct 10 '23 at 17:40
  • Oh it seems you figured it out with Rohan, all good :) – Foxxxey Oct 10 '23 at 17:41
0

yes, you used the ether keyword with a floating point correctly. In Remix your 0.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 returns 100000000000000000:

function test() public pure returns(uint){
return 0.1 ether;
}

enter image description here

If you put this WEI value into an Ethereum unit converter, you can see the number's equivalent in GWEI and ETH:

enter image description here

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, and call instead of transfer for sending the ETH:


contract AB {

error CallFailed(); error TransferAmountTooLow();

uint amount= 0.1 ether;
address payable b = payable(0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2);


 function Optimizer( )public  payable{ 
  if(msg.value < 0.1 ether) {
    revert TransferAmountTooLow();
  }
  (bool sent,) = b.call{value: msg.value}("");
  if(!sent) {
    revert CallFailed();
  }    
}

}

Rohan Nero
  • 1,562
  • 2
  • 7
  • 27
  • will it be okey on the mainnet, i mean with real funds & will it transfer 0.1 eth to specific address? – stofu Oct 09 '23 at 20:53
  • @stofu if you can compile and deploy the contract on a testnet/locally, it will compile and deploy on mainnet in the same way, so yes. – Rohan Nero Oct 09 '23 at 21:15
  • i deploy the contract on test net but its not sending eth and its also no meeting the condition of require(amount >=0.1 ether,"transfer amount to low"); – stofu Oct 10 '23 at 13:02
  • @stofu can you provide the contract address and the name of the testnet you deployed it on? Also what input are you sending along with the function call? If you deployed your contact exactly as it is in your question, then there are a couple of reasons why it wouldn't work, for example payable(xx) and _amount = msg.value – Rohan Nero Oct 10 '23 at 14:11
  • goril, input:0.4 as a parameter in optimizer function. its the same error if you deploy locally( in remix) – stofu Oct 10 '23 at 14:14
  • @stofu what is the exact error message you are getting? – Rohan Nero Oct 10 '23 at 14:14
  • transact to AB.Optimizer errored: Error encoding arguments: Error: invalid BigNumber string (argument="value", value="0.5", code=INVALID_ARGUMENT – stofu Oct 10 '23 at 14:15
  • ok............. – stofu Oct 10 '23 at 14:19