question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support unit parsing in all relevant configs (e.g "10 ether", "200 wei", etc..)

See original GitHub issue

Outline

A lot of configurations in embark need to define an amount in wei. The goal of this task is to support specifying these values as a nice string of the type “<number> <unit>” for e.g “200 finney”. The code for this is already available in embark in the utils class here. The goal is to support this feature in all the required configs.

Acceptance Criteria

  • support “<number> <unit>” config ** unit can be: wei, kwei, Kwei, babbage, femtoether, mwei, Mwei, lovelace, picoether, gwei, Gwei, shannon, nanoether, nano, szabo, microether, micro, finney, milliether, milli, ether, kether, grand, mether, gether, tether ** in the following fields: *** config/blockchain.js : gasPrice *** config/contracts.js: gasPrice *** any other relevant fields
  • if the config value is a) not a string nor b) the unit is not specified nor c) is a string starting with ‘0x’ then the value should be assumed to be in wei

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:23 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
0x-r4bbitcommented, Sep 20, 2018

@kpulkit29 It is indeed a bit hard to follow if you aren’t familiar with the codebase (neither am I). However, I did some digging and I think what needs to be done is this:

  • @iurimatias mentioned that a lot of gas related configurations in embark need to be defined in Wei. AFAICT, he’s referring to configuration options like gas, gasLimit and targetGasLimit. Notice that those options are used in contracts.json, genesis.json and blockchain.json respectively. Every embark project has these files.

  • Now, you can see that all of these options define their value in different formats, sometimes it’s a string ("auto"), sometimes it’s a hex string ("0x...") and sometimes it can be a number (800000). All of these values are just different representations. A value can be represented as hex code, binary or decimal number.

  • Specifying values in Wei can be quite cumbersome, considering how huge the numbers can get (1 Ether = 1,000,000,000,000,000,000 Wei (10^18)), that’s why programs often us hex codes to make values easier to read, parse and digest. For humans, it’d be even better if one could say "1 ether" instead of 1000000000000000000, or use any other unit that makes sense (Gwei, shannon, finney etc.)

  • It turns out that embark already comes with utility functions to take such a human readable string representation and turn that into the Wei format that embark needs to do its work. One of those functions is getWeiBalanceFromString()

  • So what needs to be done is find the places where those configuration files are being loaded (e.g. here and here) and pipe their gas, gasLimit and targetGasLimit values through the utility function before they get merge into the overall configuration object, which essentially results in users being able to specify their values in human readable formats 😃

To be fair, I couldn’t find a configuration option for gasPrice in the codebase that is configurable for users/consumers, but I’m sure @iurimatias can shed some light into darkness here.

I hope this makes sense and @iurimatias and @jrainville please correct me here if anything of this is wrong!

Does this help @kpulkit29 ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support unit parsing in all relevant configs (e.g "10 ether ...
The goal of this task is to support specifying these values as a nice string of the type "<number> <unit>" for e.g "200...
Read more >
Documentation - Ethers.js
The JSON-RPC API is another popular method for interacting with Ethereum and is available in all major Ethereum node implementations (e.g. Geth and...
Read more >
Display Logic and Input - ethers
The parseUnits will parse a string representing ether, such as 1.1 into a BigNumber in wei, and is useful when a user types...
Read more >
Cisco Firepower 4100/9300 FXOS Command Reference
To view information about operations and current configuration in various command modes, use the show command. Many of the FXOS CLI command modes...
Read more >
Remix Documentation - Read the Docs
Remix IDE is used for the entire journey of smart contract development by users at every knowledge level. It requires.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found