diff --git a/site/.vitepress/config.mts b/site/.vitepress/config.mts index fe24ce1..f21341c 100644 --- a/site/.vitepress/config.mts +++ b/site/.vitepress/config.mts @@ -105,6 +105,10 @@ export default defineConfig({ { text: 'L1', items: [ + { + text: 'writeContractDeposit', + link: '/docs/actions/wallet/L1/writeContractDeposit', + }, { text: 'writeDepositERC20', link: '/docs/actions/wallet/L1/writeDepositERC20', diff --git a/site/docs/actions/public/L1/getOutputForL2Block.md b/site/docs/actions/public/L1/getOutputForL2Block.md index a974b3a..39cd611 100644 --- a/site/docs/actions/public/L1/getOutputForL2Block.md +++ b/site/docs/actions/public/L1/getOutputForL2Block.md @@ -52,6 +52,6 @@ The block number of the L2 block for which to get the output. ### l2OutputOracle -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The address of the L2OutputOracle contract where the `getOutputForL2Block` call will be made. diff --git a/site/docs/actions/public/L1/getSecondsToFinalizable.md b/site/docs/actions/public/L1/getSecondsToFinalizable.md index ca3aa16..13ac776 100644 --- a/site/docs/actions/public/L1/getSecondsToFinalizable.md +++ b/site/docs/actions/public/L1/getSecondsToFinalizable.md @@ -36,13 +36,13 @@ Returns a `number` representative of the seconds until withdrawal finalization. ### portal -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The address of the `OptimismPortal` contract where the `readProvenWithdrawals` call will be made. ### l2OutputOracle -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The address of the L2OutputOracle contract where the `FINALIZATION_PERIOD_SECONDS` call will be made. diff --git a/site/docs/actions/public/L1/getSecondsToNextL2Output.md b/site/docs/actions/public/L1/getSecondsToNextL2Output.md index 4e04cbe..696563c 100644 --- a/site/docs/actions/public/L1/getSecondsToNextL2Output.md +++ b/site/docs/actions/public/L1/getSecondsToNextL2Output.md @@ -41,6 +41,6 @@ The latest L2 block number. ### l2OutputOracle -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The address of the L2OutputOracle contract. diff --git a/site/docs/actions/public/L1/readFinalizedWithdrawals.md b/site/docs/actions/public/L1/readFinalizedWithdrawals.md index 57a3705..a647827 100644 --- a/site/docs/actions/public/L1/readFinalizedWithdrawals.md +++ b/site/docs/actions/public/L1/readFinalizedWithdrawals.md @@ -33,7 +33,7 @@ Returns a `boolean` for whether the withdrawal has been finalized. ### portalAddress -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The `OptimismPortal` contract where the sendMessage call should be made. diff --git a/site/docs/actions/public/L1/readProvenWithdrawals.md b/site/docs/actions/public/L1/readProvenWithdrawals.md index 7bccb0f..c7a3e88 100644 --- a/site/docs/actions/public/L1/readProvenWithdrawals.md +++ b/site/docs/actions/public/L1/readProvenWithdrawals.md @@ -42,7 +42,7 @@ type ProvenWithdrawal = { ### portal -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The `OptimismPortal` contract where the sendMessage call should be made. diff --git a/site/docs/actions/public/L1/simulateDepositERC20.md b/site/docs/actions/public/L1/simulateDepositERC20.md index 1c7abd1..6407f6d 100644 --- a/site/docs/actions/public/L1/simulateDepositERC20.md +++ b/site/docs/actions/public/L1/simulateDepositERC20.md @@ -63,7 +63,7 @@ Returns a `request` that can be passed to Viem's `writeContract` and a `result` ### l1StandardBridge -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The `L1StandardBridge` contract. diff --git a/site/docs/actions/public/L1/simulateDepositETH.md b/site/docs/actions/public/L1/simulateDepositETH.md index 9fe705c..e7ccf14 100644 --- a/site/docs/actions/public/L1/simulateDepositETH.md +++ b/site/docs/actions/public/L1/simulateDepositETH.md @@ -48,7 +48,7 @@ The amount of ETH to deposit. ### portal -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The `OptimismPortal` contract. diff --git a/site/docs/actions/public/L1/simulateDepositTransaction.md b/site/docs/actions/public/L1/simulateDepositTransaction.md index 20e8db8..9e361a2 100644 --- a/site/docs/actions/public/L1/simulateDepositTransaction.md +++ b/site/docs/actions/public/L1/simulateDepositTransaction.md @@ -105,7 +105,7 @@ await publicClient.simulateDepositTransaction({ ### portal -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The `OptimismPortal` contract where the depositTransaction call should be made. diff --git a/site/docs/actions/public/L1/simulateFinalizeWithdrawalTransaction.md b/site/docs/actions/public/L1/simulateFinalizeWithdrawalTransaction.md index 7e0d34c..b589ca3 100644 --- a/site/docs/actions/public/L1/simulateFinalizeWithdrawalTransaction.md +++ b/site/docs/actions/public/L1/simulateFinalizeWithdrawalTransaction.md @@ -51,7 +51,7 @@ type FinalizeWithdrawalTransactionParameters = { ### portal -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The `OptimismPortal` contract. diff --git a/site/docs/actions/public/L1/simulateProveWithdrawalTransaction.md b/site/docs/actions/public/L1/simulateProveWithdrawalTransaction.md index a0b9ed9..ad9273a 100644 --- a/site/docs/actions/public/L1/simulateProveWithdrawalTransaction.md +++ b/site/docs/actions/public/L1/simulateProveWithdrawalTransaction.md @@ -142,7 +142,7 @@ await walletClient.simulateProveWithdrawalTransaction({ ### portal(optional) -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The `OptimismPortal` contract where the sendMessage call should be made. diff --git a/site/docs/actions/wallet/L1/writeContractDeposit.md b/site/docs/actions/wallet/L1/writeContractDeposit.md new file mode 100644 index 0000000..7d55aad --- /dev/null +++ b/site/docs/actions/wallet/L1/writeContractDeposit.md @@ -0,0 +1,94 @@ +# writeContractDeposit + +Creates an L1 to L2 transaction by depositing into a contract on L2. This function serves as a specialized version of Viem's `writeContract`, adapted for L1 -> L2 transactions. + +```ts [example.ts] +import { erc721ABI } from 'wagmi' +import { writeContractDeposit } from 'your-library' +import { walletClient } from 'your-library-client-setup' +import { baseAddresses } from 'your-library/chains' + +const txHash = await writeContractDeposit(walletClient, { + abi: erc721ABI, + address: '0x6171f829e107f70b58d67594c6b62a7d3eb7f23b', + functionName: 'approve', + args: ['0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', 2048n], + account: '0xYourAccountAddress', + l2GasLimit: 100000n, + ...baseAddresses, +}) +``` + +## Return Value + +Returns a transaction hash for the L2 transaction being initiated. The transaction hash conforms to Viem's [`WriteContractReturnType`](https://viem.sh/docs/glossary/types#writecontractreturntype). + +## Parameters + +### abi + +- **Type:** `Abi | readonly unknown[]` + +The ABI (Application Binary Interface) related to the contract. + +### address + +- **Type:** `Address` + +The contract address on L2 that you are interacting with. + +### functionName + +- **Type:** `string` + +The contract function name to call on L2. + +### args + +- **Type:** `Array` + +The arguments to pass to the function. Must match the function signature. + +### account + +- **Type:** `Account | Address` + +Account address initiating the L2 transaction. If not supplied, defaults to `client.account`. + +### l2GasLimit + +- **Type:** `bigint` + +Gas limit for the L2 transaction. + +### l2MsgValue (Optional) + +- **Type:** `bigint` + +The Ether value sent along with the L2 transaction. Defaults to `0n`. + +### strict (Optional) + +- **Type:** `boolean` + +If set to `true`, throws an error when called from a smart contract account. Defaults to `true`. + +### portal + +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) + +The `OptimismPortal` contract, or equivalent, facilitating the L1 to L2 transition. + +## Notes + +- The function will throw an error if `strict` is `true` and the `account` is a smart contract. This is to mitigate unexpected behavior due to [address aliasing](https://github.com/ethereum-optimism/optimism/blob/develop/specs/deposits.md#address-aliasing). + +- The function uses `encodeFunctionData` to create calldata for the L2 transaction, thus requiring ABI, function name, and args. + +- This function wraps around `writeDepositTransaction` and adds additional logic to cater to L2 transactions from L1. + +## Errors + +- Throws "No account found" if no `account` is supplied and none is set in the `client`. + +- Throws a strict mode error when called from a smart contract account with `strict` set to `true`. diff --git a/site/docs/actions/wallet/L1/writeDepositERC20.md b/site/docs/actions/wallet/L1/writeDepositERC20.md index 1ca96ff..da5322e 100644 --- a/site/docs/actions/wallet/L1/writeDepositERC20.md +++ b/site/docs/actions/wallet/L1/writeDepositERC20.md @@ -74,7 +74,7 @@ Extra data to include in the transaction. ### l1StandardBridge -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The `L1StandardBridge` contract. diff --git a/site/docs/actions/wallet/L1/writeDepositETH.md b/site/docs/actions/wallet/L1/writeDepositETH.md index 0a5e4df..caad08d 100644 --- a/site/docs/actions/wallet/L1/writeDepositETH.md +++ b/site/docs/actions/wallet/L1/writeDepositETH.md @@ -51,7 +51,7 @@ The amount of ETH to deposit. ### portal -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The `OptimismPortal` contract. diff --git a/site/docs/actions/wallet/L1/writeDepositTransaction.md b/site/docs/actions/wallet/L1/writeDepositTransaction.md index e5406dd..fd29bb9 100644 --- a/site/docs/actions/wallet/L1/writeDepositTransaction.md +++ b/site/docs/actions/wallet/L1/writeDepositTransaction.md @@ -122,7 +122,7 @@ await walletClient.writeDepositTransaction({ ### portal -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The `OptimismPortal` contract where the depositTransaction call should be made. diff --git a/site/docs/actions/wallet/L1/writeFinalizeWithdrawalTransaction.md b/site/docs/actions/wallet/L1/writeFinalizeWithdrawalTransaction.md index da57cf1..0aee8e6 100644 --- a/site/docs/actions/wallet/L1/writeFinalizeWithdrawalTransaction.md +++ b/site/docs/actions/wallet/L1/writeFinalizeWithdrawalTransaction.md @@ -40,6 +40,6 @@ type FinalizeWithdrawalTransactionParameters = { ### portal -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The `OptimismPortal` contract. diff --git a/site/docs/actions/wallet/L1/writeProveWithdrawalTransaction.md b/site/docs/actions/wallet/L1/writeProveWithdrawalTransaction.md index 7ba7129..87adae3 100644 --- a/site/docs/actions/wallet/L1/writeProveWithdrawalTransaction.md +++ b/site/docs/actions/wallet/L1/writeProveWithdrawalTransaction.md @@ -184,7 +184,7 @@ await walletClient.writeProveWithdrawalTransaction({ ### portal -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The `OptimismPortal` contract where the sendMessage call should be made. diff --git a/site/docs/actions/wallet/L1/writeSendMessage.md b/site/docs/actions/wallet/L1/writeSendMessage.md index 1e6a2ff..4b3ecde 100644 --- a/site/docs/actions/wallet/L1/writeSendMessage.md +++ b/site/docs/actions/wallet/L1/writeSendMessage.md @@ -89,7 +89,7 @@ await walletClient.writeSendMessage({ ### l1CrossDomainMessenger -- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress) +- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress) The `L1CrossDomainMessenger` contract where the sendMessage call should be made.