zks_estimateGasL1ToL2 - zkSync
Example code for the zks_estimateGasL1ToL2 JSON-RPC method. Сomplete guide on how to use zks_estimateGasL1ToL2 JSON-RPC in GetBlock.io Web3 documentation.
Estimates the gas required for an L1 to L2 transaction. Use this when preparing L1 contracts that send messages or assets into zkSync Era.
Parameters
callRequest
object
Yes
Transaction-shaped object with from, to, data, and optional fields
Request Example
curl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "zks_estimateGasL1ToL2",
"params": [
{
"from": "0x1111111111111111111111111111111111111111",
"to": "0x2222222222222222222222222222222222222222",
"data": "0xffffffff"
}
],
"id": "getblock.io"
}'import axios from 'axios';
const data = JSON.stringify({
"jsonrpc": "2.0",
"method": "zks_estimateGasL1ToL2",
"params": [
{
"from": "0x1111111111111111111111111111111111111111",
"to": "0x2222222222222222222222222222222222222222",
"data": "0xffffffff"
}
],
"id": "getblock.io"
});
const config = {
method: 'post',
url: 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
headers: {
'Content-Type': 'application/json'
},
data: data
};
axios(config)
.then(response => console.log(JSON.stringify(response.data, null, 2)))
.catch(error => console.log(error));Response Example
Response Parameters
result
string
Estimated gas amount in hexadecimal (32 bytes)
Use Cases
Bridging and L1→L2 message senders
Setting correct gas budgets in L1 deposit contracts
Bridge UX showing accurate cost estimates
Error Handling
403
Forbidden
Missing or invalid <ACCESS-TOKEN>
-32602
Invalid params
Request parameters are missing or malformed
429
Too Many Requests
Rate limit exceeded for your plan
SDK Integration
Last updated
Was this helpful?