Skip to main content
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
15 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
  • 28.1k
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
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,790
13 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.8k
11 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
11 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
  • 271
9 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
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 ...
qbsp's user avatar
  • 4,377
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
  • 55.6k
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.9k
8 votes

How much gas and gasPrice to set when signing a transaction?

The amount you will pay for a transaction is gasPrice*gas, so gasPrice is exactly what the name indicates, is the price per 1 gas. The gas is a measure of how much computational work your transaction ...
Jaime's user avatar
  • 8,390
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

Why does zero to non-zero in storage take higher gas?

This is a form of state or storage rent. When you change a state slot from 0 (the default) to non-0, you are increasing the size of the overall state data. The overall blockchain data - the "...
Richard Horrocks's user avatar
7 votes

How does EIP-1559 make Ethereum fees better?

EIP-1559 introduces a number of things and there's many explanations, and here's one approach at explaining. EIP-1559 allows simpler UX for fees and improves the consistency of transactions being ...
eth's user avatar
  • 86.5k
6 votes
Accepted

Is there a 'default' gas price and does it change when price of ether relative to fiat rises?

Yes, there is a default gas price in the clients. For Geth, its gas price oracle (Gpo) has nothing to do with fiat. https://github.com/ethereum/go-ethereum/blob/master/cmd/utils/flags.go is Geth's ...
eth's user avatar
  • 86.5k
6 votes
Accepted

What is the relationship between Gwei and gas?

Gas is needed by miners to execute a transaction. The more complicated a transaction is, the more gas they will need. When you send a transaction, you (or your wallet program) has to configure two ...
Jesbus's user avatar
  • 10.5k
6 votes

Is gas consumed per contract call or during contract creation?

Both. All transactions on the network cost gas. Contract deployments often take much more than regular transaction calls to contracts, but some calls can be pretty expensive. As for actual numbers, ...
natewelch_'s user avatar
  • 12.2k
6 votes

Truffle and Ganache - do I need to set the same gas-price and gas-limit in both of them?

TL;DR: Yes you can use the same value. Here is why: Ganache Ganache is a local test Blockchain. -l or --gasLimit is the block gas limit (total amount in gas unit that can fit in a block). Let's ...
Greg Jeanmart's user avatar
6 votes
Accepted

How to determine transaction fees using web3.py

You can get this from the transaction receipt. You can use web3.eth.getTransactionReceipt(transaction_hash) It returns a dictionary with the field gasused, combining this with the gasPrice that you ...
Jaime's user avatar
  • 8,390
6 votes
Accepted

SLOAD costs 800 gas - how is it possible?

EIP-1884 (included in the Istanbul hard fork) changed the cost of an SLOAD from 200 to 800, which explains why you are seeing exactly 600 more than expected. It looks like the yellow paper has not ...
Shane Fontaine's user avatar
6 votes
Accepted

What is Lazy Minting in Ethereum?

According to https://blog.openzeppelin.com/workshop-recap-building-an-nft-merkle-drop/ Lazy minting uses cryptographic primitives, the artist can sign “minting authorizations” that later allow a user ...
AlphaColo's user avatar
5 votes

Are smart contracts expensive?

In the Ethereum network, every transaction is replicated and re-computed across every node in the network, so you're paying in some sense for the execution on every node, not just on a single server ...
k26dr's user avatar
  • 861
5 votes

Can I set the gas price to whatever I want?

To see what gas prices are currently being accepted by miners, and how long it will take your transaction to confirm with a given gas price, see EthGasStation.info. Here is a snapshot of the ...
pyggie's user avatar
  • 578
5 votes
Accepted

What gives ether it's intrinsic value?

I think this question is out of scope for this stackexchange and voted to close it, but since it's still open... (note that the first several sections are greatly-simplified world-views and thus ...
lungj's user avatar
  • 6,680

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