From bea30475d4155fd116914be1154d660e98c47ada Mon Sep 17 00:00:00 2001 From: Harpal Jadeja Date: Tue, 6 Aug 2024 20:08:57 +0530 Subject: [PATCH] fix: add code to wait for receipts in L1 to L2 deposit guide (#1391) * fix: add code to wait for receipts in L1 to L2 deposit guide * feat: add `getL2TransactionHashes` and `dango.js` --- ...-celo-from-holesky-to-dango-using-viem.mdx | 102 +++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/docs/cel2/bridging/bridging-celo-from-holesky-to-dango-using-viem.mdx b/docs/cel2/bridging/bridging-celo-from-holesky-to-dango-using-viem.mdx index 11bcf2eb78..0295c2c9b8 100644 --- a/docs/cel2/bridging/bridging-celo-from-holesky-to-dango-using-viem.mdx +++ b/docs/cel2/bridging/bridging-celo-from-holesky-to-dango-using-viem.mdx @@ -13,9 +13,11 @@ Bridging Celo from Holesky to Dango is simple, all you need to do is call `depos ```js - import { createWalletClient, http, parseEther } from "viem"; + import { createWalletClient, createPublicClient, http, parseEther } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { holesky } from "viem/chains"; + import { getL2TransactionHashes, publicActionsL2 } from "viem/op-stack"; + import { dango } from "./dango.js"; const CELOL1 = "0xDEd08f6Ec0A57cE6Be62d1876d2CE92AF37eddA0"; @@ -31,6 +33,17 @@ Bridging Celo from Holesky to Dango is simple, all you need to do is call `depos transport: http(), }); + export const publicClientL1 = createPublicClient({ + account, + chain: holesky, + transport: http(), + }); + + export const publicClientL2 = createPublicClient({ + chain: dango, + transport: http(), + }).extend(publicActionsL2()); + async function main() { // Approve OptimismPortal to pull Celo on Holesky const approve = await walletClientL1.writeContract({ @@ -51,6 +64,11 @@ Bridging Celo from Holesky to Dango is simple, all you need to do is call `depos console.log(`Approval TX Hash: ${approve}`); + let approveReceipt = await publicClientL1.waitForTransactionReceipt({ + hash: approve, + }); + console.log(`Approve Transaction Receipt: ${approveReceipt}`); + // Call depositERC20Transaction on OptimismPortal const deposit = await walletClientL1.writeContract({ address: OptimismPortalProxy, @@ -98,10 +116,92 @@ Bridging Celo from Holesky to Dango is simple, all you need to do is call `depos }); console.log(`Deposit Transaction: ${deposit}`); + + + let depositReceipt = await publicClientL1.waitForTransactionReceipt({ + hash: deposit, + }); + console.log(`Deposit Transaction Receipt: ${depositReceipt}`); + + // Get the L2 transaction hash from the L1 transaction receipt. + const [l2Hash] = getL2TransactionHashes(depositReceipt); + + // Wait for the L2 transaction to be processed. + const l2Receipt = await publicClientL2.waitForTransactionReceipt({ + hash: l2Hash, + }); + + console.log(`L2Receipt: ${l2Receipt}`); } main(); ``` + + + + ```js + import { defineChain } from "viem"; + + const sourceId = 17000; + + export const dango = defineChain({ + name: "Dango Testnet", + id: 44_787, + nativeCurrency: { + decimals: 18, + name: "CELO", + symbol: "CELO", + }, + rpcUrls: { + default: { + http: ["https://forno.dango.celo-testnet.org"], + }, + }, + contracts: { + gasPriceOracle: { address: "0x420000000000000000000000000000000000000F" }, + l1Block: { address: "0x4200000000000000000000000000000000000015" }, + l2CrossDomainMessenger: { + address: "0x4200000000000000000000000000000000000007", + }, + l2Erc721Bridge: { address: "0x4200000000000000000000000000000000000014" }, + l2StandardBridge: { address: "0x4200000000000000000000000000000000000010" }, + l2ToL1MessagePasser: { + address: "0x4200000000000000000000000000000000000016", + }, + disputeGameFactory: { + [sourceId]: { + address: "0x831f39053688f05698ad0fB5f4DE7e56B2949c55", + }, + }, + l2OutputOracle: { + [sourceId]: { + address: "0x419577592C884868C3ed85B97169b93362581855", + }, + }, + portal: { + [sourceId]: { + address: "0xB29597c6866c6C2870348f1035335B75eEf79d07", + }, + }, + l1StandardBridge: { + [sourceId]: { + address: "0x9FEBd0F16b97e0AEF9151AF07106d733E87B1be4", + }, + }, + }, + blockExplorers: { + default: { + name: "Celo Explorer", + url: "https://explorer.celo.org/alfajores", + apiUrl: "https://explorer.celo.org/api", + }, + }, + testnet: true, + }); + + ``` + +