- tags: Ethereum Layer 2
Background
You may meet the below error when you’re trying to transfer all your ETH from one address to another address:
invalid transaction: insufficient funds for l1fee + gas * price + value
The reason is that the Layer 1 fee are included in Scroll’s gas fee system, but the wallet only exclude the Layer 2 gas fee to do so when you transfer all your ETH. 1
How the L1 Fee be Caculated?
-
Some state is stored in the state store slots2, which including:
l1BaseFee
precision
overhead
scalar
-
You got some RLP3 encoded raw data when you send tx to Scroll, which need to be stored to the Layer 1 network as a
calldata
, which requires fee charge4. let’s name it:raw
-
Finally we put all these together5
// EIP-1559 // 16 * non-zero calldata bytes + 4 * zero calldata bytes l1GasUsed = calcCalldataFee(calldata) + overhead l1Gas = round((l1GasUsed * l1GasPrice * scalar) / precision)
How to Retrieve State Slots?
L1BaseFeeSlot
POST https://alpha-rpc.scroll.io/l2
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 40,
"method": "eth_getStorageAt",
"params": [ "0x5300000000000000000000000000000000000002", "0x1"]
}
OverheadSlot
POST https://alpha-rpc.scroll.io/l2
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 40,
"method": "eth_getStorageAt",
"params": [ "0x5300000000000000000000000000000000000002", "0x2"]
}
ScalarSlot
POST https://alpha-rpc.scroll.io/l2
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 40,
"method": "eth_getStorageAt",
"params": [ "0x5300000000000000000000000000000000000002", "0x3"]
}
In a Batch
POST https://alpha-rpc.scroll.io/l2
Content-Type: application/json
[
{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_getStorageAt",
"params": [ "0x5300000000000000000000000000000000000002", "0x1"]
},
{
"jsonrpc": "2.0",
"id": 2,
"method": "eth_getStorageAt",
"params": [ "0x5300000000000000000000000000000000000002", "0x2"]
},
{
"jsonrpc": "2.0",
"id": 3,
"method": "eth_getStorageAt",
"params": [ "0x5300000000000000000000000000000000000002", "0x3"]
}
]