2

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

2 Answers 2

1

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

0

In my case, I was getting this problem in javascript. My code was executing

const tenGWEI = BigNumber.from("0.00000001"); // Throws Invalid BigNumber string

The right way is to get the right precision (9 in the case of GWEI) and then multiply by the amount you want. For example:

const oneGWEI = BigNumber.from(10).pow(9);
const tenGWEI = oneGWEI.mul(10);

You can check some of the precision values in the ethers docs https://docs.ethers.org/v5/api/utils/display-logic/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.