<!-- Canonical: https://docs.linea.build/api/reference -->

> For the complete Linea documentation index, see [llms.txt](/llms.txt).
> Agents can fetch this page as Markdown at [https://docs.linea.build/api/reference.md](https://docs.linea.build/api/reference.md).

# 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](https://docs.metamask.io/services/reference/linea/json-rpc-methods/).

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](https://docs.metamask.io/services/reference/linea/json-rpc-methods/bundler/).

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](/network/how-to/run-a-node), or [use a node provider](/network/build/tools/node-providers). We recommend running [Linea Besu](/network/how-to/run-a-node/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](/network/build/tools/node-providers#private-rpc-endpoints) such as Infura or Alchemy. Multiple providers offer free tier access.
-   **Use a public endpoint**: [Public endpoints](/network/build/tools/node-providers#public-rpc-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`](https://curl.se/) command in a terminal:

```bash
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](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) or [yarn](https://yarnpkg.com/getting-started/install) as the package manager. Then, in your project folder, initialise your new project:

-   npm
-   yarn

```bash
npm init -y
```

```bash
yarn init -y
```

#### Node Fetch

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

    -   npm
    -   yarn

```bash
npm i node-fetch
```

```bash
yarn add node-fetch
```

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

    index.js

```javascript
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:

```bash
node index.js
```

#### Axios

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

    -   npm
    -   yarn

```bash
npm i axios
```

```bash
yarn add axios
```

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

    index.js

```javascript
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:

```bash
node index.js
```

#### Viem

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

    -   npm
    -   yarn

```bash
npm i viem
```

```bash
yarn add viem
```

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

    index.js

```javascript
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:

```bash
node index.js
```

These examples use the public endpoint which is rate-limited. For production use, connect to a [node provider](/network/build/tools/node-providers) 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.
