Skip to content
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

How to transfer a SuperchainERC20 #1048

Merged
merged 12 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pages/stack/interop/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"explainer": "Interop explainer",
"cross-chain-message": "Anatomy of cross-chain message",
"supersim": "Supersim Multichain Development Environment",
"superchain-erc20": "SuperchainERC20"
"superchain-erc20": "SuperchainERC20 token standard",
"transfer-superchainERC20": "How to transfer a SuperchainERC20"
krofax marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 3 additions & 3 deletions pages/stack/interop/superchain-erc20.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { Callout } from 'nextra/components'
Interop is currently in active development and not yet ready for production use. The information provided here may change. Check back regularly for the most up-to-date information.
</Callout>

`SuperchainERC20` is designed to enable asset interoperability in the Superchain.
`SuperchainERC20` is an implementation of [ERC-7802](https://ethereum-magicians.org/t/erc-7802-crosschain-token-interface/21508) designed to enable asset interoperability in the Superchain.
Asset interoperability allows for tokens to securely move across chains without asset wrapping or liquidity pools for maximal capital efficiency, thus unifying liquidity and simplifying the user experience.

Additional features:

* **Simplified deployments**: Provides a consistent, unified implementation for tokens across all Superchain-compatible networks and a common crosschain interface for the EVM ecosystem at large.
krofax marked this conversation as resolved.
Show resolved Hide resolved
* **Permissionless propagation**: Easily clone an existing token contract to a new OP Stack chain using `create2` without requiring the original owner, which enables movement of assets to the new chain once Interop goes live. Importantly, permissionless propagation retains the integrity of the original owner on the contract and preserves security but proliferates the contract's availability to new chains.
* **Ethereum-aligned**: Intentionally designed to be generic and supported as an Ethereum-wide implementation (RIP coming soon).
* **Ethereum-aligned**: Implements ERC-7802, a unified interface that can be used across all of Ethereum to enable cross-chain mint/burn functionality.
krofax marked this conversation as resolved.
Show resolved Hide resolved

## How it works

Expand Down Expand Up @@ -63,7 +63,7 @@ This diagram illustrates the process where tokens are burned on the source chain

`SuperchainERC20` differs from other token implementations in its focus and implementation:

* `SuperchainERC20` has minimal differentiation from an ERC20 deployment, only requiring a minimal crosschain mint/burn interface, which aims to be a common pattern for the EVM ecosystem (RIP coming soon).
* `SuperchainERC20` implements ERC-7802, which provides a minimal crosschain mint/burn interface designed to be a common pattern for the EVM ecosystem.
* `SuperchainERC20` shares trust assumptions across all chains in the Superchain, such that custom assumptions around security and latency are not required to account for when executing transfers.

<Callout type="info">
Expand Down
128 changes: 128 additions & 0 deletions pages/stack/interop/transfer-superchainERC20.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
title: How to transfer a SuperchainERC20
lang: en-US
description: Learn how to transfer a SuperchainERC20 between chains using L2ToL2CrossDomainMessenger.
---

import { Callout, Steps } from 'nextra/components'

# How to transfer a SuperchainERC20

This guide walks you through transferring SuperchainERC20 tokens between chains using the `L2ToL2CrossDomainMessenger` contract.

## Prerequisites

Before you begin, ensure you have:

* Access to source and destination chain RPC endpoints.
* A private key with funds on both chains.
* The `cast` command-line tool installed.

<Callout type="info">
All commands in this guide use the `cast` CLI tool. Make sure you have it properly configured with your RPC endpoints.
</Callout>

## Contract addresses

krofax marked this conversation as resolved.
Show resolved Hide resolved
The following contracts are used in this guide:

* L2NativeSuperchainERC20: `0x420beeF000000000000000000000000000000001`
krofax marked this conversation as resolved.
Show resolved Hide resolved
* L2ToL2CrossDomainMessenger: `0x4200000000000000000000000000000000000023`

krofax marked this conversation as resolved.
Show resolved Hide resolved
## How it works

Transferring tokens involves two main phases:

1. **Source chain operations**: Mint tokens and initiate the transfer.
2. **Destination chain operations**: Relay the message to complete the transfer.

<Callout type="warning">
Always verify your addresses and amounts before sending transactions. Cross-chain transfers cannot be reversed.
</Callout>

<Steps>

### Step 1: Mint tokens

First, mint tokens on the source chain:

```bash
cast send 0x420beeF000000000000000000000000000000001 \
"mint(address _to, uint256 _amount)" \
YOUR_ADDRESS 1000 \
--rpc-url SOURCE_CHAIN_RPC \
--private-key YOUR_PRIVATE_KEY
```

<Callout type="default">
Replace `YOUR_ADDRESS`, `SOURCE_CHAIN_RPC`, and `YOUR_PRIVATE_KEY` with your actual values.
</Callout>

### Step 2: Initiate transfer

After minting, initiate the bridge transfer:

```bash
cast send 0x4200000000000000000000000000000000000028 \
"sendERC20(address _token, address _to, uint256 _amount, uint256 _chainId)" \
0x420beeF000000000000000000000000000000001 \
RECIPIENT_ADDRESS 1000 DESTINATION_CHAIN_ID \
--rpc-url SOURCE_CHAIN_RPC \
--private-key YOUR_PRIVATE_KEY
```
krofax marked this conversation as resolved.
Show resolved Hide resolved

<Callout type="important">
The transfer isn't complete until you relay the message on the destination chain.
</Callout>

### Step 3: Get message details

Retrieve the message details from the L2ToL2CrossDomainMessenger:

```bash
cast logs \
--address 0x4200000000000000000000000000000000000023 \
--rpc-url SOURCE_CHAIN_RPC
```

<Callout type="info">
Note down the `blockNumber`, `logIndex`, and timestamp - you'll need these for relaying.
</Callout>

### Step 4: Relay the message

Complete the transfer by relaying the message on the destination chain:

```bash
cast send 0x4200000000000000000000000000000000000023 \
--gas-limit 200000 \
"relayMessage((address, uint256, uint256, uint256, uint256), bytes)" \
"(0x4200000000000000000000000000000000000023, BLOCK_NUMBER, LOG_INDEX, TIMESTAMP, SOURCE_CHAIN_ID)" \
MESSAGE_PAYLOAD \
--rpc-url DESTINATION_CHAIN_RPC \
--private-key YOUR_PRIVATE_KEY
```

### Step 5: Verify transfer

Check the balance on the destination chain:

```bash
cast balance \
--erc20 0x420beeF000000000000000000000000000000001 \
RECIPIENT_ADDRESS \
--rpc-url DESTINATION_CHAIN_RPC
```
</Steps>

## Alternative methods

You can also use:

* `supersim --interop.autorelay` for development environments
krofax marked this conversation as resolved.
Show resolved Hide resolved
* [viem bindings/actions](https://supersim.pages.dev/guides/interop/relay-using-viem) for TypeScript integration

## Next steps

* Read the [Superchain Interop Explainer](/stack/interop/explainer#faqs) or check out this [Superchain interop design video walk-thru](https://www.youtube.com/watch?v=FKc5RgjtGes).
* Use [Supersim](supersim), a local dev environment that simulates Superchain interop for testing applications against a local version of the Superchain.
krofax marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 5 additions & 3 deletions words.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
accountqueue
ACCOUNTQUEUE
accountqueue
ACCOUNTSLOTS
accountslots
ADDI
Expand Down Expand Up @@ -29,8 +29,8 @@ BLOBPOOL
blobpool
blobspace
blockhash
BLOCKLOGS
blocklists
BLOCKLOGS
blocklogs
BLOCKPROFILERATE
blockprofilerate
Expand Down Expand Up @@ -326,7 +326,9 @@ safedb
Schnorr
secp
SELFDESTRUCT
SEPOLIA
Sepolia
sepolia
seqnr
SEQUENCERHTTP
sequencerhttp
Expand Down Expand Up @@ -404,4 +406,4 @@ xtensibility
ZKPs
ZKVM
Zora
zora
zora
krofax marked this conversation as resolved.
Show resolved Hide resolved
Loading