Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [gas]

Gas is a 'sub-currency' which enables the EVM and Ethereum's decentralised computer to run -- with each operation, an amount of gas (proportional to the computational effort required to perform the operation) is consumed.

1
vote
1answer
10 views

Gas cost difference between uint[] and mapping(uint => uint)

When mapping for example a large integer to some integer, uint[] index; index.length = 1000000; index[600001] = 4; is it cheaper to use mapping(uint => uint) index; index[600001] = 4; ? one ...
1
vote
1answer
20 views

Smart Contracts without ETH Transactions

Maybe I'm wrong, but I understand that Smart Contract Transactions must always contain a "VALUE" field, that's to say, the amount of Ether Alice will transfer to Bob in case certain condition ...
0
votes
1answer
37 views

Clique PoA Private Blockchain: Need Suggestion for Block Gas Target and Block Gas Limit

I'm following this article to create my own PoA private blockchain. Now I'm stucked at this section after number 13: I've checked the Puppeth source code and Geth CLI docs, but I'm still not quite ...
1
vote
0answers
12 views

Smart contract design for gas refund

I'm designing a proxy smartcontract that will be filled by users so that anyone has an incentive to can perform a transaction useful to the user. I won't go into the detail of "usefulness" here. My ...
2
votes
2answers
22 views

Does the require function need more gas when called with a message?

If I add a message to require as a second parameter, will it increase gas consumption?
1
vote
0answers
12 views

Impact of POS and Shrading on tx costs?

How transaction fees will be affected after implementation of Casper protocol?
0
votes
1answer
14 views

Deploying contract via Remix costs less gas than deploying via javascript

When I launch my contract via remix, it launches with no issues. When I try to launch the contract via my javascript web3, using the same gas price and gas limit, it fails b/c it ran out of gas. This ...
0
votes
0answers
24 views

Calculating gas needed to transfer tokens

Suppose I have a wallet with erc20 token balance in it and with zero ethereum balance. I need to send tokens to another wallet. But before I need to send some eth to this wallet to pay gas for tokens'...
2
votes
1answer
20 views

Keeping track of Gas costs

I have a smart contract that allows for several different user to batch tx's for their ERC20 Token distribution. In this SC the user send some ether to the smart contract, and some tokens. I want ...
0
votes
1answer
25 views

Uncaught error: VM Exception while processing transaction:out of gas

pragma solidity^0.4.18; contract project3{ address owner; struct Users{ string companyName; string role; string country; string city; uint phoneNo; string physicalAddress;} constructor (uint ...
2
votes
1answer
15 views

How to determine the gas price mathematically

The mathematical equation to define the gas price is gasprice = 1 gwei / gasused. The mathematical equation to define the tax to be paid for each transaction is tax = gasprice x gasused. Are these ...
0
votes
0answers
24 views

How to get the estimate Gas before sending transaction?

I got "undefined",so I wanna know how to get the estimate Gas before send transaction.Thanks for helping me.
2
votes
1answer
30 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 ...
0
votes
1answer
15 views

Gas cost for keep the contract

In Ethereum yellowpaper the gas cost to create a contract is equal 32000. But what is the cost to validate and keep the contract operating until it is executed? Edit: Imagine the following situation:...
1
vote
1answer
33 views

Why is delete on arrays implemented in an energy and gas wasting way?

If I delete the whole array (static/dynamic), then all elements of an array are set to default value. So, it means that if an array has a million elements, then I have to pay gas for setting up of ...
2
votes
0answers
40 views

Why is putting data to storage more expensive during the deployment of contract than storing the same data by a method?

I am working with truffle and solidity (v0.4.23) and found out that when I pass in an argument of constructor some bigger amount of data (16kB) that are saved to storage of a smart contract, it is ...
1
vote
1answer
17 views

Why use different gas?

I have this contract with this functions, why each use different gas amount? pragma solidity 0.4.24; contract Foo { //transaction cost: 21471 gas //execution cost: 199 gas //total cost: 21670 ...
1
vote
1answer
22 views

Why does it cost 21000 gas to send a transaction [duplicate]

What is the forumla used to calculate how much gas needs to be used? are the values just determined arbitrarily or was there some kind of benchmarking?
0
votes
2answers
76 views

How much does it cost to store each IPFS hash in Ethereum blockchain

I've looked in some of the resource on calculating the Gas costs like this spreadsheet I found on this thread. But the spreadsheet only have computations gas costs but not storing of hashing. I'm a ...
1
vote
1answer
18 views

How much money was spent on gas for CryptoKitties transactions?

Just the main NFT contract for CryptoKitties, not the auction sale or other helper contracts. Bonus points if you can also include billable transactions that started from another contract and then ...
1
vote
1answer
38 views

Error Ganache: Run out of gas - Works in Remix/Not from dApp

I am working on an application that stores and retrieves personal data on/from the ethereum blockchain. Just working on this to improve my Solidity and SC expertise and get comfortable with the ...
2
votes
1answer
41 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, ...
1
vote
1answer
24 views

Gas limit per block

Gas limit per block is a dynamic value. This value is increasing every year. Is it theoretically possible that such a value can somehow decrease?
1
vote
2answers
32 views

Estimate Gas Price (not Gas) using Web3

Using Web3, we are able to estimate the amount of gas needed for a transaction let estimatedGas = web3.eth.estimateGas({ to: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", data: "...
0
votes
0answers
24 views

Achieving ZERO fee ethereum transactions like EOS

How would Ethereum take on the approach of how EOS have ZERO fees when making a transaction? EOS has the concept of resources, but is there anything like this in the works of "shared resources" for ...
0
votes
2answers
24 views

How to solve insufficient funds (Ropsten)?

I have tried adjusting the Gas Limit and GWEI and I get this error. I am using infura and Ropsten. Has anyone any ideas about this? Code - var rawTransaction = {"from":myAddress, "...
0
votes
1answer
18 views

Is there any gas cost when executing `msg.sender.transfer(0)`?

I have a function which looks more or less like this: function exchange(uint256 amount, bool specialCase) external returns (uint256) { let retVal; if (specialCase) { register(amount); ...
0
votes
3answers
36 views

Gas cost call vs send for pure/view functions

I'm aware of the fact that pure/view functions cost no gas with a simple "call". But what happens if i have a function that changes the contract state based on the pure/view function result. Do i have ...
2
votes
0answers
30 views

Difference between execution costs on remix an Ganache?

I created a contract on remix and then deployed it. when I call any function there is an execution cost in gas. I also deployed the same contract on Ganache for testing. I find the execution cost in ...
0
votes
1answer
25 views

Gas cost in a struct

If i change a existing uint variable in a struct compared to normal ones does it consumes the same amount of gas(cost)? Im trying to optimize my contracts cost
0
votes
0answers
28 views

external contract call not working on private chain

I want to call a contract from another contract on my private chain: contract InfoFeed { function info() public payable returns (uint ret) { return 42; } } contract Consumer { InfoFeed feed; ...
1
vote
1answer
15 views

How do I see how much gas a .call() transaction used in remix IDE connected to ganache-cli?

I've got remix connected to ganache-cli and I'm running some read-only transactions. I can't seem to figure out how to see how much gas those transactions used up? Any help would be great thanks!
1
vote
1answer
30 views

Theoretical question: running a huge function with many iterations

I am still pretty new to Ethereum and smart contract but for a couple of last weeks I have been developing a smart contract for a gambling website project (studying purposes). In the smart contract I ...
2
votes
1answer
14 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, ...
6
votes
3answers
165 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 ...
0
votes
1answer
26 views

Memory consumption confusing case

I know that generally it cost 5,000 gas to initialize memory variable. But simple smartcontract shows me that I misunderstand something. pragma solidity ^0.4.24; contract MemConsumption { ...
0
votes
0answers
28 views

Who fixes the gasPrice in a network? [duplicate]

why we cannot send a transaction with a gassPrice = 0 ?
0
votes
0answers
15 views

Change the value of intrinsic gas?

Does anyone know a way how to change the value of the intrinsic gas setting? I've read something about how to change it with truffle, but is there a way with our genesis.json file?
1
vote
2answers
56 views

Explanation of Geth's Command Line option: targetgaslimit?

I have been trying to figure out what the targetgaslimit parameter does exactly for Geth, in the context of Private Blockchains. I have seen the following explanation but it never helped me: "Target ...
0
votes
1answer
45 views

Smart contract's function work on testnet but don't work on private network

I have been created a smart contract (ERC20 implantation). The contract run great om testrpc, ropsten and rinkeby but i want to use it in a private network. When the contract deployed in the private ...
1
vote
0answers
16 views

Gas cost of adding an item to a class-level (storage) array

I would like to make sure that the gas cost of adding an item to a (storage) array is constant, i.e., not dependent on the length of the array. To my understanding, the relevant EVM operation is ...
0
votes
1answer
40 views

Catching errors with gas issues

I am working on the frontend where I use try / catch to find errors and give appropriate messages to users. My smart contract has a payable function and I was at the point of catching errors regarding ...
1
vote
1answer
24 views

Why aren't costs “advertised” or at least knowable so funds aren't lost?

I'm admittedly new to all of this, but as I learn about the transaction model, it seems to be a confusing business model at the very least. I can understand that the price of gas fluctuates or can be ...
0
votes
2answers
51 views

Gas for view functions

I read in many places that view functions do not cost gas however that's not true because they cost gas for blockchain operations even if those do not change the state. Correct me if I am wrong For ...
0
votes
1answer
21 views

Minimum Gas limit and how can it be reduced?

Why does this minimum exist and what can we do to to reduce it further. This line of thought was spurred by this tweet from Vitalik: "And there are layer 2's without data availability tradeoffs or ...
2
votes
1answer
32 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 ...
2
votes
1answer
49 views

Transfer function gas limit, why 2,300?

I read in the literature that the limit for a Solidity transfer function is 2,300 gas units, because it prevents possible threats like reentrancy, etc. However, I cannot understand why exactly 2,300 ...
1
vote
0answers
19 views

Vyper OPCODES gas estimate at compile time

I am trying to dissect Vyper at lower levels to understand how the gas estimates are generated. I tried following the yellow paper and I searched every single line of the compiler but I can't get it ...
2
votes
2answers
1k views

If view or pure function doesn't cost any gas, would they be abused/free ride?

So if I understand this correctly, view function only read data from ethereum and doesn't mutate any state and pure function doesn't even read data and they are intended for cases like return 1+1; If ...
0
votes
1answer
23 views

Why is gasestimate coming as “infinite” when I'm trying to return a dynamic array in solidity?

I understand, that as the list grows it is going to cost infinite gas. I'm making a temp array in memory of size of our dynamic array at present size and then returning that array. But does that make ...