Questions tagged [gas-estimate]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
26
votes
3answers
12k 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 ...
19
votes
2answers
15k 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 ...
14
votes
1answer
3k 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 ...
11
votes
2answers
12k 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 ...
9
votes
1answer
3k 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, ...
9
votes
1answer
525 views

In web3.js, how do I accurately find total gas cost to deploy a new contract (including constructor)?

I am using a public node as my web3 privider, so I must sign all transactions manually. This includes transactions that create contracts. Currently, I use the following method to deploy contracts. ...
8
votes
2answers
3k 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 ...
7
votes
3answers
219 views

Composition Over Inheritance - Gas Efficiency

In OOP languages, composition over inheritance is a well-known best practice. Solidity is an OOP language too but there is also the gas efficiency issue. Question is, in Solidity, how do composition ...
7
votes
2answers
3k 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, ...
7
votes
2answers
1k 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
2answers
2k views

How to know, inside the contract function, the amount of gas that will be refunded in the end

Consider the following situation: my function can be divided into 2 parts Always consumes constant gas; Always results in a refund of 0 < R < 1500000 gas. After the second part had happened, ...
6
votes
1answer
530 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 ...
5
votes
2answers
3k 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(){ ...
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?
5
votes
1answer
4k views

Gas, gas price, gas cost

I have read in the documentation that the miner set the gas cost. Does this means that gas cost varies miner to miner ? If not, how it is determined ? Moreover, when a contract is referred in geth we ...
5
votes
1answer
491 views

Can't estimate gas usage in Mist 0.5.2

Since I upgraded to Mist 0.5.2, I get this when trying to transfer funds: We can't estimate your gas usage properly, as you need at least 1 ether in your account My account has 3 ethers.
5
votes
1answer
477 views

Is it possible to deplete all funds in an Ethereum account?

I have an Ethereum account loaded with Ethers and I need to spend all of them, leaving account final balance at exactly zero Weis. Is that possible? I know using method eth_estimateGas() and ...
5
votes
1answer
98 views

Why does gas cost explode with more than 7 variables in a struct

I'm assuming this has to do with Ethereum's 7 variable stack limit but in the following code test struct TestStruct5 { uint8 m_nOther1; uint8 m_nOther2; uint8 m_nOther3; uint8 ...
5
votes
1answer
327 views

eth_gasPrice often returns 20,000 Babbages, but not always. Why?

According to https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gasprice rpc-json method eth_gasPrice returns the current price per gas in wei. But I have several questions: What does exactly mean "...
4
votes
2answers
241 views

Do intermediate memory variables cost gas?

Example without an intermediate variable: uint startTime = 9; uint allowedTime = 7; require(now > startTime + allowedTime); Example with an intermediate variable: uint startTime = 9; uint ...
4
votes
2answers
3k 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 ...
4
votes
2answers
272 views

web3.eth.getGasPrice() always return 1GWei

For estimate transaction cost, I use web3.eth.getGasPrice() function. The return callback value always 1Gwei(1,000,000,000) in ROPSTEN. web3.eth.getGasPrice(function(error, result){ console.log(...
4
votes
1answer
524 views

How to provide gas value when we can't calculate it, when using arrays?

Recently, I am trying arrays(search) in browser-solidity and I found that the number of items in it causes changes in the gas consumption. For making a call we need to specify the gas amount but it ...
4
votes
1answer
1k 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 ...
4
votes
1answer
168 views

Testrpc transactions are failing. How do I perform a transaction when Mist cannot estimate gas?

I am attempting to perform transactions and create contracts using EthereumJS Testrpc. I set it up by running the following: Terminal 1: testrpc Terminal 2: mist --rpc localhost:8545 Running both ...
3
votes
2answers
1k views

Unaffordable gas limit for my Ethereum based crypto-coin

The gas limit for single send transaction is about 21000 gas. Now I am creating my own Ethereum based crypto-coin, and I want to keep its conversion rate as 1 coin = 1 US$ and about 0.02 US$ as ...
3
votes
2answers
194 views

Is there an estimate of average (e.g. monthly) gas usage per user?

With the whole discussion around "network value", I'm wondering how much gas the average account uses on a periodical basis. Let's say that the relevant account pool consists of any account that has ...
3
votes
1answer
317 views

Unreal big gas consumption for contract deploying

I have a big contract (more then 1000 strings of code). I deploy it without any problems. When i estimate the gas consumption let gas_need = Web3Helpers.web3.eth.estimateGas({data: code}); console....
3
votes
1answer
793 views

What is the cost of storing a transaction in blockchain vs cost of storing a transaction in aws database?

I am in the process of understanding Ethereum and blockchain technology. I am building a mobile app that needs to keep track of transactions between users. From what little knowledge I have of ...
3
votes
2answers
3k 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 ...
3
votes
0answers
38 views

Does 'estimateGas' behave the same on Ganache and on mainnet?

I noticed that estimateGas behavior in Ganache has changed: In version 6.4.1, it throws an exception if exceeding the gas-limit. In version 6.5.1, it returns the estimation even if exceeding the gas-...
3
votes
0answers
144 views

Can't debug transactions that fail during the Web3.js estimateGas() call? No Tx Hash

NOTE: I am doing my work with the Ganache v1.2.2 GUI client on a Linux Ubuntu 18.04 station. There are many revert errors that happen during the estimateGas() call that precedes the actual Web3.js ...
3
votes
1answer
251 views

Oraclize __callback function with unbounded gas usage

I am making a lottery contract and using Oraclize to select a winning number. Here is what I have now: The owner calls a finalize() function, which disallows new entries, and makes a call to ...
2
votes
1answer
36 views

Do I pay any fee to the miner if I call a non-constant function, when no state variable is changed?

Suppose I have a non-constant function which changes a state variable under some condition. In other words, the function may sometimes change this variable and sometimes leave it as is. Will I pay ...
2
votes
1answer
80 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
20 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, ...
2
votes
1answer
63 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 ...
2
votes
2answers
2k 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 to estimate gas for my function using web3 js only?

Hi this is my solidity function function closeBid(string _product) public{ } I want to estimate gas for this function so in web3 js I called this like var gas = MyContract.closeBid()....
2
votes
2answers
290 views

TokenTimelock gives out of gas errors when deployed within Truffle 4.0.1

I'm trying to deploy a contract using Truffle v4.0.1, within Truffle's own console but I keep getting out of gas errors. The constructor looks like: function MyAwesomeCrowdsale( uint64 ...
2
votes
1answer
295 views

Why `address.call` function “saves” unnecessary gas for after the internal execution?

I deployed a contract of a multisig wallet to ropsten and try to test its abilities: https://ropsten.etherscan.io/address/0x8bf20c41ee6a9fd84e81d6f6df872d9628cd08b2 Things that worked fine: Withdraw ...
2
votes
1answer
78 views

Why don't gas calculations take into account array size anymore?

I clearly remember that a couple of months ago when I tried to push some items into a storage array each consecutive 'array-pushing-transaction' took more gas to execute. In other words, it was ...
2
votes
2answers
204 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
54 views

How does ether transfer processed [duplicate]

I want to understand deeply how ether transfer processed and how 21000 of gas determined. Is this a simple constant fee of the transfer transaction or ether transfer transaction is the some predefined ...
2
votes
1answer
164 views

How to make this function more gas efficient?

I have this function: function foo(uint256 _a, uint256 _b, uint256 _c) { require(map[msg.sender].a == 1); require(map[msg.sender].b < 1); require(map[msg.sender].c > 1); ...
2
votes
1answer
320 views

Why estimateGas return 21001 instead 21000?

For example web3.eth.estimateGas({from: eth.coinbase, to: eth.accounts[1], amount: web3.toWei(1, "ether")}) return 21001, but not 21000, so why?
2
votes
1answer
93 views

Is it possible to estimate used gas based on algorithm's Big O?

[Example Algorithm 1]: I have an array of structs(PaymentReceipt[] paymentReceiptList;) and imagine there are around 1000 pushed items and array's size keep increases. Each item has a time_start and ...
2
votes
1answer
88 views

How do I figure out how much USD it will cost to deploy or execute methods on a contract?

Is there a simple tool for this or do I have to calculate it myself?
2
votes
2answers
74 views

Why miners do not simulate their list of transactions to detect a gas exceed and discard those Txs that exceed gas?

Base on this answer related to How Ethereum estimate the gas for running a contract?: Which brings the second point. geth gets its estimate by simulating the transaction itself, based on the ...
2
votes
1answer
162 views

How do I combine integers, to save gas on transaction data and storage?

For example, I have two integers: one is uint128, another is uint64. I want to store those two integers by converting them to bytes24. And when I use them, parse the bytes24 to uint128 and uint64. ...