I want to send a transaction in RSK network and I get this message in logs: Not enough gas for transaction execution.
I got the gas limit parameter from my testing environment, using web3.eth.estimateGas
.
The gas fee is calculated using Gas Limit * Gas Price per Unit. So if the gas limit was 20,000 and the price per unit was 200 gwei, the calculation would be 20,000 * 200 = 4,000,000 gwei or 0.004 ETH.
The gas calculation formula is: 21,000 (gas limit) x (50 (base fee) + 15 (Tip)), or 21,000 x (50 + 15). This returns a total gas fee of 1,365,000 gwei or 0.001365 ETH.
In Solidity Gas is a fee which is required to conduct a transaction on the Ethereum blockchain. Gas prices are specified in gwei. Gwei is a denomination of the cryptocurrency Ether.
RSK nodes have a JSON-RPC for eth_estimateGas
,
which is the most reliable way to perform gas estimations.
You can do this from the terminal using curl
:
curl \
-X POST \
-H "Content-Type:application/json" \
--data '{"jsonrpc":"2.0","method":"eth_estimateGas","params":[{"from": "0x560e6c06deb84dfa84dac14ec08ed093bdd1cb2c", "to": "0x560e6c06deb84dfa84dac14ec08ed093bdd1cb2c", "gas": "0x76c0", "gasPrice": "0x3938700", "value": "0x9184e72a", "data": "" }],"id":1}' \
http://localhost:4444
{"jsonrpc":"2.0","id":1,"result":"0x5208"}
Alternatively, using web3.js
:
web3.eth.estimateGas({"to": "0x391ec8a27d29a42c7601651d2f38b1e1895e27a1", "data": "0xe26e496319a16c8ccae126f4aac7e3010123927a4739288cd1ace12feafae9a2"})
23176
While this is the same JSON-RPC found in geth
(Ethereum) and other Ethereum-compatible nodes,
note that the gas calculations in RSK and Ethereum are different.
Thus their implementations differ.
For example, the price of certain VM opcodes are different. Another notable point of difference related to gas estimation, is that Ethereum implements EIP-150, whereas RSK does not. This means that the 1/64 reduction in gas estimation does not apply to RSK. (The detailed implications of this on gas estimation are perhaps beyond the scope of this question.)
This means that you will expect incorrect values when running against ganache-cli
(previously testrpc
),
which is used by default in common developer tools such as Truffle.
To get the correct gas,
using the RSK-specific calculations,
the best way is to use RSK Regtest
when invoking eth_estimateGas
for local development and testing.
In other scenarios you may also use
RSK Testnet and Mainnet.
The following other scenarios are also relevant, but not directly related to your question, but are also good to know:
When invoking smart contract functions
that have the pure
or view
modifiers,
no gas (and therefore gas estimation) is necessary.
When performing certain transactions that have a define invariant gas price,
simply you may use that as a hard-coded constant.
For example the transfer of the native currency (RBTC in this case),
the invariant gas price is 21000
.
This assumes that no data
(sometimes referred to as "message")
was sent with the transaction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With