You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn how to transfer a SuperchainERC20 between chains using L2ToL2CrossDomainMessenger.
5
5
---
@@ -13,106 +13,202 @@ Please note that the OP Stack interoperability upgrade, required for crosschain
13
13
14
14
# Transferring a SuperchainERC20
15
15
16
-
This guide provides an overview of transferring `SuperchainERC20` tokens between chains.
16
+
This guide shows how to transfer `SuperchainERC20` tokens between chains programatically.
17
+
18
+
<Callout>
19
+
This tutorial provides step-by-step instructions for transferring `SuperchainERC20` tokens using code.
20
+
[See here](../superchain-erc20#how-it-works) for a detailed explanation of how this works.
21
+
</Callout>
17
22
18
23
## Overview
19
24
20
-
Transferring SuperchainERC20 tokens between chains involves two main phases:
25
+
**Warning:** Always verify your addresses and amounts before sending transactions.
26
+
Cross-chain transfers cannot be reversed.
21
27
22
-
1.**Source Chain Operations**
23
-
* Mint tokens if needed
24
-
* Initiate the transfer using the bridge
25
-
2.**Destination Chain Operations**
26
-
* Relay the transfer message
27
-
* Verify the transfer completion
28
+
### What you'll build
28
29
29
-
<Callouttype="warning">
30
-
Always verify your addresses and amounts before sending transactions. Cross-chain transfers cannot be reversed.
31
-
</Callout>
30
+
* A TypeScript application to transfer `SuperchainERC20` tokens between chains
31
+
32
+
### What you'll learn
33
+
34
+
* How to send `SuperchainERC20` tokens on the blockchain and between blockchains
35
+
* How to relay messages between chains
36
+
37
+
## Prerequisites
38
+
39
+
Before starting this tutorial, ensure your development environment meets the following requirements:
40
+
41
+
### Technical knowledge
42
+
43
+
* Intermediate TypeScript knowledge
44
+
* Understanding of smart contract development
45
+
* Familiarity with blockchain concepts
46
+
47
+
### Development environment
32
48
33
-
## How it works
34
-
35
-
This diagram illustrates the process of a SuperchainERC20 token transfer between chains.
36
-
Through the `L2ToL2CrossDomainMessenger` contract, tokens are burned on the source chain and a transfer message is emitted.
37
-
This message must then be relayed to the destination chain, where an equivalent amount of tokens will be minted to the specified recipient address - ensuring secure cross-chain transfers while maintaining the total token supply across all chains.
38
-
39
-
```mermaid
40
-
sequenceDiagram
41
-
actor User
42
-
participant SourceChain
43
-
participant Bridge as L2ToL2CrossDomainMessenger
44
-
participant DestChain
45
-
46
-
Note over User,DestChain: Step 1: Prepare Tokens
47
-
User->>SourceChain: Check token balance
48
-
alt
49
-
User->>SourceChain: Mint or acquire tokens
50
-
end
51
-
52
-
Note over User,DestChain: Step 2: Initiate Transfer
53
-
User->>SourceChain: Approve bridge contract
54
-
User->>Bridge: Call sendERC20
55
-
Bridge->>SourceChain: Burn tokens
56
-
Bridge-->>Bridge: Emit transfer message
57
-
58
-
Note over User,DestChain: Step 3: Complete Transfer
59
-
User->>Bridge: Get message details
60
-
User->>Bridge: Relay message on destination
61
-
Bridge->>DestChain: Mint tokens to recipient
62
-
63
-
Note over User,DestChain: Step 4: Verify
64
-
User->>DestChain: Check token balance
65
-
```
49
+
* Unix-like operating system (Linux, macOS, or WSL for Windows)
50
+
* Node.js version 16 or higher
51
+
* Git for version control
52
+
53
+
### Required tools
54
+
55
+
The tutorial uses these primary tools:
56
+
57
+
* Foundry: For issuing transactions
58
+
* TypeScript: For implementation
59
+
* Node: For running TypeScript code from the command line
60
+
* Viem: For blockchain interaction
61
+
62
+
63
+
## Directions
66
64
67
65
<Steps>
68
-
### Prepare your tokens
69
66
70
-
Ensure you have tokens on the source chain using one of these methods:
67
+
### Preparation
71
68
72
-
* Use existing tokens you already own
73
-
* Mint new tokens using the [SuperchainERC20 contract](https://github.com/ethereum-optimism/supersim/blob/main/contracts/src/L2NativeSuperchainERC20.sol) if you have minting permissions
74
-
* Acquire tokens through a supported exchange or transfer
69
+
You need onchain `SuperchainERC20` tokens.
70
+
You can [deploy your own token](./deploy-superchain-erc20), but in this tutorial we will use [`CustomSuperchainToken`](https://sid.testnet.routescan.io/address/0xF3Ce0794cB4Ef75A902e07e5D2b75E4D71495ee8), existing `SuperchainERC20` token on the [Interop devnet](../tools/devnet).
75
71
76
-
### Initiate the transfer
72
+
1. Create environment variables for the RPC endpoints for the blockchains and the token address.
The transfer isn't complete until the message is successfully relayed on the destination chain. See the [technical reference guide](/stack/interop/tutorials/relay-messages-viem) for specific relay instructions.
96
-
</Callout>
94
+
1. Wait a few minutes until you can see the ETH [on the block explorer](https://sid.testnet.routescan.io/) for your address.
1. Check your token balance on the destination chain
103
-
2. Confirm the transferred amount matches what you sent
104
-
3. The tokens should now be available for use on the destination chain
105
-
</Steps>
105
+
1. Obtain tokens on Interop devnet 0.
106
+
When using `CustomSuperchainToken` there are two ways to do this:
107
+
108
+
- Use the [block explorer](https://sid.testnet.routescan.io/address/0xF3Ce0794cB4Ef75A902e07e5D2b75E4D71495ee8/contract/420120000/writeContract?chainid=420120000) and a browser wallet to run the [faucet](https://sid.testnet.routescan.io/address/0xF3Ce0794cB4Ef75A902e07e5D2b75E4D71495ee8/contract/420120000/writeContract?chainid=420120000#F6) function.
For detailed technical instructions including contract addresses, specific commands, and message relaying details, refer to our [technical reference guide](/stack/interop/tutorials/relay-messages-viem).
*[viem bindings/actions](/stack/interop/tutorials/relay-messages-viem) for TypeScript integration
128
+
### Transfer tokens using TypeScript
129
+
130
+
We are going to use a [Node](https://nodejs.org/en) project, to be able to use [`@eth-optimism/viem`](https://www.npmjs.com/package/@eth-optimism/viem) to send the executing message.
131
+
We use [TypeScript](https://www.typescriptlang.org/) to have type safety combined with JavaScript functionality.
Use `@eth-optimism/viem`'s `walletActionsL2().sendSuperchainERC20` to send the `SuperchainERC20` tokens.
181
+
Internally, this function calls [`SuperchainTokenBridge.sendERC20`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/SuperchainTokenBridge.sol#L52-L78) to send the tokens.
This is how you use `@eth-optimism/viem` to create an executing message.
199
+
200
+
</details>
201
+
202
+
1. Run the TypeScript program, and see the change in your `CustomSuperchainToken` balances.
203
+
204
+
```sh
205
+
npm start
206
+
```
207
+
208
+
</Steps>
114
209
115
210
## Next steps
116
211
117
212
* 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).
213
+
* Learn [how this works](/stack/interop/superchain-erc20).
118
214
* Use [Supersim](/app-developers/tools/supersim), a local dev environment that simulates Superchain interop for testing applications against a local version of the Superchain.
0 commit comments