I am building a Shared Wallet contract as a project. As I have started working on the front end in react web app I have encountered the problem that javascript cannot store large numbers. I could not figure out how to pass big numbers as inputs when calling my solidity functions so I decided to simply store my values in ether and convert within solidity.

eg: (where toWei is set to 1e18)

function UpdateAllowance(address _user, uint _amount) internal onlyOwner Permissions(_amount) {
         _amount = _amount*toWei; //SEE HERE
        emit AllowanceChange(_user, msg.sender, allowance[_user]._allowance - _amount, allowance[_user]._allowance, _x - int(_amount));
        allowance[_user]._allowance -= _amount;

The problem now is that I do not know how to apply this to my receive function:

receive() external payable {
    emit BalanceChange(msg.sender, int(msg.value), address(this).balance);
    emit PaymentIn(msg.sender, msg.value);

Is there a way to modify this function to take ether as an input, or apply a similar conversion as above?

Alternatively, I have no problem converting number to big number in js but I could not manage to get this to work when using BN as an input when calling my solidity functions from the web app. If you can give me advice how to do that that would also work as a solution. Any help is greatly appreciated!

1 Answer 1


In the frontend, you can use the ethers.js library to convert a string representing the number into a BigNumber and then pass that into the contract. In this case you would use ethers.utils.parseUnits to convert a user input in, for example, ETH into Wei, although you can also use it for any number of digits.

Here's the ethers documentation page that explains the function.

  • Awesome, thank you! I'll look into that
    – millbird
    Commented Dec 2, 2021 at 4:13

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.