👉How to roll in tokens

ERC20 tokens

The most outstanding advantage of Cycle is that it allows assets from multiple chains to be deposited into Cycle, which is named Rollin in our scenario. The most common scene is rolling erc20 tokens to Cycle, which is supported by SDK. Here we show an example of how to rollin ERC20 token from Sepolia to Cycle.

async function getZkEvmClient(
    privateKey: string,
    userAddress: string,
    network: string = 'testnet',
    version: string = 'starfish'
) {
    const zkEvmClient = new ZkEvmClient()
    return zkEvmClient.init({
        log: true,
        network,
        version,
        child: {
          name: 'cycle',
          provider: new HDWalletProvider(privateKey, RPC_CYCLE),
          defaultConfig: {
            from: userAddress,
          },
        },
        parent: {
          name: 'sepolia',
          provider: new HDWalletProvider(privateKey, RPC_SEPOLIA),
          defaultConfig: {
            from: userAddress,
          },
        },
    })
}

async function rollin(
    tokenId: number,
    amount: BigNumberish,
    receiverAddress: string
) {
    const client = await getZkEvmClient()
    const erc20Token = client.customERC20(tokenId, true)
    const result = await erc20Token.deposit(amount, receiverAddress)
    const txHash = await result.getTransactionHash()
    const receipt = await result.getReceipt()
}

Currently, we only have a test ERC20 token named 'CYCLE' used to present Cycle's capacity of all-chain assets management whose tokenId is 1. Soon we will have more origin tokens issued on Cycle and wrap tokens whose original tokens are already issued on Security Layer/Extend Layers.

Soon, we will provide a query-API listing all the tokens' information including token address and token id.

When a new kind of ERC20 token is rolling-in from the origin layer to Cycle for the first time, the rollin smart contract will automatically deploy a wrapped ERC20 token contract that corresponds to the origin token deployed on the origin layer.

Last updated