AI Network operates a token bridge between AIN native coins and AIN ERC20 tokens on Ethereum. Disclaimer: Check-in and check-out requests may take a few days to be processed.
Note: This guide assumes that you have an Ethereum wallet with some AIN ERC20 tokens in it. You can buy AIN ERC20 tokens on Uniswap, Balancer, or GOPAX.
⚠️Make sure you are on the right network (Ethereum Mainnet vs Ropsten Test Network) before sending your assets.
There is no minimum/maximum amount you need to check-in.
1-3. Make sure the transaction is successfully executed.
You can view your transaction on Etherscan by clicking the transaction on MetaMask and then "View on block explorer".
2. Send a check-in request transaction to the AI Network blockchain.
check-in-mainnet.js
/* This code snippet is for Mainnet! */conststringify=require('fast-json-stable-stringify');constAccounts=require('web3-eth-accounts');constAin=require('@ainblockchain/ain-js').default;constain=newAin('https://mainnet-api.ainetwork.ai',1); // chainId = 1 (mainnet)constethAccounts=newAccounts();constainErc20TokenAddress='0x3A810ff7211b40c4fA76205a14efe161615d0385';// Create 1 new accountconstaccounts=ain.wallet.create(1);// WARNING: Make sure to record this private key somewhere safe! We cannot retrieve it for you!console.log(JSON.stringify(ain.wallet.accounts,null,2));constmyAddress= accounts[0];ain.wallet.setDefaultAccount(myAddress);// Or, import an account you already have// const myAddress = ain.wallet.addAndSetDefaultAccount(YOUR_PRIVATE_KEY);// Create a sender proof with your Ethereum key (sender)consttimestamp=Date.now();constref=`/checkin/requests/ETH/1/${ainErc20TokenAddress}/${myAddress}/${timestamp}`;// Should be exactly the same as the AIN ERC20 token you sent in Step 1-2.constamount=20000;// Sender is the Ethereum address that you used to send AIN ERC20 token in Step 1-2.constsender='YOUR-ETHEREUM-ADDRESS';constsenderPrivateKey='YOUR-ETHEREUM-PRIVATE-KEY';constsenderProofBody= { ref, amount, sender, timestamp, nonce:-1,};constsenderProof=ethAccounts.sign(ethAccounts.hashMessage(stringify(senderProofBody)), senderPrivateKey).signature;// Send a check-in requestain.db.ref(ref).setValue({ value: { amount, sender: myAddress, sender_proof: senderProof, }, nonce:-1, gas_price:500, timestamp: timestamp // Should be the same as the checkinId in ref }).then((res) => {console.log(JSON.stringify(res,null,2)); });
check-in-testnet.js
/* This code snippet is for Testnet! */conststringify=require('fast-json-stable-stringify');constAccounts=require('web3-eth-accounts');constAin=require('@ainblockchain/ain-js').default;constain=newAin('https://testnet-api.ainetwork.ai',0); // chainId = 0 (testnet)constethAccounts=newAccounts();constainErc20TokenAddress='0xB16c0C80a81f73204d454426fC413CAe455525A7';// Create 1 new accountconstaccounts=ain.wallet.create(1);// WARNING: Make sure to record this private key somewhere safe! We cannot retrieve it for you!console.log(JSON.stringify(ain.wallet.accounts,null,2));constmyAddress= accounts[0];ain.wallet.setDefaultAccount(myAddress);// Or, import an account you already have// const myAddress = ain.wallet.addAndSetDefaultAccount(YOUR_PRIVATE_KEY);// Create a sender proof with your Ethereum key (sender)consttimestamp=Date.now();constref=`/checkin/requests/ETH/3/${ainErc20TokenAddress}/${myAddress}/${timestamp}`;// Should be exactly the same as the AIN ERC20 token you sent in Step 1-2.constamount=20000;// Sender is the Ethereum address that you used to send AIN ERC20 token in Step 1-2.constsender='YOUR-ETHEREUM-ADDRESS';constsenderPrivateKey='YOUR-ETHEREUM-PRIVATE-KEY';constsenderProofBody= { ref, amount, sender, timestamp, nonce:-1,};constsenderProof=ethAccounts.sign(ethAccounts.hashMessage(stringify(senderProofBody)), senderPrivateKey).signature;// Send a check-in requestain.db.ref(ref).setValue({ value: { amount, sender, sender_proof: senderProof, }, nonce:-1, gas_price:500, timestamp: timestamp // Should be the same as the checkinId in ref }).then((res) => {console.log(JSON.stringify(res,null,2)); });
3. Check that your AI Network account's balance has increased on Insight.
You can check your AI Network account's balance at the AI Network blockchain explorer.
Similarly, a check-out refers to a transfer of your AIN native coins on AI Network to Ethereum as AIN ERC20 tokens.
1. Send a check-out request transaction to the AI Network blockchain.
For check-out's, there is a minimum and a maximum allowed per request as well as a maximum per day for the entire network. Currently the limits are:
Minimum check-out amount per request: 10,000 AIN
Maximum check-out amount per request: 100,000 AIN
Maximum check-out amount per day for the network: 1,000,000 AIN
/* This code snippet is for Mainnet! */constAin=require('@ainblockchain/ain-js').default;constain=newAin('https://testnet-api.ainetwork.ai',1); // chainId = 1 (mainnet)constainErc20TokenAddress='0x3A810ff7211b40c4fA76205a14efe161615d0385';// Import an account you created in the check-in processconstmyAddress=ain.wallet.addAndSetDefaultAccount(YOUR_PRIVATE_KEY);// Send a check-in requestconsttimestamp=Date.now();constref=`/checkout/requests/ETH/1/${ainErc20TokenAddress}/${myAddress}/${timestamp}`;constamount=10000;// This is the Ethereum address that will receive the AIN ERC20 tokensconstrecipient='YOUR-ETHEREUM-ADDRESS';ain.db.ref(ref).setValue({ value: { amount, recipient, fee_rate:0.001 }, nonce:-1, gas_price:500, timestamp: timestamp // Should be the same as the checkoutId in ref }).then((res) => {console.log(JSON.stringify(res,null,2)); });
/* This code snippet is for Testnet! */constAin=require('@ainblockchain/ain-js').default;constain=newAin('https://testnet-api.ainetwork.ai',0); // chainId = 0 (testnet)constainErc20TokenAddress='0xB16c0C80a81f73204d454426fC413CAe455525A7';// Import an account you created in the check-in processconstmyAddress=ain.wallet.addAndSetDefaultAccount(YOUR_PRIVATE_KEY);// Send a check-in requestconsttimestamp=Date.now();constref=`/checkout/requests/ETH/3/${ainErc20TokenAddress}/${myAddress}/${timestamp}`;constamount=10000;// This is the Ethereum address that will receive the AIN ERC20 tokensconstrecipient='YOUR-ETHEREUM-ADDRESS';ain.db.ref(ref).setValue({ value: { amount, recipient, fee_rate:0.001 }, nonce:-1, gas_price:500, timestamp: timestamp,// Should be the same as the checkoutId in ref }).then((res) => {console.log(JSON.stringify(res,null,2)); });
2. Check that your transaction was successfully added to the blockchain on Insight.