buildProveWithdrawal
Builds the transaction that proves a withdrawal was initiated on an L2. Used in the Withdrawal flow.
Usage
ts
import { account, publicClientL2, walletClientL1 } from './config'
const receipt = await getTransactionReceipt(publicClientL2, {
hash: '0xbbdd0957a82a057a76b5f093de251635ac4ddc6e2d0c4aa7fbf82d73e4e11039',
})
const [withdrawal] = getWithdrawals(receipt)
const output = await walletClientL1.getL2Output({
l2BlockNumber: receipt.blockNumber,
targetChain: publicClientL2.chain,
})
const args = await publicClientL2.buildProveWithdrawal({
account,
output,
withdrawal,
})
const hash = await walletClientL1.proveWithdrawal(args)
import { account, publicClientL2, walletClientL1 } from './config'
const receipt = await getTransactionReceipt(publicClientL2, {
hash: '0xbbdd0957a82a057a76b5f093de251635ac4ddc6e2d0c4aa7fbf82d73e4e11039',
})
const [withdrawal] = getWithdrawals(receipt)
const output = await walletClientL1.getL2Output({
l2BlockNumber: receipt.blockNumber,
targetChain: publicClientL2.chain,
})
const args = await publicClientL2.buildProveWithdrawal({
account,
output,
withdrawal,
})
const hash = await walletClientL1.proveWithdrawal(args)
ts
import { createPublicClient, createWalletClient, custom, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet, base } from 'viem/chains'
import { publicActionsL2, walletActionsL1 } from 'viem/op-stack'
export const walletClientL1 = createWalletClient({
chain: mainnet,
transport: custom(window.ethereum)
}).extend(walletActionsL1())
export const publicClientL2 = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
// JSON-RPC Account
export const [account] = await walletClientL1.getAddresses()
// Local Account
export const account = privateKeyToAccount(...)
import { createPublicClient, createWalletClient, custom, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet, base } from 'viem/chains'
import { publicActionsL2, walletActionsL1 } from 'viem/op-stack'
export const walletClientL1 = createWalletClient({
chain: mainnet,
transport: custom(window.ethereum)
}).extend(walletActionsL1())
export const publicClientL2 = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
// JSON-RPC Account
export const [account] = await walletClientL1.getAddresses()
// Local Account
export const account = privateKeyToAccount(...)
Account Hoisting
If you do not wish to pass an account
to every buildProveWithdrawal
, you can also hoist the Account on the Wallet Client (see config.ts
).
ts
import { publicClientL2, walletClientL1 } from './config'
const args = await publicClientL2.buildProveWithdrawal({
output,
withdrawal,
})
const hash = await walletClientL1.proveWithdrawal(args)
import { publicClientL2, walletClientL1 } from './config'
const args = await publicClientL2.buildProveWithdrawal({
output,
withdrawal,
})
const hash = await walletClientL1.proveWithdrawal(args)
ts
import { createPublicClient, createWalletClient, custom, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet, base } from 'viem/chains'
import { publicActionsL2, walletActionsL1 } from 'viem/op-stack'
// Retrieve Account from an EIP-1193 Provider.
const [account] = await window.ethereum.request({
method: 'eth_requestAccounts'
})
export const walletClientL1 = createWalletClient({
account,
transport: custom(window.ethereum)
}).extend(walletActionsL1())
export const publicClientL2 = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
import { createPublicClient, createWalletClient, custom, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet, base } from 'viem/chains'
import { publicActionsL2, walletActionsL1 } from 'viem/op-stack'
// Retrieve Account from an EIP-1193 Provider.
const [account] = await window.ethereum.request({
method: 'eth_requestAccounts'
})
export const walletClientL1 = createWalletClient({
account,
transport: custom(window.ethereum)
}).extend(walletActionsL1())
export const publicClientL2 = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
ts
import { createPublicClient, createWalletClient, custom, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet, base } from 'viem/chains'
import { publicActionsL2, walletActionsL1 } from 'viem/op-stack'
export const walletClientL1 = createWalletClient({
account: privateKeyToAccount('0x...'),
transport: custom(window.ethereum)
}).extend(walletActionsL1())
export const publicClientL2 = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
import { createPublicClient, createWalletClient, custom, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet, base } from 'viem/chains'
import { publicActionsL2, walletActionsL1 } from 'viem/op-stack'
export const walletClientL1 = createWalletClient({
account: privateKeyToAccount('0x...'),
transport: custom(window.ethereum)
}).extend(walletActionsL1())
export const publicClientL2 = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
Returns
BuildProveWithdrawalReturnType
The parameters required to execute a prove withdrawal transaction.
Parameters
account (optional)
- Type:
Account | Address
The Account to send the transaction from.
Accepts a JSON-RPC Account or Local Account (Private Key, etc).
ts
const args = await client.buildProveWithdrawal({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
output,
withdrawal,
})
const args = await client.buildProveWithdrawal({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
output,
withdrawal,
})
output
- Type:
GetL2OutputReturnType
The L2 output. Typically provided by getL2Output
Action.
ts
const args = await client.buildProveWithdrawal({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
output: { /* ... */ },
withdrawal,
})
const args = await client.buildProveWithdrawal({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
output: { /* ... */ },
withdrawal,
})
withdrawal
- Type:
Withdrawal
The withdrawal message. Typically provided by getWithdrawals
Action.
ts
const args = await client.buildProveWithdrawal({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
output,
withdrawal: { /* ... */ },
})
const args = await client.buildProveWithdrawal({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
output,
withdrawal: { /* ... */ },
})