Hot answers tagged

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


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

You are confusing a few concepts. Inheritance and composition Factory (I suspect this is a misuse of the factory idea. More to follow). Eternal storage. The structure seems like it might have been inspired by a well-known pattern. Let us turn our attention to the top of the graph, the ERC20 contract, the escrow contract and the dotted connectors, "...


2

Short answer: it really depends on the token, and typically varies from 25'000 to 150'000, with very rare cases going over 500'000 gas. Recommendation: set it 200'000 if you don't have access to an estimate, it will work 99% of the time. It is a "limit" anyway, you will get back any unspent gas immediately. If your wallet proposes an estimate, add roughly ...


1

Yes, it does. To the EVM, setting a bool to false is equivalent to setting a uint to 0 in that it clears a storage slot. You can try it out with the code below. In this contract, the following transaction costs are: setBool() = 41705 setUint() = 41474 unsetBool() = 13386 unsetUint() = 13204 pragma solidity ^0.5.10; contract RefundTest { bool ...


1

Depending on what you are trying to achieve exactly, there might be another method, using extcodecopy to copy a contract's code. This method would for example allow you to deploy one or several "template" smart contracts on their own, and then build and deploy a separate Deployer contract, which copies code from a template and uses it to deploy a copy. Here'...


1

This "warning" relates to the 'require' conditions that may not be 'true'. It can be safely ignored. Experiment with 'require' in a simple setting to see what I mean. Hopefully the Remix team will find a way to make the warning more useful, with fewer false positives. Hope it helps. P.s. You can silence the high/infinite gas warning in Remix.


1

The one that has to send the transaction have to pay the transaction gas. I dont think contract can pay transaction gas but they can relay the gas they have been assigned to other contracts. You can check out Meta transactions Using this method we are able to interact with the blockchain from accounts that don’t hold any Ether


1

EDIT if the contract is not already deployed. Yeah you can totally do that. Just keep that in mind it will cost more gas function bulkAddress(uint256[] _amount, address[] _acct) public { for(uint i = 0; i< _acct.length; i++){ ...your logic } } and can call this function using web3 contractInstance.methods.bulkAddress(...


1

Yes, the gas will be paid for by you, the sender of the transaction. The gas will not be taken from the contract.


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


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