0

I asked this question, and then I figured out the answer with help from folks here in this exchange.

QUESTION

I have contract functions that return a uint256 amount. This amount is related to the contract's balance. So it shows up in Wei (I guess), as a very large number, in Ethereum Wallet.

Can I return this number in Ether so that it shows up in a more friendly way in the Wallet and I don't risk messing up units in calculations? Or do I have to manually convert units and return a uint256 as divided by some constant?

ANSWER

Well, a function returns a value of a given type, for example, in this case, uint256.

The money units available in solidity are constants, and have no relation to the type system.

bumped to the homepage by Community yesterday

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

You can manually convert it once the contract function has returned the value with the web3 object.

For the old web3 object you can do web3.fromWei(weiValue, 'ether') where 'weiValue' is the value your contract function returns, to get the value as Ether.

For the new web3 object, version 1.0, it will be web3.utils.fromWei(weiValue, 'ether') where 'weiValue' is a string of the value your contract returns. Note you have to convert it to a string first. See: http://web3js.readthedocs.io/en/1.0/web3-utils.html#towei

  • Thanks for the answer, but there is a point missing and I would be very thankful if you could help as well: can I configure the Ethereum Wallet to read those values in friendlier way? – blue-dino Jan 16 '18 at 15:16
  • When you say Ethereum Wallet, are you referring to Mist? – willjgriff Jan 16 '18 at 22:20
  • I was using the default ethereum wallet. I don't know if it is mist; but I figured out what was wrong and I will edit the question and turn it into a KB page. – blue-dino Jan 17 '18 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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