How To Use Presto with viem.sh
To use Presto with viem.sh library using a custom RPC endpoint, follow these steps:
Install the viem.sh library by running
npm install viem.sh
in your project directory.Create your rollup (How to Create a Rollup), open it, and get the RPC URL (What Is RPC).
Set up a provider to connect to your Presto L2 network using your custom RPC endpoint.
Make sure to replace
YOUR_CUSTOM_RPC_ENDPOINT
with the URL of your custom RPC endpoint.
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);
Last updated