Hot answers tagged

4

When you create a transaction you set two parameters: gas: Maximum amount of gas to be used gasPrice: Price to pay for each gas unit To execute the transaction your account needs to have at least gas * gasPrice ether. Before executing your account is charged with gas * gasPrice. After the transaction has completed its execution unused gas and refunded gas ...


3

You can actually do a double flashloan, but the success will depend on the total amount of gas consumed in the transaction. In fact, you don't need to have two contracts and you can request the two loans from the same contract. Below is a simple example on how this could be done: // SPDX-License-Identifier: MIT pragma solidity ^0.7.3; import {IERC20} from &...


3

Yup, it does cache the numbers, even without the optimizer enabled! When passing 65535 (max uint16) as the parameter x, it costs 1003 gas to run either foo or bar. I ran this test with Solidity v0.8.3 on Remix. contract PowersOfTwo { uint256 internal constant TWO_POW_1 = 2**1; uint256 internal constant TWO_POW_2 = 2**2; uint256 internal constant ...


2

You can include in your contract a key that only your app know, but... the Ethereum net make public the smart contracts code, then I dont know how you can avoid decrypting the communication between the app and the contract. Maybe if you dont verify the contract the code of it stay hidden. Other solution I can think is to create 2 contracts, where the second ...


2

Yes, modulo is cheaper in unchecked arithmetic! Take the following code: pragma solidity ^0.8.0; contract Modulos { function foo(uint256 x, uint256 y) external view returns (uint256 result, uint256 gasUsed) { uint256 startGas = gasleft(); result = x % y; gasUsed = startGas - gasleft(); } function bar(uint256 x, ...


1

Usually it is safe to leave the gas estimation for the wallet itself and not to try to do it yourself. In the case wallets cannot estimate the gas, which sometimes happens for complex transactions, you can do test transactions on testnet and figure out how many gas units the transactions spend and then use that as a hardcoded limit.


1

View and Pure functions are gasless only if they do not get called from the contract internally. The function in the question would be gasless if called externally. Pure functions do not read or modify state, where as View functions read but do not modify state.


1

Possibly someone with deeper knowledge of compilation details will chime in with more precision. Intuitively, one might expect a slight difference to account for the extra steps of jumping into another section of code, packing return arguments, and unpacking received arguments, and them carrying to assign the value to foo_value. The difference could be ...


1

Gas powers the transaction. The transaction consumes a certain amount of gas. Any remaining supplied (sent) gas is returned to the sender so there is no risk in sending extra gas. The transaction fails if the work cannot be completed before all the gas is gone. GasPrice is Ether to spend per unit of gas burned. Think of it like paying $4.50/gal for gas and ...


1

The address 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 belong to a contract. Contracts don't pay fees, users invoking them pay the transactions fees. In this particular case the contract is WETH. It is used to wrap ETH as an ERC20 token. It is used by several exchanges.


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