Skip to content

Latest commit

 

History

History
201 lines (145 loc) · 8 KB

deploy-superchain-erc20.mdx

File metadata and controls

201 lines (145 loc) · 8 KB
title description lang content_type topic personas categories is_imported_content
Deploying a SuperchainERC20
Learn about the basic details of deploying assets on SuperchainERC20
en-US
tutorial
deploying-a-superchainerc20
protocol-developer
chain-operator
app-developer
interoperable-assets
interoperability
cross-chain-messaging
superchain-erc20
token-standard
token-deployment
smart-contracts
superchain
false

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

The SuperchainERC20 standard is ready for production deployments. However, the OP Stack interoperability upgrade, required for crosschain messaging, is currently still in active development.

Deploying a SuperchainERC20

Overview

This guide explains how to issue new assets with the SuperchainERC20 contract. Those assets can then be bridged quickly and safely using the SuperchainTokenBridge contract (once interop is operational). For more information on how it works, see the explainer.

Note that bridging assets through the Superchain using SuperchainTokenBridge never affects the total supply of your asset. The supply remains fixed, bridging only changes the chain on which the asset is located. The token's total amount across all networks always remains the same, ensuring value stability.

To ensure fungibility across chains, SuperchainERC20 assets must have the same contract address on all chains. This requirement abstracts away the complexity of cross-chain validation. Achieving this requires deterministic deployment methods. There are multiple ways to do this. Here we will use the SuperchainERC20 Starter Kit.

This tutorial teaches you how to deploy a *new* `SuperchainERC20`. If you're looking to migrate an existing ERC20 visit [this tutorial](./upgrade-to-superchain-erc20).

What you'll do

What you'll learn

  • How to deploy SuperchainERC20 tokens on different chains at the same address.

Prerequisites

Before starting this tutorial, ensure your development environment meets the following requirements:

Technical knowledge

  • Understanding of smart contract development
  • Familiarity with blockchain concepts

Development environment

  • Unix-like operating system (Linux, macOS, or WSL for Windows)
  • Git for version control

Required tools

The tutorial uses these primary tools:

  • Foundry: For sending transactions to blockchains.

Step by step explanation

### Install the prerequisites and the SuperchainERC20 Starter Kit

Follow the setup steps in the SuperchainERC20 Starter Kit.

Prepare for deployment

The Starter Kit already deploys a SuperchainERC20 token to Supersim. Here we will deploy it to the Interop devnet.

  1. Edit packages/contracts/foundry.toml to add the RPC endpoints for the devnet (add the bottom two rows).

    [rpc_endpoints]
    op_chain_a = "http://127.0.0.1:9545"
    op_chain_b = "http://127.0.0.1:9546"
    devnet0 = "https://interop-alpha-0.optimism.io"
    devnet1 = "https://interop-alpha-1.optimism.io"

    You can import most RPC endpoints with this command, but it does not include the Interop devnet.

    pnpm contracts:update:rpcs
  2. Edit packages/contracts/configs/deploy-config.toml for the deployment settings.

    • Set these parameters in the [deploy-config] section:

      Parameter Meaning Example
      salt A unique identifier Carthage
      chains The chains to deploy the contract1 ["devnet0","devnet1"]

      (1) These names must correspond to the chain names in the [rpc-endpoints] section of foundry.toml you updated in the previous step.

    • Set these parameters in the [token] section:

      Parameter Meaning Example
      owner_address Owner of the token Your address1
      name Token name Quick Transfer Token
      symbol Token symbol QTT
      decimals Number of decimal places 18

      (1) This should be an address you control (for which you know the private key), which has some ETH on the devnets. See here to add ETH to the devnets.

    Here is a sample packages/contracts/configs/deploy-config.toml file you can use, as long as you update owner_address.

    [deploy_config]
    salt = "is the source of our word salary"
    chains = ["devnet0","devnet1"]
    
    [token]
    owner_address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
    name = "Quick Transfer Token"
    symbol = "QTT"
    decimals = 18
  3. Set the private key. Edit packages/contracts/.env to set DEPLOYER_PRIVATE_KEY to the private key of an account that has ETH on both devnet blockchains.

    DEPLOYER_PRIVATE_KEY= <<<private key goes here>>>

Deploy the contracts

Run the deployment script.

pnpm contracts:deploy:token
Sanity check
1.  Set `TOKEN_ADDRESS` to the address where the token is deployed.

    ```sh
    TOKEN_ADDRESS=0x322f4aF25D370BE2A2C74eEFf0DD0d2AF2e7eD75
    ```

2.  Set `PRIVATE_KEY` to the private key for the owner address.

    ```sh
    PRIVATE_KEY= <<<private key goes here>>>
    ```

3.  Mint tokens for an address you control on both chains.
    The owner address is the easiest to use.

    ```sh
    OWNER_ADDRESS=`cast wallet address --private-key $PRIVATE_KEY`
    RPC_DEV0=https://interop-alpha-0.optimism.io
    RPC_DEV1=https://interop-alpha-1.optimism.io
    cast send --private-key $PRIVATE_KEY $TOKEN_ADDRESS "mintTo(address,uint256)" $OWNER_ADDRESS 1000 --rpc-url $RPC_DEV0
    cast send --private-key $PRIVATE_KEY $TOKEN_ADDRESS "mintTo(address,uint256)" $OWNER_ADDRESS 2000 --rpc-url $RPC_DEV1       
    ```

4.  Check the balance of the owner address on both blockchains.

    ```sh
    cast call $TOKEN_ADDRESS "balanceOf(address)" $OWNER_ADDRESS --rpc-url $RPC_DEV0 | cast to-dec        
    cast call $TOKEN_ADDRESS "balanceOf(address)" $OWNER_ADDRESS --rpc-url $RPC_DEV1 | cast to-dec
    ```

Next steps