Transfer and Query Balances
January 27, 2022 ยท View on GitHub
Transfer: NetworkA > NetworkB
Let's transfer some tokens from NetworkA (ETH) to NetworkB (CELO).
Approve Tokens For Transfer
First, we must approve the ERC20 contract address to allow for a specified amount of token to be transferred by the provided recipient address.
In this case, we're going to be approving 100 tokens to be transferred by the ERC20 handler contract.
Flags: 1. recipient: the ERC20 Handler contract from the deployed contract table 2. erc20address: the ERC20 contract from the deployed contract table
./chainbridge-core-example \
evm-cli \
erc20 \
approve \
--url $NODE_ENDPOINT_NETWORK_A \
--privateKey $BRIDGE_ADMIN_PRIVATE_KEY \
--erc20Address $ERC_20_ADDRESS \
--amount 100 \
--recipient 0x0 \
--decimals 18
Transfer Tokens
In this step, we're going to be transferring 1 ERC20 token.
Flags: 1. bridge: the bridge contract from the deployed contract table 2. recipient: the address to receive the tokens 3. resourceId: the resource ID from the deployed contract table
./chainbridge-core-example \
evm-cli \
erc20 \
deposit \
--url $NODE_ENDPOINT_NETWORK_A \
--privateKey $BRIDGE_ADMIN_PRIVATE_KEY \
--bridge $BRIDGE_ADDRESS \
--recipient 0x0 \
--amount 1 \
--domainId 0 \
--resourceId $RESOURCE_ID \
--decimals 18
Transfer: NetworkB > NetworkA
Let's transfer some tokens from NetworkB (CELO) to NetworkA (ETH).
Approve Tokens For Transfer
Just as in the above case, we must approve the ERC20 contract address to allow for a specified amount of token to be transferred by the provided recipient address.
We're going to be approving 100 tokens to be transferred by the ERC20 handler contract.
Flags: 1. recipient: the ERC20 Handler contract from the deployed contract table 2. erc20address: the ERC20 contract from the deployed contract table
./chainbridge-core-example \
celo-cli \
erc20 \
approve \
--url $NODE_ENDPOINT_NETWORK_B \
--privateKey $BRIDGE_ADMIN_PRIVATE_KEY \
--erc20Address $ERC_20_ADDRESS \
--amount 100 \
--recipient 0x0 \
--decimals 18
Transfer Tokens
In this step, we're going to be transferring 100 ERC20 tokens.
Flags: 1. bridge: the bridge contract from the deployed contract table 2. recipient: the address to receive the tokens 3. resourceId: the resource ID from the deployed contract table
./chainbridge-core-example \
celo-cli \
erc20 \
deposit \
--url $NODE_ENDPOINT_NETWORK_B \
--privateKey $BRIDGE_ADMIN_PRIVATE_KEY \
--bridge $BRIDGE_ADDRESS \
--recipient 0x0 \
--amount 100 \
--domainId 1 \
--resourceId $RESOURCE_ID \
--decimals 18
Query Balances
Query balance of an account from an ERC20 contract.
NetworkA
In this step we'll query the specific ERC20 token balance of an Ethereum address on NetworkA.
Flags: 1. erc20address: the ERC20 contract from the deployed contract table 2. accountAddress: the address who's balance we wish to know
./chainbridge-core-example \
evm-cli \
erc20 \
balance \
--url $NODE_ENDPOINT_NETWORK_A \
--erc20Address $ERC_20_ADDRESS \
--accountAddress 0x284D2Cb760D5A952f9Ea61fd3179F98a2CbF0B3E
NetworkB
Now, we'll query the specific ERC20 token balance of an Ethereum address on NetworkB.
Flags: 1. erc20address: the ERC20 contract from the deployed contract table 2. accountAddress: the address who's balance we wish to know
./chainbridge-core-example \
celo-cli \
erc20 \
balance \
--url $NODE_ENDPOINT_NETWORK_B \
--erc20Address $ERC_20_ADDRESS \
--accountAddress 0x284D2Cb760D5A952f9Ea61fd3179F98a2CbF0B3E