prepareDepositTransaction
Prepares parameters for a deposit transaction to be initiated on an L1 and executed on the L2.
Usage
import { account, baseClient, mainnetClient } from './config'
const request = await baseClient.prepareDepositTransaction({
account,
mint: parseEther('1'),
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})
const hash = await mainnetClient.depositTransaction(request)
import { account, baseClient, mainnetClient } from './config'
const request = await baseClient.prepareDepositTransaction({
account,
mint: parseEther('1'),
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})
const hash = await mainnetClient.depositTransaction(request)
import { createWalletClient, createPublicClient, custom, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet, base } from 'viem/chains'
import { publicActionsL2, walletActionsL1 } from 'viem/op-stack'
export const mainnetClient = createWalletClient({
chain: mainnet,
transport: custom(window.ethereum)
}).extend(walletActionsL1())
export const baseClient = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
// JSON-RPC Account
export const [account] = await mainnetClient.getAddresses()
// Local Account
export const account = privateKeyToAccount(...)
import { createWalletClient, createPublicClient, custom, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet, base } from 'viem/chains'
import { publicActionsL2, walletActionsL1 } from 'viem/op-stack'
export const mainnetClient = createWalletClient({
chain: mainnet,
transport: custom(window.ethereum)
}).extend(walletActionsL1())
export const baseClient = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
// JSON-RPC Account
export const [account] = await mainnetClient.getAddresses()
// Local Account
export const account = privateKeyToAccount(...)
Account Hoisting
If you do not wish to pass an account
to every prepareDepositTransaction
, you can also hoist the Account on the Wallet Client (see config.ts
).
import { baseClient, mainnetClient } from './config'
const request = await baseClient.prepareDepositTransaction({
mint: parseEther('1')
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})
const hash = await mainnetClient.depositTransaction(request)
import { baseClient, mainnetClient } from './config'
const request = await baseClient.prepareDepositTransaction({
mint: parseEther('1')
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})
const hash = await mainnetClient.depositTransaction(request)
import { createWalletClient, createPublicClient, 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 mainnetClient = createWalletClient({
account,
transport: custom(window.ethereum)
}).extend(walletActionsL1())
export const baseClient = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
import { createWalletClient, createPublicClient, 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 mainnetClient = createWalletClient({
account,
transport: custom(window.ethereum)
}).extend(walletActionsL1())
export const baseClient = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
import { createWalletClient, createPublicClient, custom, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet, base } from 'viem/chains'
import { publicActionsL2, walletActionsL1 } from 'viem/op-stack'
export const mainnetClient = createWalletClient({
account: privateKeyToAccount('0x...'),
transport: custom(window.ethereum)
}).extend(walletActionsL1())
export const baseClient = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
import { createWalletClient, createPublicClient, custom, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet, base } from 'viem/chains'
import { publicActionsL2, walletActionsL1 } from 'viem/op-stack'
export const mainnetClient = createWalletClient({
account: privateKeyToAccount('0x...'),
transport: custom(window.ethereum)
}).extend(walletActionsL1())
export const baseClient = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
Returns
DepositTransactionParameters
The parameters required to execute a deposit 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).
const request = await client.prepareDepositTransaction({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
})
const request = await client.prepareDepositTransaction({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
})
data (optional)
- Type:
Hex
Contract deployment bytecode or encoded contract method & arguments.
const request = await client.prepareDepositTransaction({
data: '0x...',
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})
const request = await client.prepareDepositTransaction({
data: '0x...',
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})
gas (optional)
- Type:
bigint
Gas limit for transaction execution on the L2.
const request = await client.prepareDepositTransaction({
gas: 21_000n,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
})
const request = await client.prepareDepositTransaction({
gas: 21_000n,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
})
isCreation (optional)
- Type:
boolean
Whether or not this is a contract deployment transaction.
const request = await client.prepareDepositTransaction({
data: '0x...',
isCreation: true
})
const request = await client.prepareDepositTransaction({
data: '0x...',
isCreation: true
})
mint (optional)
- Type:
bigint
Value in wei to mint (deposit) on the L2. Debited from the caller's L1 balance.
const request = await client.prepareDepositTransaction({
mint: parseEther('1')
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})
const request = await client.prepareDepositTransaction({
mint: parseEther('1')
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})
to (optional)
- Type:
Address
L2 Transaction recipient.
const request = await client.prepareDepositTransaction({
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
})
const request = await client.prepareDepositTransaction({
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
})
value (optional)
- Type:
bigint
Value in wei sent with this transaction on the L2. Debited from the caller's L2 balance.
const request = await client.prepareDepositTransaction({
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
})
const request = await client.prepareDepositTransaction({
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
})