Transfer Gateway Tutorial
Overview
In this doc, we'll walk you through the setup required to transfer tokens between token contracts you've deployed to Extdev Testnet and Rinkeby. If you haven't done so already you should first read through the high-level overview of the Transfer Gateway.
#1. Deploy Token Contracts to Extdev Testnet
If you wish to transfer tokens from a token contract deployed on Rinkeby to one that's deployed on Extdev, you'll need to ensure that the token contract you deploy to Extdev implements the mintToGateway
function. We've created some sample contracts and a simple CLI to interact with them.
#MyToken ERC721 Contract
#MyCoin ERC20 Contract
Full source for all contracts can be found in the Truffle DAppChain Example repo.
Download the
zeknd
binary, while you won't be spinning up your own DAppChain in this tutorial, you will be using some of the CLI commands built into thezeknd
binary to interact with Extdev.Make sure you have
node
(v8 or later) andyarn
installed.Clone the Truffle DAppChain Example repo.
Generate your own private key for deploying and calling contracts on Extdev.
You should see something similar to this displayed in the console:
This is the public address that corresponds to your new private key. You'll find the private key in the
extdev_private_key
file, and the corresponding public key in theextdev_public_key
file.Deploy the
MyToken
andMyCoin
contracts toextdev
.
#2. Deploy Token Contracts to Rinkeby
There aren't any special requirements for token contracts deployed to Ethereum networks.
#MyRinkebyToken ERC721 Contract
#MyRinkebyCoin ERC20 Contract
Full source for all contracts can be found in the Truffle DAppChain Example repo.
Let's deploy these contracts to Rinkeby.
Generate an Ethereum private key:
Get the address of the new Rinkeby account from the
rinkeby_account
file:Give the Rinkeby account some ETH so it can be used to deploy contracts to Rinkeby. You can either use https://faucet.rinkeby.io or transfer some ETH from another account.
Set your Infura API key (get it from https://infura.io):
Deploy the sample contracts:
If this fails with an error similar to this one:
Transfer a bit more ETH to your Rinkeby account.
#3. Map Extdev Contracts to Rinkeby Contracts
Once you've deployed your contracts to both chains you'll need to let the Transfer Gateway know you want it to transfer tokens between the contracts. You can either do so programmatically using the TransferGateway
class in zekn
-js, or the zeknd
CLI. For this tutorial we've built a more streamlined JS CLI with web3
and zekn
-js, so you don't have to go looking for contract addresses, transaction hashes, and sacrificial goats.
Map the MyToken
contract deployed on Extdev to the MyRinkebyToken
contract deployed on Rinkeby:
Map the MyCoin
contract deployed on Extdev to the MyRinkebyCoin
contract deployed on Rinkeby:
After you execute these commands the Transfer Gateway will attempt to verify that you are the creator of these contracts. Note that this may take a couple of minutes. In the meantime, you can proceed to the next step.
#4. Map Extdev Account to Rinkeby Account
Now that the two token contracts are connected via the Transfer Gateway you can start transferring tokens from Extdev to Rinkeby. However, if you want to transfer tokens from Rinkeby to Extdev, you'll need to connect your Extdev account to your Rinkeby account.
Great, everything should now be ready for flawless token transfer between Extdev and Rinkeby!
#5. Transfer Tokens
#From Rinkeby to Extdev
Now that all contracts and accounts have been mapped you can transfer tokens and ETH to the Rinkeby Gateway contract.
Let's start by minting some of the MyRinkebyToken
ERC721 tokens, and transferring one of them to Extdev:
And now let's transfer some of the MyRinkebyCoin
ERC20 tokens. Note that a billion of them have already been minted to your account so you can transfer them right away.
#From Extdev to Rinkeby
The ERC721 tokens can be transferred back to Rinkeby using the withdraw-token
command:
The ERC20 tokens can be transferred back to Rinkeby using the withdraw-coin
command:
#Troubleshooting
Sometimes the withdrawal process may error out due to network issues or because gas ran out. If that happens, you can try to complete the interrupted withdrawal using the resume-withdrawal
command.
NOTE: Only one pending withdrawal is allowed per user.
Last updated