Skip to main content

Questions tagged [gas-estimate]

Filter by
Sorted by
Tagged with
43 votes
3 answers
21k views

What are the limitations to estimateGas and when would its estimate be considerably wrong?

web3.eth.estimateGas and JSON-RPC estimateGas can be used to see how much gas should be specified for a transaction, before crafting the transaction. Since it is an estimate, are there any ...
eth's user avatar
  • 86.5k
19 votes
2 answers
32k views

how to estimate gas cost?

I have a function that iterate through an array, which could cost a lot of gas. But I still want to test out the estimate gas cost, then decide if I should maintain the design or not. function ...
dome some's user avatar
  • 319
23 votes
5 answers
29k views

How to estimate gas at contract creation/deployment to private ethereum blockchain

What I have done a) When I use web3.eth.estimateGas to estimate the cost of a contract creation constructor with no parameters, the estimate is correct. b) If the contract is already deployed then ...
Imroz's user avatar
  • 871
18 votes
1 answer
8k views

What happens if transaction runs out of gas before transaction completes?

As gas cost can only be estimated until the transaction is executed against the actual contract state at the time of execution on the blockchain, what happens if transaction runs out of gas before the ...
zanzu's user avatar
  • 5,400
8 votes
3 answers
15k views

Getting infinite gas estimates for simple functions

I am testing out solidity in remix ide using simple contracts. This is the contract that I wrote: contract mortal { address owner; function mortal() { owner = msg.sender; } function kill(){ ...
Ahsan Jamal's user avatar
3 votes
2 answers
1k views

Does using a very high gas limit somehow get your transactions executed slower?

I'm executing transactions on mainnet with a NodeJS script: async function send(web3, transaction, destAddr, gasPrice, privateKey) { const options = { data : transaction.encodeABI(), ...
goodvibration's user avatar
9 votes
2 answers
6k views

How to estimate the cost to call a Smart Contract method?

After succesfully deployed this Smart Contract on Ethereum testnet https://testnet.etherscan.io/address/0x27c042342C9ba937214117e11A4970A6145034cB is it possible to calculate how much gas is going ...
Juan Ignacio Pérez Sacristán's user avatar
8 votes
2 answers
2k views

Infinite gas estimation from solc for simple function

Here is a simple Solidity contract: pragma solidity ^0.4.16; contract Test { uint[] array; function testGasEstimation() public { array.length = 1; } } Here is the output of ...
medvedev1088's user avatar
1 vote
2 answers
2k views

How to estimate gas for a function without any input parameter?

How to estimate gas for a contract function that doesn't take any input parameter bu changes state? For eg, function buy() returns (uint amount){ amount = msg.value / buyPrice; ...
Prashant Prabhakar Singh's user avatar
6 votes
2 answers
6k views

How can I estimate price of data storage? [duplicate]

I'd like to make estimations of the cost of an application, and one of the things I need is the price to store n kB of data on a contract. In ether and in USD. Where could I find rates or prices of ...
Teleporting Goat's user avatar
5 votes
1 answer
1k views

Is it possible to calculate the gas costs of a transaction exactly upfront?

In the Ethereum wallet there are the estimated gas costs. Why is it only an estimate? Is is possible to calculate the gas costs precisely upfront?
mKoeppelmann's user avatar
  • 7,636
2 votes
1 answer
372 views

Sending a transaction - can I assume that when the 'data' field is missing, the 'gas' field should always be 21000?

I have implemented a function for transferring ETH from my account to another account: async function transfer(to, value) { let options = { from : PUBLIC_ADDRESS, to : to, ...
goodvibration's user avatar
0 votes
2 answers
323 views

Will same contract consume different gas in different network?

I have a contract deployed both in test and main network and if i execute same method with same parameters, will gas used differ?
Madan's user avatar
  • 65
26 votes
4 answers
76k views

Estimate gas price with ethers.js

I'm looking to estimate transaction fees in an application. In order to do so I need to estimate the current gas price before I execute the transaction. I see web3.js has a getGasPrice method: https://...
Sam Richards's user avatar
14 votes
3 answers
11k views

How to whitelist up to 50k addresses in a single contract?

What is the best practice in whitelisting a large amount of addresses in a contract. For example, if I wanted to include 50k addresses into a mapping that will reflect true for only the 50k addresses, ...
blockchaindotsol's user avatar
10 votes
2 answers
28k views

Correct syntax for estimating gas cost of a function in Web3?

Suppose I have the following function: function SetMessage (bytes32 _message) returns (bool success) { message = _message; return true; } Which might be called in Web3 as follows, for ...
ZhouW's user avatar
  • 1,358
8 votes
1 answer
361 views

Can I estimate the total gas limit of several dependent transactions?

Assume two dependent transactions A and B. Transaction B depends on transaction A and will fail if transaction A has failed. I would like to estimate the gas limit required for the success of both ...
amanusk's user avatar
  • 266
7 votes
2 answers
4k views

Mist Testnet error "it seems this transaction will fail"

I am very new to Ethereum, and just working through some early tutorials using the testnet. My version is up to date; the blockchain is also up to date; and I have only one account in the keystore, ...
Benc93's user avatar
  • 393
6 votes
4 answers
23k views

how to estimate gas limit when using web3.eth.sendSignedTransaction

I am using web3 to transfer tokens by using web3.eth.sendSignedTransaction. When I am setting the parameter rawTx like var rawTx = { "from" : walletbase, "nonce" : ...
E.W's user avatar
  • 83
6 votes
1 answer
1k views

Gas estimation for mapping updating with web3js

The gas estimation for contract deploying with web3js will look like: var res = web3.eth.estimateGas({ from: web3.eth.defaultAccount, data: contractByteCode }); For example, I have the ...
Victor Baranov's user avatar
5 votes
1 answer
2k views

How to minimize gas consumption during contract creation

I have trouble deploying a contract to the main network and I believe this is due to high gas consumption. An earlier version of the contract worked on the main network. The current version works in ...
Max Binnewies's user avatar
4 votes
3 answers
6k views

How do you estimate the gas cost of any arbitrary function in Remix IDE?

I've found plenty of information on how to do this using Truffle and Web3, but nothing regarding how to achieve this in the Remix IDE. Examples would be very much appreciated.
John DeBord's user avatar
3 votes
3 answers
846 views

MetaMask incorrectly estimates 100,000 gas for ERC20 transfer. Why?

MetaMask is incorrectly limiting the gas limit estimate to 100,000. This is actually a rather complex "transfer" that will need about 145,000. Why does MetaMask limit ERC20 .transfer() to ...
Rob Hitchens's user avatar
  • 55.6k
3 votes
1 answer
117 views

Gas used for the same deterministic operation is different

standard ICO function which exchanges Ether to ERC20 token balance. Call 1, used 49431: https://ropsten.etherscan.io/tx/0x6671c8fd39d195b09868d914d80f0e884e42259c7346b69afb483f2e18fae263 Call 2, ...
lebed2045's user avatar
  • 295
3 votes
2 answers
310 views

Does execution of same function in a contract uses different amount of gas each time it's executed

1-Does execution of same function in a contract uses different amount of gas each time it's executed? 2-Also if same function (for eg, transfer() function) is written in two different contracts, ...
Prashant Prabhakar Singh's user avatar
3 votes
2 answers
5k views

Ethers js estimateGas() without needing ETH in account

I am trying to estimate the gas used for a uniswap transaction. I am able to perform this on the Kovan testnet however when I try and run the same script on the mainnet it raises an error, "Error:...
Mvteyv's user avatar
  • 55
3 votes
1 answer
411 views

Gas cost tests: Sending a transaction to a new address is more expensive?

A friend and I were thinking about transaction costs, is there any attached cost to send a transfer to a new address that has not been stored on chain before? So we started digging. First off we ...
Enrique Alcazar's user avatar
2 votes
2 answers
1k views

I set a 3 gwei for gas price. Now my transaction has been pending for 48+ hours now. But blocks aren't even full!

I tried to set a gas price of 3 gwei for interacting with a smart contract. Now the transaction is pending for 48+ hours. If the blocks aren't full, why dont the miners pick it up? I can bump the fee ...
Patoshi パトシ's user avatar
2 votes
0 answers
523 views

Is gasleft() the best way to manage big loops in solidity?

I'm developing an Smart Contract that has to iterate through an undetermined size list of ERC20 tokens, and make a swap for each token. I'm aware that you cannot loop an undetermined size list, ...
Alexander Herranz's user avatar
2 votes
1 answer
937 views

Can miner himself add a transaction with a zero gas price?

In general it doesn't make any sense to send a transaction with zero gas price. Probably it will be pending forever. But what about miner - can he: Send some transaction with zero gas price (so the ...
Sergey Potekhin's user avatar
2 votes
1 answer
2k views

How to caculate/estimate Gas Limit and Gas Price based on current state of the ether network?

Ethgasstation and similar websites estimate proper Gas Price based on current state of Ethereum network. Is there any way of using working with Geth/web3 to estimate proper Gas Price? and similar to ...
Vahid Kharazi's user avatar
2 votes
1 answer
3k views

Getting 'base fee exceeds gas limit' on a transaction which requires a small amount of gas

I have the following contract: pragma solidity ^0.4.24; contract MyContract { address public owner; bool public unlocked; constructor() public { owner = msg.sender; ...
goodvibration's user avatar
1 vote
1 answer
354 views

Different gas cost for same operation?

I'm running a smart contract locally on TestRPC and using MetaMask to interact with it. Repeatedly calling the same function with the same parameters seems to accumulate different gas consumption (...
Adam Szabo's user avatar
1 vote
1 answer
2k views

"Gas estimation failed" on Ropsten using MetaMask!

I'm testing a smart contract using Remix, MetaMask, Ropsten. Yesterday I developed my contract on Ropsten network and everything goes in the right way. Today I was developing the SAME contract code, ...
Louisio95's user avatar
  • 101
1 vote
1 answer
67 views

Block Gas Limit Doubt

Suppose i have a loop. Here user is a struct of which player is an address. address[] memory addrs = new address[](n); for(uint i=0;i<n;i++){ addrs[i] = user.player; } return addrs; This is a ...
Sundeep Kumar's user avatar
0 votes
1 answer
417 views

Estimating Gas Cost for Smart Contract Deployment Using Foundry

I'm trying to estimate the gas cost for deploying a smart contract using Foundry. Can someone provide guidance on how to do this accurately?
adam mr's user avatar
  • 141
0 votes
1 answer
332 views

Question about Gas and Gas Price

In my transaction: gasPrice: 210000 blockHash: "0x69bd71736f2a5d2c83919a0de81a7de0b6b690bb6bdda3acff254d5c68f634bc", blockNumber: 3178, from: "0xc8caa71c16299b40b8579742a27ee53162886040", gas: ...
s k's user avatar
  • 886
0 votes
0 answers
155 views

Why does my private network transaction use a different amount of gas than my mainnet transaction performed immediately after?

I am forking the mainnet from my own geth node with ganache-cli --fork option. Immediately after the fork, I simulate a transaction to a contract on the forked, private network. I then immediately ...
python_crypto_questions's user avatar
0 votes
0 answers
77 views

How can I measure gas in solidity to increment a user's balance according to the amount of gas spent to call the function? [duplicate]

I have a function that I am calling and based on the logic of that function and how much gas it spends to execute the function, I want to increment a user's balance to reimburse the user for the gas ...
lopezdp's user avatar
  • 123
0 votes
3 answers
1k views

How can I get the current ETH gas fees in python

I am trying to make a python program that gets the ETH gas prices. I am trying to avoid selenium scraping because I am using this for a discord bot. Does anyone know any good python APIs I can use?
Pixeled's user avatar
  • 101