Hot answers tagged

2

Changing a value from 0 to a non-0 value will always cost 20,000 gas. There is no way to pre-initialise a variable with a value of 0, to make it not cost 20,000 gas when changing the value. An alternative approach to get around this is to initialise the variable as 1, and use a getter to get the value of the variable, e.g. contract Demo { uint256 private ...


1

Aave employs the concept of an "index" - it's not that the protocol writes to the storage of all user accounts, but that the index gets updated and this is paid for by users. Later on, whoever queries the "balanceOf" function (which is free because is constant) will use the latest index to calculate the given user's balance. This is ...


1

Gas is the measure of computation required to execute your transaction, depending on what functions your contract uses the gas used changes. This is analogous to the transaction bytes size in Bitcoin transactions. The fees you set are how much gwei you are willing to pay for each gas unit, that's why it's PerGas. It's analogous to the satoshi/vbytes in ...


1

After a bit of searching I figured out that the receipt should be the mined object.. I also wasn't sending any value with the transaction. const addr1Bal = await provider.getBalance(addr1.address) const txValue = ethers.utils.parseEther('0.03').mul(BigNumber.from('4')) const tx = await contract.connect(addr1).mint(4, { value: txValue }) ...


1

Isn't the speculation over cryptos actually bad for the blockchain itself? Any native blockchain medium of exchange of unit of accounting must be disconnected from a political currency, like USD or Yuan, as otherwise it would very hard to achieve a global consensus mechanism, where global being working across geopolitical adversaries. the more a currency ...


1

It uses web3.eth.estimateGas (https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html), which basically runs the transaction locally and returns the amount of gas used. It's pretty good most of the times but it can definitely get it wrong. Not sure in which specific cases though.


1

require(msg.value <= 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) // or type(uint256).max/2 would work. Its unlikely someone try to send more than 5.7*10^58 ETH to your contract though x)


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