Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert 21000 BigUInt estimated gas price into Wei ? #163

Closed
DiwakarThapa opened this issue Apr 16, 2019 · 1 comment
Closed

How to convert 21000 BigUInt estimated gas price into Wei ? #163

DiwakarThapa opened this issue Apr 16, 2019 · 1 comment

Comments

@DiwakarThapa
Copy link

No description provided.

@BaldyAsh
Copy link
Collaborator

BaldyAsh commented Apr 17, 2019

Hi, @DiwakarThapa . Sorry, but before I answer your question, it is better to make sure that we both understand what we are talking about.


I think you are talking about gas limit, not gas price. Usually the gas limit is equal to 21000, and it is the gas limit that needs to be "estimated".
Gas limit is the maximum amount of gas that the user is willing to pay to complete this action or confirm a transaction.
Gas price is the amount of Gwei that the user is willing to spend on each unit of gas.
In order to calculate the total cost of a transaction commission in Ether, it is necessary to multiply the gas limit by its price. For example, if the gas limit is 50.000 units, and the gas price is 20 Gwei, then this means that the sender is ready to spend 0.001 ether on the transaction. 50.000 * 20 Gwei = 0.001 Ether.
You can’t convert gas limit into Wei, because it is not measured in Wei.


But if you really want to covert some gas price into Wei from 21000 BigUInt, then make this

let wei = Web3.Utils.formatToEthereumUnits(biguint, toUnits: .wei, decimals: 18, decimalSeparator: ",")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants