Token Bridge

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.

AIN ERC20 Token Addresses

AIN Native Token Pool Addresses

Check-in

Here, a check-in refers to a transfer of your AIN ERC20 tokens on Ethereum to AI Network as AIN native coins.

1. Send your AIN ERC20 tokens to the AI Network ERC20 Token Pool address.

1-1. Using a MetaMask, Add AIN ERC20 Token to your list of tokens.

1-2. Send AIN ERC20 to AI Network ERC20 Token Pool.

AI Network ERC20 Token Pool address

⚠️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! */
const stringify = require('fast-json-stable-stringify');
const Accounts = require('web3-eth-accounts');
const Ain = require('@ainblockchain/ain-js').default;
const ain = new Ain('https://mainnet-api.ainetwork.ai', 1); // chainId = 1 (mainnet)
const ethAccounts = new Accounts();
const ainErc20TokenAddress = '0x3A810ff7211b40c4fA76205a14efe161615d0385';

// Create 1 new account
const accounts = 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));
const myAddress = 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)
const timestamp = Date.now();
const ref = `/checkin/requests/ETH/1/${ainErc20TokenAddress}/${myAddress}/${timestamp}`;
// Should be exactly the same as the AIN ERC20 token you sent in Step 1-2.
const amount = 20000;
// Sender is the Ethereum address that you used to send AIN ERC20 token in Step 1-2.
const sender = 'YOUR-ETHEREUM-ADDRESS';
const senderPrivateKey = 'YOUR-ETHEREUM-PRIVATE-KEY';
const senderProofBody = {
  ref,
  amount,
  sender,
  timestamp,
  nonce: -1,
};
const senderProof = ethAccounts.sign(ethAccounts.hashMessage(stringify(senderProofBody)), senderPrivateKey).signature;

// Send a check-in request
ain.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! */
const stringify = require('fast-json-stable-stringify');
const Accounts = require('web3-eth-accounts');
const Ain = require('@ainblockchain/ain-js').default;
const ain = new Ain('https://testnet-api.ainetwork.ai', 0); // chainId = 0 (testnet)
const ethAccounts = new Accounts();
const ainErc20TokenAddress = '0xB16c0C80a81f73204d454426fC413CAe455525A7';

// Create 1 new account
const accounts = 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));
const myAddress = 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)
const timestamp = Date.now();
const ref = `/checkin/requests/ETH/3/${ainErc20TokenAddress}/${myAddress}/${timestamp}`;
// Should be exactly the same as the AIN ERC20 token you sent in Step 1-2.
const amount = 20000;
// Sender is the Ethereum address that you used to send AIN ERC20 token in Step 1-2.
const sender = 'YOUR-ETHEREUM-ADDRESS';
const senderPrivateKey = 'YOUR-ETHEREUM-PRIVATE-KEY';
const senderProofBody = {
  ref,
  amount,
  sender,
  timestamp,
  nonce: -1,
};
const senderProof = ethAccounts.sign(ethAccounts.hashMessage(stringify(senderProofBody)), senderPrivateKey).signature;

// Send a check-in request
ain.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.

  • Mainnet: https://insight.ainetwork.ai/accounts/${YOUR-AIN-ADDRESS}

  • Testnet: https://testnet-insight.ainetwork.ai/accounts/${YOUR-AIN-ADDRESS}

Check-out

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! */
const Ain = require('@ainblockchain/ain-js').default;
const ain = new Ain('https://testnet-api.ainetwork.ai', 1); // chainId = 1 (mainnet)
const ainErc20TokenAddress = '0x3A810ff7211b40c4fA76205a14efe161615d0385';

// Import an account you created in the check-in process
const myAddress = ain.wallet.addAndSetDefaultAccount(YOUR_PRIVATE_KEY);

// Send a check-in request
const timestamp = Date.now();
const ref = `/checkout/requests/ETH/1/${ainErc20TokenAddress}/${myAddress}/${timestamp}`;
const amount = 10000;
// This is the Ethereum address that will receive the AIN ERC20 tokens
const recipient = '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! */
const Ain = require('@ainblockchain/ain-js').default;
const ain = new Ain('https://testnet-api.ainetwork.ai', 0); // chainId = 0 (testnet)
const ainErc20TokenAddress = '0xB16c0C80a81f73204d454426fC413CAe455525A7';

// Import an account you created in the check-in process
const myAddress = ain.wallet.addAndSetDefaultAccount(YOUR_PRIVATE_KEY);

// Send a check-in request
const timestamp = Date.now();
const ref = `/checkout/requests/ETH/3/${ainErc20TokenAddress}/${myAddress}/${timestamp}`;
const amount = 10000;
// This is the Ethereum address that will receive the AIN ERC20 tokens
const recipient = '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.

You can view your transaction at:

  • Mainnet: https://insight.ainetwork.ai/transactions/${txHash}

  • Testnet: https://testnet-insight.ainetwork.ai/transactions/${txHash}

3. Check that your Ethereum wallet has received AIN ERC20 tokens.

You can confirm your increased AIN ERC20 token balance on either MetaMask or Etherscan.

  • Mainnet: https://etherscan.io/address/${ethereumAddress}

  • Testnet: https://ropsten.etherscan.io/address/${ethereumAddress}

Last updated