Getting Started with Mantle Viem
Overview
mantle-viem is a TypeScript extension for Viem that provides actions for working with Mantle L2 chain.
Features
- Simplifies cross L1 & L2 interactions
- Seamless extension to Viem
- TypeScript ready
- Test suite running against forked Ethereum network
Installation
npm
npm i mantle-viem
Quick Start
1. Set up your Client & Transport
Firstly, set up your Client with a desired Transport & Mantle Chain from mantle-viem.
import { mantle } from '@mantleio/viem/chains'
import { createPublicClient, http } from 'viem'
const client = createPublicClient({
chain: mantle,
transport: http(),
})
2. Extend Client with the mantle-viem
Now that you have a Client set up, you can extend it with Mantle Actions.
import { publicActionsL2 } from '@mantleio/viem'
import { mantle } from '@mantleio/viem/chains'
import { createPublicClient, http } from 'viem'
const client = createPublicClient({
chain: mantle,
transport: http(),
}).extend(publicActionsL2())
3. Consume Mantle Actions
Now that you have an Mantle Client set up, you can now interact with Mantle and consume Actions!
import { publicActionsL2 } from '@mantleio/viem'
import { mantle } from '@mantleio/viem/chains'
import { createPublicClient, http, parseEther } from 'viem'
const client = createPublicClient({
chain: mainnet,
transport: http(),
}).extend(publicActionsL2())
const args = await publicClient.buildProveWithdrawal({/* ... */})