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.
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.
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:
- Run your own node: Either run your own node by setting it up yourself, or use a node provider. We recommend running Linea Besu if you want to run a node yourself and interact with the blockchain.
- Connect to a private RPC endpoint: Connect to a blockchain infrastructure provider such as Infura or Alchemy. Multiple providers offer free tier access.
- Use a public endpoint: Public endpoints are free to use but are rate limited and not suitable for production environments.
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
- yarn
npm init -y
yarn init -y
Node Fetch​
-
In your project folder, install the
node-fetchpackage:- npm
- yarn
npm i node-fetchyarn add node-fetch -
Create your JavaScript file and copy the following code:
index.jsconst 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)}) -
Run the code using the following command:
node index.js
Axios​
-
In your project folder, install the
axiospackage:- npm
- yarn
npm i axiosyarn add axios -
Create your JavaScript file and copy the following code:
index.jsconst 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)}) -
Run the code using the following command:
node index.js
Viem​
-
In your project folder, install the
viempackage:- npm
- yarn
npm i viemyarn add viem -
Create your JavaScript file and copy the following code:
index.jsconst { 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);}); -
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.
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.