Questions tagged [gas-estimate]
The gas-estimate tag has no usage guidance.
356 questions
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 ...
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://...
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 ...
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 ...
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 ...
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, ...
10
votes
4
answers
1k
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 ...
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 ...
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 ...
9
votes
1
answer
2k
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
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(){
...
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 ...
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 ...
7
votes
2
answers
2k
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 ...
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, ...
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" : ...
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 ...
6
votes
2
answers
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
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 ...
6
votes
1
answer
473
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 ...
6
votes
2
answers
117
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
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?
5
votes
1
answer
3k
views
Understanding "eth_estimateGas" results estimating gas
I have been playing around with parity's "eth_estimateGas" call to determine different tokens gas requirements. Generally using this code:
let transfer_data = contract.transfer.getData("<...
5
votes
1
answer
4k
views
Gas, gas price, gas cost
I have read in the documentation that the miners set the gas cost. Does this means that gas cost varies from miner to miner? If not, how it is determined?
Moreover, when a contract is referred in geth ...
5
votes
1
answer
507
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
5
answers
9k
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
1
answer
609
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
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 ...
5
votes
1
answer
838
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
1
answer
867
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
2
answers
18k
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 ...
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.
4
votes
1
answer
14k
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
1
answer
3k
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 ...
4
votes
2
answers
1k
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
2
answers
952
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
1
answer
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
1
answer
738
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
1
answer
1k
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 ...
4
votes
1
answer
624
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 ...
4
votes
0
answers
203
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
1
answer
193
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
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(),
...
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 ...
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 ...
3
votes
2
answers
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
2
answers
941
views
How to find out when pending transactions go through? Ideally I'd be alerted
How do I know when transactions are either successfully mined or still sitting in the mempool? I don't want to just overbid on gas to get my transaction to get mined faster / more instantly from the ...
3
votes
2
answers
781
views
modifier vs function which method is more efficient in terms of gas?
contract test {
address public _onwer;
error NotOwner();
modifier OnlyOwner1() {
if(msg.sender != _onwer) {
revert NotOwner();
}
_;
}
function OnlyOwner2() ...
3
votes
1
answer
1k
views
Is there an Ethers.js equivalent of Low, Medium, High gas preferences?
I'm finding polygon main network transfers to be quite slow, taking ~5 minutes on average. If I execute them on polygonscan directly, I can speed them up by setting the gas preference slider to High ...
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, ...