Solidity Remix – Solving ‘invalid BigNumber String’ Error

remixsolidity

I got this error :

Error: invalid BigNumber string (argument="value", value="0.002", code=INVALID_ARGUMENT, 
    version=bignumber/5.5.0)

Smart Contract Code:

  contract DonateContract {
  AggregatorV3Interface internal priceFeed;


  address payable owner; // contract creator's address
  
  //contract settings
  constructor() {
    priceFeed = AggregatorV3Interface(0x2514895c72f50D8bd4B4F9b1110F0D6bD2c97526);
    owner = payable(msg.sender); // setting the contract creator
  }

  //public function to make donate
  function donate(uint256 _payAmount) public payable  {
      (bool success,) = owner.call{value: _payAmount}("");
      require(success, "Failed to send money");
      CRON token = CRON(0x1Fdd591131AB310F6eF4B6Fd67103FF3fA264A29); 
      (,int price,,,) = priceFeed.latestRoundData();
      int cost =  int(_payAmount) * 6 * price ;
      token.transfer(owner,uint256(cost)); 
  } 
} 

Basically I wanna type any amount in BNB and its usually a small number like this : 0.002

Best Answer

You should share how you are making the call, I'm assuming you are putting the value directly in remix and calling the function donate()

You can't use decimal numbers, also a 1 would be equivalent to 1 wei (smallest unit of ETH/BNB)

1 wei = 0.000000000000000001 BNB

Once you fix this, if what you are trying to do is to transfer BNB in the transaction itself you should look into how msg.value works and how to set a value in remix and if you still have questions create a new one :) Where to set msg.value

Related Topic