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()
}