Units
1 ether = 1,000,000,000,000,000,000 wei.
1 gwei = 1,000,000,000 wei 1 ether = 1,000,000,000 gweiIn solidity everything is stored in wei values. There are no fractions nor decimals, we just work with integers. So by having this long zero values provide a way to have decimals without having decimals.
result = await devnetcoin.buyDEV({from: hank,
value: web3.toWei(1, "ether"),
gas: 508460,
gasPrice: web3.toWei('20', "gwei")})
web3.fromWei(web3.eth.getBalance(val).toString(), 'ether').toString()
Gas
To get basic fees to get some idea of how much gas, note the following:
- 32k gas to create a contract.
- 21k gas for normal transaction
- 200 gas * 1 byte of byte code.
- Transaction data costs 64 for non-zero bytes and 4 for zero bytes
- Constructor cost
See this response on Ethereum Stack Exchange.
The limit of computation per block is not constant. Miners can set this.
VALUE field - The amount of wei to transfer from the sender to the recipient, this is the value we are going to send to either another user or to a contract.
GASPRICE value, representing the fee the sender is willing to pay for gas. One unit of gas corresponds to the execution of one atomic instruction, Gasprice is in wei. Wei is a smallest unit. (1 wei = 10^-18 ether or 10^18 wei = 1 ether. Because it is quite high, we use gwei. 1 gwei = 1,000,000,000 wei.
Total cost of transaction is Gas Limit * Gas Price
Gas price fluctuates. During normal times:
- 40 GWEI will always get you in next block
- 20 GWEI will get you in the next few blocks
- 2 GWEI will get you in the next few minutes.
Depends on what minors are willing to take.
1 ether = 1,000,000,000 gweiTo see the current price for a unit of gas you can run:
web3.eth.gasPriceThe new function in web3.js 1.0.0 (still beta as of this writing) requires a callback:
web3.eth.getGasPrice(console.log)(the callbacks are always error, response in 1.0.0 so in the new stuff you'll get two values printed in the console log)
This will be about 20 Gwei. Or you can look to see what the Gas price is at the ETH Gas Station. The current price shown at the ETH Gas station is 11 Gwei (std) and 9 Gwei (safe low). Creating contracts seem to cost a little more.
In practice when we've created contracts we've seen that we can use the estimateGas function to tell how much for storing the bytes:
this.state.provider.eth.estimateGas({ data: contract.bytecode }, somecallbackfunction)
The callback function for the contracts we've been working on shows the gas limit (or amount of gas) is about 645234. But this is only the cost of storing the contract code on the blockchain. You need to add more gas limit for creating the contract, for passing parameters, etc. We've found that by adding 80000 more to our gas Limit the contract goes through.