3

In my Solidity smart contract, there is a function that needs to receive an amount as parameter.

This parameter is the value to be used for a transfer function. Considering the user may need to transfer 1.25 Ethers, how can he input this data, as there´s not a data type for it?

1 Answer 1

5

For the transfer you can specify the amount in wei, which would be 1250000000000000000 for 1.25 ETH. For that you can use unsigned integer. No need for decimals.

In most cases (not only for ETH) you can avoid using decimals by scaling the value to the desired precision.

4
  • see also ethereum.stackexchange.com/questions/19629/…
    – ivicaa
    Feb 20, 2018 at 20:57
  • Yes, this is a work around. Technically, it works. But in real life it´s not a good approach asking the user to input somethiing like 18 digits just to mean "1". Is there another way?
    – MCreimer
    Feb 21, 2018 at 17:04
  • You don‘t have to present it like that in your User Interface. IMHO, technically smart contract is backend code. Anyway nothing for non-techies without a nice frontend.
    – ivicaa
    Feb 21, 2018 at 17:13
  • OK, I guess this is an front-end problem. Today I´m using Mist, but in production environment, using web3.js I guess I will not have this problem anymore. Thanks
    – MCreimer
    Feb 21, 2018 at 20:20

Your Answer

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

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