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

As @fixanoid stated in his answer you can change the gas limit in the genesis.json. But this isn't an optimal solution in my opinion. You are better off using a specific flag for your miner. Geth has the --targetgaslimit flag that will cause your miner(s) to move step by step towards a given gas limit. Only a certain increase is allowed per block. ...


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

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

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

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 ...


2

What is the meaning of stipend if transactions are always have gas limit set by sender? Not really. When EOA calls contract A, the gas limit is set in the transaction, this is true. However, when contract A calls contract B, contract A may set limit on how much gas the contract B is allowed to spend. This limit may be lower than the remaining gas ...


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

The stipend is 2300, not 23000. A scenario where this stipend is not enough: Changing a state-variable from zero to non-zero.


1

You have to pay some gas for every byte in data field of a transaction. After Istanbul fork new cost are given in EIP 2028 16 gas a non-zero byte (it was 68 gas) 4 gas a zero byte (it didn't change) So if your addresses have a zero byte the transaction will be 12 gas cheaper.


1

Using loops in Solidity is not the best idea to achieve your needs. In your case it would be the best if you force the users to "ask" for the free tokens. Look at my code: pragma solidity >=0.4.22 <0.6.0; contract test3 { constructor(address[] memory _user_addresses) public { usersAddresses = _user_addresses; } struct User { ...


1

3 things to try: Avoid using unstable versions, switch to the last stable Elasa (v1.9.6) You may have to increase the gas a bit when deploying contracts, because of new versions of solidity where gas calculation changes Using a gas price oracle is sometimes needed


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

Ethereum has hard coded limit of 24 Kbytes for the smart contract runtime since https://eips.ethereum.org/EIPS/eip-170. This limit is different from the block gas limit. Note: compilation returns a bytecode which is composed of the constructor and the runtime, only the last part has to be within the 24 Kbytes limit.


1

In short: It's exactly as you suspect, a higher gas limit means your transaction is less likely to be included by miners. The reasoning: miners seek to maximize their profit within each block. Calls to eth_estimateGas can be computationally heavy, so miners typically do not determine the actual gas each tx will consume. Instead they calculate gasPrice * ...


1

This is a non-trivial problem. You cannot use loops. It's not that the gas will get too large to be practical. The contract will fail completely when the loops get too large and that would be catastrophic. No widely accepted standard exists at this time. You might look at this proposal: https://github.com/ethereum/EIPs/issues/1726 and this implementation:...


1

I though I will comment to @lunr's answer but adding as an answer due to it's length. And if that's true, will that transaction take longer to get confirmed than say a regular transfer transaction? (given they're both sent with the same gas price) The answer is it depends. Let A be a regular transaction and B be the one that consumes gas limit. Suppose ...


1

Does a transaction that requires the entire block gas limit to be executed (currently ~8M) take the entire block by itself? Yes. And if that's true, will that transaction take longer to get confirmed than say a regular transfer transaction? (given they're both sent with the same gas price) Probably. That's because including that tx in a block will be ...


1

the value is replaced with available gas right? As a bit of a simplification, yes. IIRC, I believe the amount of gas forwarded to the callee is actually 63/64ths of the remaining gas in the transaction.


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

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

This error normally happens if the compiler detects a potential exception. For example if you have a function with a modifier let's say : function f() onlyOwner {..} modifier onlyOwner { require(msg.sender == owner); _; } calling this function with a different account than the owner will generate the error you've got because we ...


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