Getting Started with OP Stack
Viem provides first-class support for chains implemented on the OP Stack.
The OP Stack is a set of modular open-source software that enable developers to build fast, secure, and scalable Layer 2 Ethereum protocols & applications. Read more.
Quick Start
1. Set up your Client & Transport
Firstly, set up your Client with a desired Transport & OP Stack Chain.
import { createPublicClient, http } from 'viem'
import { base } from 'viem/chains'
 
const client = createPublicClient({ 
  chain: base, 
  transport: http(), 
}) 2. Extend Client with the OP Stack
Now that you have a Client set up, you can extend it with OP Stack Actions! Read more.
import { createPublicClient, http } from 'viem'
import { base } from 'viem/chains'
import { publicActionsL2 } from 'viem/op-stack'
 
const client = createPublicClient({
  chain: base,
  transport: http(),
}).extend(publicActionsL2()) 3. Consume OP Stack Actions
Now that you have an OP Stack Client set up, you can now interact with the OP Stack and consume Actions!
import { createPublicClient, http, parseEther } from 'viem'
import { mainnet } from 'viem/chains'
 
const client = createPublicClient({
  chain: mainnet,
  transport: http(),
}).extend(publicActionsL2()) 
 
const l1Gas = await client.estimateL1Gas({ 
  account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', 
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', 
  value: parseEther('1') 
}) 
