linea_estimateGas - Linea

This method returns a Linea-specific gas estimate for a transaction, including the recommended gas limit, the base fee per gas, and the priority fee per gas. It takes the same inputs as eth_estimateGas but accounts for Linea's Layer 1 data-submission cost, so it produces a more accurate price for Linea transactions and helps avoid rejection for exceeding module limits.

Parameters

ParameterTypeRequiredDescription
transactionobjectYesTransaction call object

Transaction Object

FieldTypeRequiredDescription
fromstringNo20-byte sender address
tostringYes20-byte recipient or contract address
gasstringNoGas limit for the transaction (hex)
gasPricestringNoGas price in wei (hex)
valuestringNoValue to send in wei (hex)
datastringNoEncoded function call data

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "linea_estimateGas",
    "params": [{"from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "to": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "value": "0x16345785d8a0000"}],
    "id": "getblock.io"
}'

example.js

javascriptconst axios = require('axios');

const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
    jsonrpc: '2.0',
    method: 'linea_estimateGas',
    params: [{"from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "to": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "value": "0x16345785d8a0000"}],
    id: 'getblock.io'
}, {
    headers: { 'Content-Type': 'application/json' }
});

console.log(response.data.result);

example.py

pythonimport requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'linea_estimateGas',
        'params': [{"from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "to": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "value": "0x16345785d8a0000"}],
        'id': 'getblock.io'
    }
)

print(response.json())

example.rs

rustuse reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();

    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "linea_estimateGas",
            "params": [{"from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "to": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "value": "0x16345785d8a0000"}],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;

    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "baseFeePerGas": "0x7",
        "gasLimit": "0xcf08",
        "priorityFeePerGas": "0x43a82a4"
    }
}

Response Parameters

ParameterTypeDescription
jsonrpcstringJSON-RPC protocol version ("2.0")
idstringRequest identifier matching the request
resultobjectObject with the recommended gas limit and Linea fee components

Result Object

FieldTypeDescription
baseFeePerGasstringBase fee per gas in wei, hex-encoded
gasLimitstringRecommended gas limit for the transaction, hex-encoded
priorityFeePerGasstringPriority fee per gas in wei, including the L1 submission cost

Use Cases

  • Accurate Pricing: Price a Linea transaction with L1 costs included
  • Rejection Avoidance: Set a gas price high enough for sequencer inclusion
  • Wallet Fee UX: Show a Linea-accurate fee before signing
  • Batch Budgeting: Size operations against Linea's module limits

Error Handling

Error CodeMessageDescription
-32602Invalid paramsThe transaction object is missing required fields or malformed
-32000Execution errorThe transaction cannot be priced against the current state
3Execution revertedThe transaction would revert on execution
-32603Internal errorThe node failed to produce an estimate

Web3 Integration

ethers-example.js

javascriptconst { ethers } = require('ethers');

const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

const tx = { from: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', to: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', value: '0x16345785d8a0000' };
const estimate = await provider.send('linea_estimateGas', [tx]);
console.log(estimate);

viem-example.js

javascriptimport { createPublicClient, http } from 'viem';
import { linea } from 'viem/chains';

const client = createPublicClient({ chain: linea, transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/') });

const estimate = await client.request({
    method: 'linea_estimateGas',
    params: [{ from: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', to: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', value: '0x16345785d8a0000' }]
});
console.log(estimate);