|
1 | 1 | This document shows you how to customize wrapped tokens using adapter contracts, transfer tokens between Ethereum and Polygon zkEVM networks, and how to use Matic.js to bridge assets from Ethereum to Polygon zkEVM and vice versa. |
2 | 2 |
|
3 | | -## Basic functions for error passing |
4 | | - |
5 | | -We refer to Ethereum as the _root_ chain and zkEVM as the _child_ chain. |
6 | | - |
7 | | -Below we provide the two basic functions used for _error passing_ in each of the two directions: L1 --> L2 and L2 --> L1. |
8 | | - |
9 | | -**Message** |
10 | | - |
11 | | -- From root to child |
12 | | - |
13 | | -```jsx |
14 | | -const bridgeTx = zkEvmClient.rootChainBridge.bridgeMessage( |
15 | | - destinationNetwork: number, |
16 | | - destinationAddress: string, |
17 | | - forceUpdateGlobalExitRoot: boolean, |
18 | | - permitData = '0x', |
19 | | - option?: ITransactionOption |
20 | | -); |
21 | | - |
22 | | -const claimTx = zkEvmClient.childChainBridge.claimMessage( |
23 | | - smtProof: string[], |
24 | | - smtProofRollup: string[], |
25 | | - globalIndex: string, |
26 | | - mainnetExitRoot: string, |
27 | | - rollupExitRoot: string, |
28 | | - originNetwork: number, |
29 | | - originTokenAddress: string, |
30 | | - destinationNetwork: number, |
31 | | - destinationAddress: string, |
32 | | - amount: TYPE_AMOUNT, |
33 | | - metadata: string, |
34 | | - option: ITransactionOption |
35 | | -); |
36 | | - |
37 | | -// proof can be found from the proof gen API |
38 | | -``` |
39 | | - |
40 | | -- From child to root |
41 | | - |
42 | | -```jsx |
43 | | -const bridgeTx = zkEvmClient.childChainBridge.bridgeMessage( |
44 | | - destinationNetwork: number, |
45 | | - destinationAddress: string, |
46 | | - forceUpdateGlobalExitRoot: boolean, |
47 | | - permitData = '0x', |
48 | | - option?: ITransactionOption |
49 | | -); |
50 | | - |
51 | | -const claimTx = zkEvmClient.rootChainBridge.claimMessage( |
52 | | - smtProof: string[], |
53 | | - smtProofRollup: string[], |
54 | | - globalIndex: string, |
55 | | - mainnetExitRoot: string, |
56 | | - rollupExitRoot: string, |
57 | | - originNetwork: number, |
58 | | - originTokenAddress: string, |
59 | | - destinationNetwork: number, |
60 | | - destinationAddress: string, |
61 | | - amount: TYPE_AMOUNT, |
62 | | - metadata: string, |
63 | | - option: ITransactionOption |
64 | | -); |
65 | | - |
66 | | -// proof can be found from the proof gen API |
67 | | -``` |
68 | | - |
69 | 3 | ## Bridging customized ERC20 token |
70 | 4 |
|
71 | 5 | The existing zkEVM bridge uses the ERC-20 standard contract for creating wrapped tokens depending on the token's native network. |
@@ -254,3 +188,69 @@ Make sure you are using `matic.js version > 3.6.4`. |
254 | 188 | const txHash = await claimTx.getTransactionHash(); |
255 | 189 | console.log("claimed txHash", ctxHash); |
256 | 190 | ``` |
| 191 | +
|
| 192 | +
|
| 193 | +## Basic functions for error passing |
| 194 | +
|
| 195 | +We refer to Ethereum as the _root_ chain and zkEVM as the _child_ chain. |
| 196 | +
|
| 197 | +Below we provide the two basic functions used for _error passing_ in each of the two directions: L1 --> L2 and L2 --> L1. |
| 198 | +
|
| 199 | +
|
| 200 | +- From root to child (L1 --> L2) |
| 201 | +
|
| 202 | +```jsx |
| 203 | +const bridgeTx = zkEvmClient.rootChainBridge.bridgeMessage( |
| 204 | + destinationNetwork: number, |
| 205 | + destinationAddress: string, |
| 206 | + forceUpdateGlobalExitRoot: boolean, |
| 207 | + permitData = '0x', |
| 208 | + option?: ITransactionOption |
| 209 | +); |
| 210 | +
|
| 211 | +const claimTx = zkEvmClient.childChainBridge.claimMessage( |
| 212 | + smtProof: string[], |
| 213 | + smtProofRollup: string[], |
| 214 | + globalIndex: string, |
| 215 | + mainnetExitRoot: string, |
| 216 | + rollupExitRoot: string, |
| 217 | + originNetwork: number, |
| 218 | + originTokenAddress: string, |
| 219 | + destinationNetwork: number, |
| 220 | + destinationAddress: string, |
| 221 | + amount: TYPE_AMOUNT, |
| 222 | + metadata: string, |
| 223 | + option: ITransactionOption |
| 224 | +); |
| 225 | +
|
| 226 | +// proof can be found from the proof gen API |
| 227 | +``` |
| 228 | + |
| 229 | +- From child to root (L2 --> L1) |
| 230 | + |
| 231 | +```jsx |
| 232 | +const bridgeTx = zkEvmClient.childChainBridge.bridgeMessage( |
| 233 | + destinationNetwork: number, |
| 234 | + destinationAddress: string, |
| 235 | + forceUpdateGlobalExitRoot: boolean, |
| 236 | + permitData = '0x', |
| 237 | + option?: ITransactionOption |
| 238 | +); |
| 239 | + |
| 240 | +const claimTx = zkEvmClient.rootChainBridge.claimMessage( |
| 241 | + smtProof: string[], |
| 242 | + smtProofRollup: string[], |
| 243 | + globalIndex: string, |
| 244 | + mainnetExitRoot: string, |
| 245 | + rollupExitRoot: string, |
| 246 | + originNetwork: number, |
| 247 | + originTokenAddress: string, |
| 248 | + destinationNetwork: number, |
| 249 | + destinationAddress: string, |
| 250 | + amount: TYPE_AMOUNT, |
| 251 | + metadata: string, |
| 252 | + option: ITransactionOption |
| 253 | +); |
| 254 | + |
| 255 | +// proof can be found from the proof gen API |
| 256 | +``` |
0 commit comments