Questions tagged [gas-estimate]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
34
votes
3answers
16k 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 ...
18
votes
2answers
24k 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 ...
20
votes
5answers
22k 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 ...
17
votes
1answer
7k 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 ...
1
vote
2answers
1k 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; ...
5
votes
2answers
4k 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 ...
8
votes
2answers
5k 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 ...
8
votes
2answers
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 ...
6
votes
3answers
6k 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(){ ...
4
votes
1answer
7k views

I'm getting "invalid opcode: opcode 0xfe not defined", when trying to estimate the gas fees

I'm trying to estimate gas fees of a contract that I'm about to execute. My code is as follows. import Web3 from "web3"; const web3 = new Web3(); const estimateGasLimit = async ( ...
0
votes
2answers
212 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?
2
votes
1answer
160 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, ...
2
votes
1answer
504 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(), ...
12
votes
2answers
6k 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, ...
7
votes
2answers
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, ...
5
votes
1answer
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?
6
votes
1answer
770 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 ...
3
votes
3answers
8k 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" : ...
2
votes
1answer
2k 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.
2
votes
1answer
1k 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 ...
0
votes
0answers
109 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 ...
6
votes
2answers
12k 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 ...
4
votes
1answer
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 ...
3
votes
1answer
59 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, ...
3
votes
2answers
7k 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://...
2
votes
2answers
162 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 ...
2
votes
2answers
227 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, ...
2
votes
1answer
161 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 ...
1
vote
1answer
1k 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, ...
1
vote
1answer
2k 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; ...
0
votes
0answers
25 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 ...
0
votes
1answer
232 views

Question about Gas and Gas Price

In my transaction: gasPrice: 210000 blockHash: "0x69bd71736f2a5d2c83919a0de81a7de0b6b690bb6bdda3acff254d5c68f634bc", blockNumber: 3178, from: "0xc8caa71c16299b40b8579742a27ee53162886040", gas: ...