Skip to main content
JSON-RPC API reference

Use the Linea API

Linea supports the standard Ethereum JSON-RPC API methods, meaning the developer experience is identical to building on Ethereum itself. However, some methods differ to Ethereum, and are covered in this section.

info

The following pages document the JSON-RPC methods most relevant for building on Linea, available on the public RPC endpoint (https://rpc.linea.build); a few infrastructure methods are intentionally omitted. Methods with Linea-specific behavior are documented in detail. Standard Ethereum methods include curl examples you can run directly against the public endpoint, no API key required.

For private endpoints with higher rate limits and WebSocket support, see the MetaMask services documentation.

Account abstraction (ERC-4337)

The full set of bundler methods is also served on rpc.linea.build: eth_sendUserOperation, eth_estimateUserOperationGas, eth_supportedEntryPoints, eth_getUserOperationByHash, eth_getUserOperationReceipt, plus pimlico_getUserOperationGasPrice, pimlico_getUserOperationStatus, and pimlico_simulateAssetChanges. For parameter and response details, see MetaMask Services bundler methods.

You must connect to an RPC endpoint when making calls to the Linea blockchain. Use one or more of the following options:

Make calls​

The following examples call the Linea API methods using the public endpoint https://rpc.linea.build. You can substitute the endpoint with whichever endpoint you prefer.

curl​

Run the curl command in a terminal:

curl https://rpc.linea.build \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": 1}'

Node (JavaScript)​

The following examples use various JavaScript libraries to make calls to the Linea blockchain.

Prerequisites​

Install npm or yarn as the package manager. Then, in your project folder, initialise your new project:

npm init -y

Node Fetch​

  1. In your project folder, install the node-fetch package:

    npm i node-fetch
  2. Create your JavaScript file and copy the following code:

    index.js
    const fetch = require("node-fetch");

    fetch("https://rpc.linea.build", {
    method: "POST",
    headers: {
    "Content-Type": "application/json",
    },
    body: JSON.stringify({
    jsonrpc: "2.0",
    method: "eth_blockNumber",
    params: [],
    id: 1,
    }),
    })
    .then((response) => response.json())
    .then((data) => {
    console.log(data)
    })
    .catch((error) => {
    console.error(error)
    })
  3. Run the code using the following command:

    node index.js

Axios​

  1. In your project folder, install the axios package:

    npm i axios
  2. Create your JavaScript file and copy the following code:

    index.js
    const axios = require("axios")

    axios
    .post("https://rpc.linea.build", {
    jsonrpc: "2.0",
    method: "eth_blockNumber",
    params: [],
    id: 1,
    })
    .then((response) => {
    console.log(response.data)
    })
    .catch((error) => {
    console.error(error)
    })
  3. Run the code using the following command:

    node index.js

Viem​

  1. In your project folder, install the viem package:

    npm i viem
  2. Create your JavaScript file and copy the following code:

    index.js
    const { createClient, http } = require('viem');

    const client = createClient({
    transport: http('https://rpc.linea.build')
    });

    client.request({
    method: 'eth_blockNumber',
    params: []
    })
    .then((blockNumber) => {
    console.log(parseInt(blockNumber, 16)); // Convert hex to decimal
    })
    .catch((error) => {
    console.error(error);
    });
  3. Run the code using the following command:

    node index.js

These examples use the public endpoint which is rate-limited. For production use, connect to a node provider for higher rate limits and WebSocket support.

note

Response values shown in these reference pages are real examples captured from rpc.linea.build at a point in time. Values for chain-state methods (block numbers, balances, gas prices, fee history) will differ when you run the same calls. This is expected behavior, not an error.

Was this page helpful?