> For the complete documentation index, see [llms.txt](https://docs-presto.gateway.fm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-presto.gateway.fm/overview/features-for-developers/how-to-use-presto-with-viem.sh.md).

# How To Use Presto with viem.sh

To use Presto with [viem.sh](http://viem.sh/) library using a custom RPC endpoint, follow these steps:

1. Install the [viem.sh](http://viem.sh/) library by running `npm install viem.sh` in your project directory.
2. Create your rollup ([How to Create a Rollup](/overview/main-functionality/how-to-create-a-rollup.md)), open it, and get the RPC URL ([What Is RPC](/overview/features-for-developers/what-is-rpc.md)).<br>

   <figure><img src="/files/cqybA1LuVZsN77ykORt7" alt=""><figcaption></figcaption></figure>
3. Set up a provider to connect to your Presto L2 network using your custom RPC endpoint.
4. Make sure to replace `YOUR_CUSTOM_RPC_ENDPOINT` with the URL of your custom RPC endpoint.

```jsx
const { viem } = require('viem.sh');

const provider = new viem.providers.JsonRpcProvider('YOUR_CUSTOM_RPC_ENDPOINT');

async function getBlockByNumber(blockNumber) {
  try {
    const block = await provider.getBlock(blockNumber);
    console.log(block);
  } catch (error) {
    console.log(error);
  }
}

getBlockByNumber(12345);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs-presto.gateway.fm/overview/features-for-developers/how-to-use-presto-with-viem.sh.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
