12

pure and view functions only are "free" when you call them externally, as in you call that function by itself and run the calculation on your node. So if you had a function that returned "1+1", yes you can call that individual view function as many times as you want for free, even without creating a transaction. However, if you use a view or pure function ...


11

Just to add to @Shawn's good answer. Yes, you can abuse them. But as the pure and view computations are performed only on your own node you would only hurt your own node. You would not hurt the Ethereum network in any way. If you call the function(s) enough, you might even crash your node but it still wouldn't hurt the network in any way.


4

This is because recoveredAddresses isn't marked as memory, so by default, it's in storage. Every time you push to it, you're growing the length, even across transaction calls. That also means that the function contains has to iterate over a larger and larger array of addressArray every time it's executing, growing the gas cost over time. The solution is to ...


3

newer solidity versions have out of gas issues deploying our sample contracts. Specify the solidity version in the truffle-config.js compilers: { solc: { version: "0.5.0", }, } from @cruz: @adam.chasen I believe in one of the more recent versions of truffle, we bumped the solidity version to 0.5.8 (which defaults the evmVersion to ...


3

Yes, you can let the charge be a function of the gas of the transaction. You would do something like this: uint256 charge = gasleft() / 10; This is sensitive and you should know that gasleft() returns the amount of gas available at that point in the execution. Therefore, if you call gasleft() at the beginning of a function, the number will be higher than ...


3

TL;DR: Yes you can use the same value. Here is why: Ganache Ganache is a local test Blockchain. -l or --gasLimit is the block gas limit (total amount in gas unit that can fit in a block). Let's say for example your block gasLimit is 1000000, you would be able to fit only 10 transactions of 100000 gas units each. -g or --gasPrice is the default price per ...


3

How and why is this possible? The user set a value of 0.1 ETH (100,000,000 Gwei) as the gas price. It's possible to set the gas price to anything you want. Why Ethereum does not provide any protection mechanism for paying very high transaction fees and why there is no limit for that? It's likely that certain wallets do prevent such mistakes from being ...


2

Which version of Truffle do you use? In my case, downgrading Truffle from v5.0.27 to v5.0.5 fixed the issue. npm i -g truffle@v5.0.5


2

Thanks to Ismael's solution: const ganache = require('ganache-cli'); const Web3 = require('web3'); const options = { gasLimit: 8000000 }; const provider = ganache.provider(options); // quote from doc "Both .provider() and .server() take a single object // which allows you to specify behavior of ganache-cli" // https://github.com/trufflesuite/ganache-cli#...


2

The block limit can increase or decrease, depending on what the miners choose. The miners have a limited ability to adjust this value in order to help (or hurt) the network. This value has been changed at times of high network stress, such as when there were too many transactions to process and also when there was an ongoing DDOS attack.


2

In a good interface, a consumer doesn't have to guess how much gas is required. Sending Ether from one person to another always costs the exact same amount of gas. Sending an ERC20 token (provided it follows the standard) also costs a fixed number. Each operation (line of a smart contract) costs a known number of gas. It is quite easy for people who run ...


2

View will not cost gas only if called from outside the network, that is if a function in a contract is view and is called from another contract it will cost gas. The reason it will not cost gas if called from outside the network is that the function can be resolved in the local node that you are using to connect to the network without submitting a ...


2

Look at the tx data for those two transactions. The one from Remix looks like a full contract, but the one from javascript doesn't look like it's deploying a contract.


2

The Ethereum network allows you to set two variables when sending a transaction: gasLimit and gasPrice. The transaction fee, which is 2,100 Ether in this case, is equal to gasLimit * gasPrice. gasLimit is the amount of gas to send in order to complete a transaction. For example, if your transaction to a smart contract needs 100,000 gas, you will send a ...


2

If the transaction executes your on-chain function, which you obviously have 100% confidence of for not spending an excessive amount of gas, then the only drawback is that the gas limit that you set may exceed the block gas limit, in which case your transaction will not be executed. If the transaction executes someone else's on-chain function, whose gas ...


2

The gas parameter represents the price which you are willing to pay for each gas unit (it's like a public auction - the higher your price is, the faster your transaction will be executed by one of the miners on the network). The gasLimit parameter represents the maximum number of gas units that you are willing to allow for your transaction (it is ...


1

No there is no way to know it reliably. Even sending the same transaction multiple times may result in different gas amounts. (See for example here Why gas-used are different for same transfer() tx? ). Also other factors make it difficult/impossible to estimate it correctly, such as loops (can we know in advance how many times we will loop?). The amount can ...


1

It depends on how you use it. If you are calling it from your backend system through a node there is no gas limit as the call never goes inside a block. The call is simply made to the node and the node returns the required information - the blockchain network is not consulted at all. So the only restrictions are your node's throughput and computation power. ...


1

A transfer for a simple ERC20 token used 51,574 gas. MetaMask set the gas limit at 54,861 gas. Though the required gas will depend on how the ERC20 contract was implemented. You can always have a look on Etherscan for the transaction fees for previous transfers of the ERC20 token. Gas prices are 5 gwei for standard speed according to https://ethgasstation....


1

Your use of for(i=0; i<n; i++_) implies O(n) complexity, meaning you can optimize the process but it will still increase in cost proportional to n. Optimization only affects slope steepness. The real problem is there is a slope at all. Unbounded for loops are an anti-pattern because they are not scale-invariant. Have a look at this: https://blog.b9lab....


1

Note that the miner can only slight change the gas limit. A block header is invalid if the gas limit is more than 1/1024 plus or minus the parents gas limit, meaning if block 10 has a gas limit of 1,000,000, block 11's gas limit must be between 1000000-floor(1000000/1024) and 1000000+floor(1000000/1024). So contract writers should of course should just be ...


1

There is a way to increase the gasLimit. You will use a flag when starting ganache-cli to do so. Per the README, use -l or --gasLimit (the block gas limit (defaults to 0x6691b7)). However, if you are having to do this, you will not be able to perform this on the main network. A lot of Ethereum development is design decisions on what goes on and off chain. ...


1

Here are few hints: replace public modifier with external in your contract. Here is why Not used gas (limit) is returned back to you so you may put as much as possible. On time of writing it's around 6-7M. You may put low gas price (e.g. 1 GWEI). However, your transaction will take some time. You may estimate it here: https://ethgasstation.info/


1

In your case, both elementIndex and returnAllElements functions will cost no gas as both the functions are reading state variables from the blockchain and give an intended result. You can optimize the above functions to reduce a time taken by them. Refer the following question to understand View/Pure Gas usage - Cost gas if called internally by another ...


1

This is probably not the case here since you're using Infura, but in case others are seeing this error when submitting transactions to a light node: If the light node has no peers to ask about chain state, it may return this error since it can't determine the balance of the sender, and thus considers it insufficient.


1

Key was wrong - I corrected the key and now it runs.


1

If you change the struct you have to pay gas. In my opinion this is a better way to manage structs. You just push the new struct in an array and leave the old ones that you dont need anymore. Game[] public games; struct Game{ string gameID; string[2] teams; string winningTeam; string losingTeam; mapping(string => uint) totalWeiBet; ...


1

Disclaimer: I'm assuming an understanding of what gas is. The gas limit is the maximum amount of gas that could be spent during an Ethereum transaction. This number is not fixed--early on in the Ethereum days, the gas limit was much lower than it is today. There is a calculation that Ethereum nodes do to adjust the gas limit after each transaction, based ...


1

Without details it's not possible to know that this is "the" problem, but it's a suspect. The Byzantium fork is a protocol change. Consequently, there is incompatibility between compiled code beyond a certain version, and blockchain nodes running an older protocol. Your private network may be composed of nodes running an older protocol than your compiled ...


1

Answer(I found out the answer by myself): The gas parameter in truffle.js is the maximum amount you are willing to pay for deploys. It is not the chain's block gas limit! So doesn't matter how big that is, if the block gas limit is smaller than the gas you attach to a transaction, you will always get the same error "Exceeds block gas limit". Which also ...


Only top voted, non community-wiki answers of a minimum length are eligible