Skip to content

Commit 6f4ce05

Browse files
tomip01ilitterijrchatruc
authored
docs(l2): add quick handsOn on bridging assets between L1 and L2 (#2589)
**Motivation** This PR tries to show some basic walkthrough on moving assets between the two chains in the docs **Description** * Add an example of how to deposit and how to withdraw funds in L2 and L1. * Explain the deposit functions from the CommonBridge contract in the L1 Closes #2524 --------- Co-authored-by: Ivan Litteri <[email protected]> Co-authored-by: Javier Rodríguez Chatruc <[email protected]>
1 parent 20437d6 commit 6f4ce05

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

crates/l2/docs/README.md

+77
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,83 @@ Make sure docker is running!
3737

3838
For more information on how to run the L2 node with the prover attached to it, the [Prover Docs](./prover.md) provides more insight.
3939

40+
## Bridge Assets
41+
42+
### Funding an L2 Account from L1
43+
44+
To transfer ETH from Ethereum L1 to your L2 account:
45+
46+
1. Prerequisites:
47+
- An L1 account with sufficient ETH balance, for developing purpose you can use:
48+
- Address: `0x8943545177806ed17b9f23f0a21ee5948ecaa776`
49+
- Private Key: `0xbcdf20249abf0ed6d944c0288fad489e33f66b3960d9e6229c1cd214ed3bbe31`
50+
- The address of the deployed CommonBridge contract.
51+
- An Ethereum utility tool like [Rex](https://github.com/lambdaclass/rex)
52+
53+
2. Make a deposit:
54+
55+
Using Rex is as simple as:
56+
```Shell
57+
# Format: rex l2 deposit <AMOUNT> <PRIVATE_KEY> <BRIDGE_ADDRESS> [L2_RPC_URL]
58+
rex l2 deposit 50000000 0xbcdf20249abf0ed6d944c0288fad489e33f66b3960d9e6229c1cd214ed3bbe31 0x65dd6dc5df74b7e08e92c910122f91d7b2d5184f
59+
```
60+
61+
3. Verification:
62+
63+
Once the deposit is made you can verify the balance has increase with:
64+
```Shell
65+
# Format: rex l2 balance <Address> [RPC_URL]
66+
rex l2 balance 0x8943545177806ed17b9f23f0a21ee5948ecaa776
67+
```
68+
69+
For more information on what you can do with the CommonBridge see [here](./contracts.md).
70+
71+
### Withdrawing funds from the L2 to L1
72+
73+
1. Prerequisites:
74+
- An L2 account with sufficient ETH balance, for developing purpose you can use:
75+
- Address: `0x8943545177806ed17b9f23f0a21ee5948ecaa776`
76+
- Private Key: `0xbcdf20249abf0ed6d944c0288fad489e33f66b3960d9e6229c1cd214ed3bbe31`
77+
- The address of the deployed CommonBridge L2 contract (note here that we are calling the L2 contract instead of the L1 as in the deposit case). You can use:
78+
- CommonBridge L2: `0x000000000000000000000000000000000000ffff`
79+
- An Ethereum utility tool like [Rex](https://github.com/lambdaclass/rex).
80+
81+
2. Make the Withdraw:
82+
83+
Using Rex we simply use the `rex l2 withdraw` command (it uses the default CommonBridge address).
84+
```Shell
85+
# Format: rex l2 withdraw <AMOUNT> <PRIVATE_KEY> [RPC_URL]
86+
rex l2 withdraw 5000 0xbcdf20249abf0ed6d944c0288fad489e33f66b3960d9e6229c1cd214ed3bbe31
87+
```
88+
89+
If the withdraw is successful, the hash will be printed in the format:
90+
91+
```
92+
Withdrawal sent: <L2_WITHDRAWAL_TX_HASH>
93+
...
94+
```
95+
96+
3. Claim the Withdraw:
97+
98+
After making the withdraw it has to be claimed in the L1. This is done with the L1 CommonBridge contract. We can use the Rex command `rex l2 claim-withdraw`. Here we have to use the tx hash obtained in the previous step. Also, it is necessary to wait for the block that includes the withdraw to be verified.
99+
100+
```Shell
101+
# Format: rex l2 claim-withdraw <L2_WITHDRAWAL_TX_HASH> <PRIVATE_KEY> <BRIDGE_ADDRESS>
102+
rex l2 claim-withdraw <L2_WITHDRAWAL_TX_HASH> 0xbcdf20249abf0ed6d944c0288fad489e33f66b3960d9e6229c1cd214ed3bbe31 0x65dd6dc5df74b7e08e92c910122f91d7b2d5184f
103+
```
104+
105+
4. Verification:
106+
107+
Once the withdrawal is made you can verify the balance has decrease with:
108+
```Shell
109+
rex l2 balance 0x8943545177806ed17b9f23f0a21ee5948ecaa776
110+
```
111+
112+
And also increased in the L1:
113+
```Shell
114+
rex balance 0x8943545177806ed17b9f23f0a21ee5948ecaa776
115+
```
116+
40117
## Configuration
41118

42119
Configuration consists of two steps, the parsing of a `.toml` config file and the creation and modification of a `.env` file, then each component reads the `.env` to load the environment variables. A detailed list is available in each part documentation.

crates/l2/docs/contracts.md

+26
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,32 @@
1717

1818
Allows L1<->L2 communication from L1. It both sends messages from L1 to L2 and receives messages from L2.
1919

20+
#### Deposit Functions
21+
22+
##### Simple Deposits
23+
24+
- Send ETH directly to the contract address using a standard transfer
25+
- The contract's `receive()` function automatically forwards funds to your identical address on L2
26+
- No additional parameters needed
27+
28+
##### Deposits with Contract Interaction
29+
30+
```solidity
31+
function deposit(DepositValues calldata depositValues) public payable
32+
```
33+
34+
Parameters:
35+
36+
- `to`: Target address on L2
37+
- `recipient`: Address that will receive the ETH on L2 (can differ from sender)
38+
- `gasLimit`: Maximum gas for L2 execution
39+
- `data`: Calldata to execute on the target L2 contract
40+
41+
This method enables atomic operations like:
42+
43+
- Depositing ETH while simultaneously interacting with L2 contracts
44+
- Funding another user's L2 account
45+
2046
### `OnChainOperator`
2147

2248
Ensures the advancement of the L2. It is used by the operator to commit batches of blocks and verify batch proofs.

0 commit comments

Comments
 (0)