Interact with the frontend
This section guides you through configuring and running the frontend for the Chromia Bridge Demo.
Prerequisites
Before proceeding, ensure you have the following:
- Chromia CLI
- Node.js
- MetaMask or a compatible wallet.
- Chromia Bridge Demo repository
If you haven't cloned the repository yet, run:
git clone https://bitbucket.org/chromawallet/chromia-bridge-demo.git
To obtain the <BRIDGE_DEMO_BRID>
for the Chromia bridge component:
- If you deployed the bridge, this is the BRID assigned during deployment.
- If you leased a bridge, you should have received this information.
Navigate to the frontend folder
The following steps require you to be inside the chromia-bridge-demo/bridgefrontend
folder.
Ensure you are in the correct directory:
cd chromia-bridge-demo/bridgefrontend
Set up the frontend configuration file
Create a .env
file:
cp .env.example .env
Next, edit the .env
file with the required values:
VITE_BRID=<BRIDGE_DEMO_BRID>
VITE_BRIDGE_ADDRESS=<YOUR_BRIDGE_EVM_ADDRESS>
VITE_TOKEN_ADDRESS=<YOUR_TOKEN_EVM_ADDRESS>
<BRIDGE_DEMO_BRID>
: The RID of the Chromia bridge component.<YOUR_BRIDGE_EVM_ADDRESS>
: The deployed EVM bridge contract address.<YOUR_TOKEN_EVM_ADDRESS>
: The ERC20 token contract address.
Install dependencies
Run the following command to install the necessary dependencies:
npm install
Start the frontend app
Launch the development server with the command:
npm run dev
The app will be accessible at http://localhost:5173.
Import the token into MetaMask
Before interacting with the bridge, you must import the test token into MetaMask (or your preferred wallet) to track your balances.
- Open MetaMask and ensure you are on the BSC Testnet.
- Click on Import Token.
- Enter the token contract address:
<YOUR_TOKEN_EVM_ADDRESS>
. - Click Next and confirm the import.
Verify your test token balance
- If you deployed the ALICE test token, your balance should start at 100,000 ALICE.
- If you are using a different test token, check the initial minting rules for that contract.
After verifying your balance, you can proceed to account setup.
Initialize FT4 account
- Click Setup to create an FT4 account linked to your EVM account.
- If the page reloads, click Login.
Approve token spending
The test ALICE token contract has 18 decimal places, meaning 3000 tokens must be entered as:
3000000000000000000000
- Enter the value needed to approve spending 3000 tokens.
- Click Approve spending of 3e+21 tokens by the Bridge.
- Confirm the action in MetaMask.
Bridge tokens from EVM to Chromia
- To bridge 3000 tokens, enter the following value:
3000000000000000000000
- Click Bridge 3e+21 tokens to Chromia.
- Confirm the transaction in MetaMask.
Set up shell environment variables for easier queries
To avoid copy-pasting the blockchain RIDs each time, set them once before running queries:
export NODE=https://node0.testnet.chromia.com:7740
export ER=<EVENT_RECEIVER_BRID>
export BRIDGE=<BRIDGE_DEMO_BRID>
NODE
: The URL of the Chromia node that handles transactions and queries.ER
: The RID of theevent_receiver
blockchain, which tracks token deposits and withdrawals.BRIDGE
: The RID of thebridge
blockchain, which manages token bridging between Chromia and EVM.
Verify token transfer
- Ensure that 3000 tokens have been deducted from your MetaMask balance.
- Check the latest deposits on Chromia by running:
chr query --api-url $NODE -brid $BRIDGE eif.hbridge.get_erc20_deposits filter=[null,null,null,null,null] page_size=null page_cursor=null
- Check your FT4 account balance. Use the values retrieved from the previous step to complete the following command:
chr query --api-url $NODE -brid $BRIDGE ft4.get_asset_balance account_id=<YOUR_ACCOUNT_ID> asset_id=<YOUR_ASSET_ID>
Bridge tokens back to EVM
- To bridge 1500 tokens back, enter the following value:
1500000000000000000000
- Click Bridge 1.5e+21 tokens to EVM and confirm the action in MetaMask.
- Check for the withdrawal event by running:
chr query --api-url $NODE -brid $BRIDGE eif.hbridge.get_erc20_withdrawals filter=[null,null,null,null,null,null,null] page_size=null page_cursor=null
- Click Request Withdraw from EVM and confirm the transaction in MetaMask.
- Click Withdraw from bridge and confirm with MetaMask.
- Open MetaMask and verify that 1500 tokens have been restored to your balance.
You have now successfully set up and configured the Chromia Bridge Demo to transfer tokens between the EVM and Chromia networks.