From 0f7640a560524ba4120a0ef1148a369c00d5fa6f Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 20 Aug 2024 16:44:36 +0100 Subject: [PATCH] fix: format steps --- .../how-to-send-l1-l2-transaction/10.index.md | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/content/tutorials/how-to-send-l1-l2-transaction/10.index.md b/content/tutorials/how-to-send-l1-l2-transaction/10.index.md index 7765474a..44422c48 100644 --- a/content/tutorials/how-to-send-l1-l2-transaction/10.index.md +++ b/content/tutorials/how-to-send-l1-l2-transaction/10.index.md @@ -92,90 +92,90 @@ Sending an L1->L2 transaction requires following these steps: 1. Initialise the providers and the wallet that will send the transaction: - ```ts - const l1provider = new Provider(L1_RPC_ENDPOINT); - const l2provider = new Provider(L2_RPC_ENDPOINT); - const wallet = new Wallet(WALLET_PRIV_KEY, l2provider, l1provider); - ``` + ```ts + const l1provider = new Provider(L1_RPC_ENDPOINT); + const l2provider = new Provider(L2_RPC_ENDPOINT); + const wallet = new Wallet(WALLET_PRIV_KEY, l2provider, l1provider); + ``` 1. Retrieve the current gas price on L1. - ```ts - // retrieve L1 gas price - const l1GasPrice = await l1provider.getGasPrice(); - console.log(`L1 gasPrice ${ethers.utils.formatEther(l1GasPrice)} ETH`); - ``` + ```ts + // retrieve L1 gas price + const l1GasPrice = await l1provider.getGasPrice(); + console.log(`L1 gasPrice ${ethers.utils.formatEther(l1GasPrice)} ETH`); + ``` 1. Populate the transaction that you want to execute on L2: - ```ts - const contract = new Contract(L2_CONTRACT_ADDRESS, ABI, wallet); - // populate tx object - const tx = await contract.populateTransaction.setGreeting(message); - ``` + ```ts + const contract = new Contract(L2_CONTRACT_ADDRESS, ABI, wallet); + // populate tx object + const tx = await contract.populateTransaction.setGreeting(message); + ``` 1. Retrieve the gas limit for sending the populated transaction to L2 using `estimateGasL1()` from `zksync-ethers` `Provider` class. This function calls the `zks_estimateGasL1ToL2` RPC method under the hood: - ```ts - // Estimate gas limit for L1-L2 tx - const l2GasLimit = await l2provider.estimateGasL1(tx); - console.log(`L2 gasLimit ${l2GasLimit.toString()}`); - ``` + ```ts + // Estimate gas limit for L1-L2 tx + const l2GasLimit = await l2provider.estimateGasL1(tx); + console.log(`L2 gasLimit ${l2GasLimit.toString()}`); + ``` 1. Calculate the total transaction fee to cover the cost of sending the -transaction on L1 and executing the transaction on L2 using -`getBaseCost` from the `Wallet` class. This method: + transaction on L1 and executing the transaction on L2 using + `getBaseCost` from the `Wallet` class. This method: -- Retrieves the ZKsync BridgeHub contract address calling `zks_getBridgehubContract` RPC method. -- Calls the `l2TransactionBaseCost` function on the ZKsync BridgeHub system contract to retrieve the fee. + - Retrieves the ZKsync BridgeHub contract address calling `zks_getBridgehubContract` RPC method. + - Calls the `l2TransactionBaseCost` function on the ZKsync BridgeHub system contract to retrieve the fee. - ```ts - const baseCost = await wallet.getBaseCost({ - // L2 computation - gasLimit: l2GasLimit, - // L1 gas price - gasPrice: l1GasPrice, - }); + ```ts + const baseCost = await wallet.getBaseCost({ + // L2 computation + gasLimit: l2GasLimit, + // L1 gas price + gasPrice: l1GasPrice, + }); - console.log(`Executing this transaction will cost ${ethers.utils.formatEther(baseCost)} ETH`); - ``` + console.log(`Executing this transaction will cost ${ethers.utils.formatEther(baseCost)} ETH`); + ``` 1. Encode the transaction calldata: - ```ts - const iface = new ethers.utils.Interface(ABI); - const calldata = iface.encodeFunctionData("setGreeting", [message]); - ``` + ```ts + const iface = new ethers.utils.Interface(ABI); + const calldata = iface.encodeFunctionData("setGreeting", [message]); + ``` 1. Finally, send the transaction from your wallet using the `requestExecute` method. This helper method: -- Retrieves the Zksync BridgeHub contract address calling `zks_getBridgehubContract`. -- Populates the L1-L2 transaction. -- Sends the transaction to the `requestL2TransactionDirect` function of the ZKsync BridgeHub system contract on L1. - - ```ts - const txReceipt = await wallet.requestExecute({ - // destination contract in L2 - contractAddress: L2_CONTRACT_ADDRESS, - calldata, - l2GasLimit: l2GasLimit, - refundRecipient: wallet.address, - overrides: { - // send the required amount of ETH - value: baseCost, - gasPrice: l1GasPrice, - }, - }); - txReceipt.wait(); - ``` + - Retrieves the Zksync BridgeHub contract address calling `zks_getBridgehubContract`. + - Populates the L1-L2 transaction. + - Sends the transaction to the `requestL2TransactionDirect` function of the ZKsync BridgeHub system contract on L1. + + ```ts + const txReceipt = await wallet.requestExecute({ + // destination contract in L2 + contractAddress: L2_CONTRACT_ADDRESS, + calldata, + l2GasLimit: l2GasLimit, + refundRecipient: wallet.address, + overrides: { + // send the required amount of ETH + value: baseCost, + gasPrice: l1GasPrice, + }, + }); + txReceipt.wait(); + ``` ## Full example Create a `send-l1-l2-tx.ts` file in the root directory with the next script: ::drop-panel - ::panel{label="send-l1-l2-tx.ts"} + ::panel{label="Click to show L1-L2 full script"} ```ts [send-l1-l2-tx.ts] import { Contract, Wallet, Provider, types } from "zksync-ethers";