Skip to content

docs(l2): add quick handsOn on bridging assets between L1 and L2 #2589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 30, 2025
Merged
65 changes: 65 additions & 0 deletions crates/l2/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,71 @@ Make sure docker is running!

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

## Bridge Assets

### Funding an L2 Account from L1

To transfer ETH from Ethereum L1 to your L2 account:

1. Prerequisites:
- An L1 account with sufficient ETH balance
- The address of the deployed CommonBridge contract
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When developing locally, the value of this address is always the same. Let's put it here for reference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 5e728a7

- An Ethereum utility tool like [Rex](https://github.com/lambdaclass/rex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😉


2. Make a deposit:

Using Rex is as simple as:
```Shell
# Format: rex l2 deposit <AMOUNT> <PRIVATE_KEY> <BRIDGE_ADDRESS> [L2_RPC_URL]
rex l2 deposit 50000000 0xbcdf20249abf0ed6d944c0288fad489e33f66b3960d9e6229c1cd214ed3bbe31 0x65dd6dc5df74b7e08e92c910122f91d7b2d5184f
```

3. Verification:

Once the deposit is made you can verify the balance has increase with:
```Shell
# Format: rex l2 balance <Address> [RPC_URL]
rex l2 balance 0x8943545177806ed17b9f23f0a21ee5948ecaa776
```

For more information on what you can do with the CommonBridge see [here](./contracts.md).

### Withdrawing funds from the L2 to L1

1. Prerequisites:
- An L2 account with sufficient ETH balance
- 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)
- An Ethereum utility tool like [Rex](https://github.com/lambdaclass/rex)

2. Make the Withdraw:

Using Rex we simply use the `rex l2 withdraw` command.
```Shell
# Format: rex l2 withdraw <AMOUNT> <PRIVATE_KEY> [RPC_URL]
rex l2 withdraw 5000 0xbcdf20249abf0ed6d944c0288fad489e33f66b3960d9e6229c1cd214ed3bbe31
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a comment saying that if successful, the tx_hash will be printed in the format: Withdrawal sent: 0x7d01..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
0e45603


3. Claim the Withdraw:

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 committed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 committed.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 54adfb5


```Shell
# Format: rex l2 claim-withdraw <L2_WITHDRAWAL_TX_HASH> <PRIVATE_KEY> <BRIDGE_ADDRESS>
rex l2 claim-withdraw <L2_WITHDRAWAL_TX_HASH> 0xbcdf20249abf0ed6d944c0288fad489e33f66b3960d9e6229c1cd214ed3bbe31 0x65dd6dc5df74b7e08e92c910122f91d7b2d5184f
```

4. Verification:

Once the withdrawal is made you can verify the balance has decrease with:
```Shell
rex l2 balance 0x8943545177806ed17b9f23f0a21ee5948ecaa776
```

And also increased in the L1:
```Shell
rex balance 0x8943545177806ed17b9f23f0a21ee5948ecaa776
```

## Configuration

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.
Expand Down
26 changes: 26 additions & 0 deletions crates/l2/docs/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,32 @@

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

#### Deposit Functions

##### Simple Deposits

- Send ETH directly to the contract address using a standard transfer
- The contract's `receive()` function automatically forwards funds to your identical address on L2
- No additional parameters needed

##### Deposits with Contract Interaction

```solidity
function deposit(DepositValues calldata depositValues) public payable
```

Parameters:

- `to`: Target address on L2
- `recipient`: Address that will receive the ETH on L2 (can differ from sender)
- `gasLimit`: Maximum gas for L2 execution
- `data`: Calldata to execute on the target L2 contract

This method enables atomic operations like:

- Depositing ETH while simultaneously interacting with L2 contracts
- Funding another user's L2 account

### `OnChainOperator`

Ensures the advancement of the L2. It is used by the operator to commit blocks and verify block proofs
Expand Down
Loading