As of May 31, 2023, we have updated our Code of Conduct.
31 votes
Accepted

how to estimate gas cost?

Using Truffle and testrpc. It's actually pretty easy to build a development environment and test different use cases. For the gas estimation, it's mostly based on Web3 native functions: You can ...
Greg Jeanmart's user avatar
29 votes

Gas price in ETH unit

There is no fixed gas price that transactions must have. You can specify the gas price, and if you set a gas price within certain bounds, the transaction will be accepted by miners using their ...
eth's user avatar
  • 83.3k
19 votes
Accepted

Where does the consumed ether/gas go?

Gas is paid for out of the sender's ether balance, at the rate specified by the chosen gas cost. Any unused gas is refunded, and consumed gas is credited to the miner who mined the transaction, again ...
Nick Johnson's user avatar
  • 8,004
18 votes
Accepted

Can I set the gas price to whatever I want?

Can I set the gas price to what ever I want? Yes, you can. But miners have a default strategy for determining gas price to charge and if the amount you're willing to pay is below that, your ...
linagee's user avatar
  • 6,038
17 votes
Accepted

How much does it cost to use a contract?

The total cost of a transaction that creates a contract or executes a contract is based on 2 factors: gasUsed is the total gas that is consumed gasPrice specified in the transaction Total cost = ...
eth's user avatar
  • 83.3k
15 votes
Accepted

Why not mine my own transactions?

Why shouldn't I set up a miner account, which would mine only transactions with the lowest gas-price possible - 1 wei? Yep, you can, but... Should some other miner catch them first (for some odd ...
Richard Horrocks's user avatar
14 votes
Accepted

How does "Gas Price Oracle" work?

This blog post (old since default gas price is currently 0.02 szabos) from Stephan Tual has the hint: The default gas price is set at 50 shannon (0.05 szabos, or 0.00000005 ether). Remember that ...
zanzu's user avatar
  • 5,270
14 votes
Accepted

How can I set the gas price while deploying a contract with web3.js?

From the documentation: var contractInstance = MyContract.new([constructorParam1] [, constructorParam2], {data: '0x12345...', from: myAccount, gas: 1000000}); Yes, you can just add a gasPrice to ...
user19510's user avatar
  • 27.6k
13 votes

How to get the actual Gas price?

web3 has an async function called getGasPrice. In a geth terminal I can use: web3.eth.getGasPrice(function(e, r) { console.log(r) }) This currently returns 20000000000 in geth on mainnet (20 Shannon)...
ZMitton's user avatar
  • 2,710
12 votes
Accepted

How to get the actual Gas price?

EDIT: with EIP-1559 (shipped in London fork in July 2021) this is not true anymore. I'm changing this answer to community wiki so that anyone can fix it (I don't really have time, sorry) As explained ...
12 votes

What were the key assumptions and analyses that went into setting Ethereum's gas price?

I suspect that the question about the price discovery mechanism of gas/Ether was not studied very deeply by the Ethereum developers. The mechanism that currently exists must work by miners adaptively ...
Alexey Akhunov's user avatar
12 votes

Why not mine my own transactions?

In order to have a 1% chance of finding a block, you need 1% of the global hash rate. And that will cost you, a lot. A back of the envelope computation tells me you'd need about 1 million Nvidia GTX ...
Tudor Constantin's user avatar
12 votes
Accepted

Why is it so expensive to trade on Uniswap with MetaMask? ($50 fee)

The answer is that uniswap is a set of Smart Contract running on the Ethereum platform and thus requires gas in order to execute any functions. Meaning that when you swap token A for token B or token ...
People Call Me Adam's user avatar
11 votes

how to estimate gas cost?

The answer provided by Greg Jeanmart perfectly explained how to estimate the gas cost for a function. Here I want to point out that the design of your function giveAwayDividend() might be vulnerable ...
longcc's user avatar
  • 146
11 votes
Accepted

How do events influence a transaction's gas?

The increase it by 375 + 375 * numberOfIndexedParameters + numberOfUnindexedBits. For example: event Event(uint16 indexed a, uint32 indexed b, uint64 c, uint128 d); emit Event(1, 2, 3, 4); The ...
goodvibration's user avatar
11 votes
Accepted

what is difference between "gas" "gas price" and "fee"?

in a nutshell : gas is the cost unit gas price is a single gas unit's price and Fee= gas*gas price why using gas instead wei? because we need a fixed value (unit) for expressing the ...
Badr Bellaj's user avatar
  • 18.4k
10 votes

Can I send gas to another user?

Gas is not a token or a cryptocurrency. It is the most granular unit of payment for deploying and executing code in Ethereum. Currently conversion of ether to gas happens at the point where ...
Alexey Akhunov's user avatar
10 votes

Where does the consumed ether/gas go?

Gas consumed x Gas price = transaction fee. The transaction fee is paid to the miner of the block similar to Bitcoin.
bamos's user avatar
  • 1,934
10 votes

How do I retrieve the exact gas costs spent for a transaction with ethers.js?

After a bit of searching I figured out that the receipt should be the mined object.. I also wasn't sending any value with the transaction. const addr1Bal = await provider.getBalance(addr1....
love lain's user avatar
  • 231
9 votes
Accepted

Disable mining/gas/ether or set really low

There are several different options for a private/consortium chain setup: Use a custom genesis block to set the difficulty level for mining to make it less intensive. Only turn mining on for some of ...
dbryson's user avatar
  • 6,303
9 votes
Accepted

How to get the transaction cost in a Truffle unit test?

You have to multiply the gasUsed for the gasPrice. The gasUsed is contained into the transaction receipt. While the gasPrice is into the transaction itself. Indeed, in your case, you're trying to ...
mirg's user avatar
  • 4,287
9 votes
Accepted

weird transaction sending to self

It's about canceling a transaction. More precisely, it's a replacement transaction for something else that was in the pending transaction pool. Consider a case where a transaction is sent with ...
Rob Hitchens's user avatar
  • 54.3k
9 votes
Accepted

How do I set a gasPrice with ethers deploy script?

You can override the options property of a transaction by adding an object as the last parameter: const mycontract = await MyContract.deploy({gasPrice: 50000000000}); // 50gwei You can also specify ...
Anton Cheng's user avatar
8 votes
Accepted

Gas cost of different computations

Take a look to http://ethdocs.org/en/latest/contracts-and-transactions/account-types-gas-and-transactions.html. Also, check the following spreadsheet: https://docs.google.com/spreadsheets/d/...
Albert Palau's user avatar
8 votes
Accepted

How can I estimate price of data storage?

Currently the only times you pay for storage are when you write it and when you read it back. There is no ongoing cost for storage, although there have been some discussions about whether there should ...
Edmund Edgar's user avatar
  • 16.7k
8 votes
Accepted

Does ERC-20 balanceOf function cost no gas?

In Ethereum there are two ways of interacting with a smart contract: transactions and calls. Calls are possible only for function which are marked as pure or view. If you issue a call to such ...
Lauri Peltonen's user avatar
8 votes
Accepted

What's the vulnerability in my contract?

It sounds like you are being front run. This means that a bot is watching you send a transaction, reading the input (specifically, _answer), and submitting a transaction with the correct answer but a ...
Shane Fontaine's user avatar
7 votes

How are miners minimum acceptable gas price determined?

Replying to euri10's question (this should be a comment instead of an answer but I cannot format in comments), here is the geth --help snippet that displays the options to set the gas price options - ...
tsarbucks.eth employeeoftheday's user avatar
7 votes
Accepted

Should I use the default gas price?

The default gas price is 50 shannon on frontier, 20 on Homestead. (remember to upgrade) Vitalik recently ran a test to see how long it took for transactions with different gas prices to be included, ...
MrChico's user avatar
  • 1,776
7 votes
Accepted

Geth Gas price too low for acceptance

This is a limitation of the 1.3.x stable branch. This check was already removed for own/local transactions in the 1.4 branch (https://github.com/ethereum/go-ethereum/pull/1997), allowing you to insert ...
Péter Szilágyi's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible