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 ...
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 ...
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 ...
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 ...
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, ...
9
votes
3answers
435 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 ...
9
votes
1answer
1k 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
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 ...
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 ...
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, ...
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(){ ...
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
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 ...
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 ...
6
votes
1answer
242 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
2answers
850 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 ...
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 ...
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
499 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
2answers
3k 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(...
5
votes
1answer
552 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
129 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 ...
5
votes
1answer
685 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 "...
5
votes
0answers
42 views

Deploy gas issue for require reason string

I found a strange case and didn't find out why. ... modifier onlyMaster() { require(msg.sender == master || msg.sender == developer, "caller is not the master"); _; } ... ...
5
votes
1answer
541 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 ...
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 ( ...
4
votes
2answers
899 views

Understanding Gas Fees for NFTs

I am going to mint a collection of 10,000 NFTs. However, I've become very concerned over the gas costs associated with such an endeavor. I was wondering if someone could help me understand the ...
4
votes
1answer
2k views

Remix error "gas required exceeds allowance or always failing transaction" on private blockchain

I'm trying to test contract interaction using Remix with two basic contract: contract Callee contract Caller Callee function/variable: uint[] public values; function storeValue(uint value) { ...
4
votes
1answer
630 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
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 ...
4
votes
2answers
411 views

Is there a Gas Cost profiler

I am trying to figure out what part of a complicated smart contract transaction is responsible for the cost. I was wondering if there is already a tool for that. Ideally it would spit out you are ...
4
votes
0answers
118 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-...
4
votes
1answer
185 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
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://...
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" : ...
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
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
217 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
2k views

What is the approximate cost to store a mapping to be used in a contract?

Given a simple address to address mapping as follows: mapping (address => address) public matches; Can someone give me an idea of the cost in ether to store something like this in a solidity ...
3
votes
1answer
344 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
921 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
1answer
426 views

Contract is sent and gets an address, but eth.getCode returns 0x

I'm trying to deploy a contract on a private blockchain network. My solidity code has a lot of variables used in it. The deployment does give me a contract address, however, when trying to retrieve ...
3
votes
0answers
574 views

Ethers and Web3-React: Cannot estimate gas when trying to connect with contracts deployed on testnet and using Alchemy as node provider

I'm trying to connect with contracts deployed on the Rinkeby testnet using a node provider. When I was testing using hardhat as a local node, the contracts are called with no problem, but when I ...
3
votes
1answer
310 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
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(), ...
2
votes
2answers
11k views

How can I calculate the gas fee of a swap on Uniswap?

According to gas tracker on Etherscan the average gas price is 212 gwei and the average Uniswap swap estimate is $70.26 which implies that the gas fee is around 201101. To my knowledge swap gas fee is ...
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
1k views

How to optimize the gasPrice and gas options in a contract send() function? [duplicate]

There are many questions and answers about estimating the amount of gas consumed. This question is about what to do with this estimate. What values should we actually provide to gas and gasPrice in ...
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
2 3 4 5