# Interact with the frontend · Chromia Docs (concept)

> This section guides you through configuring and running the frontend for the Chromia Bridge Demo.

Source: https://docs.chromia.com/ecosystem/bridge/deploy-bridge/interact-with-frontend/

# Interact with the frontend

On this page

* [Prerequisites](#prerequisites)
* [Navigate to the frontend folder](#navigate-to-the-frontend-folder)
* [Set up the frontend configuration file](#set-up-the-frontend-configuration-file)
* [Install dependencies](#install-dependencies)
* [Start the frontend app](#start-the-frontend-app)
* [Import the token into MetaMask](#import-the-token-into-metamask)
* [Verify your test token balance](#verify-your-test-token-balance)
* [Initialize FT4 account](#initialize-ft4-account)
* [Approve token spending](#approve-token-spending)
* [Bridge tokens from EVM to Chromia](#bridge-tokens-from-evm-to-chromia)
* [Set up shell environment variables for easier queries](#set-up-shell-environment-variables-for-easier-queries)
* [Verify token transfer](#verify-token-transfer)
* [Bridge tokens back to EVM](#bridge-tokens-back-to-evm)

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](https://docs.chromia.com/get-started/installation/)**
* **[Node.js](https://nodejs.org/)**
* **[MetaMask](https://metamask.io/)** or a compatible wallet.
* **[Chromia Bridge Demo repository](https://bitbucket.org/chromawallet/chromia-bridge-demo/src/main/)**

If you haven't cloned the repository yet, run:

Terminal

```
git clone https://bitbucket.org/chromawallet/chromia-bridge-demo.git
```

To obtain the `<BRIDGE_DEMO_BRID>` for the Chromia bridge component:

* If you **[deployed](https://docs.chromia.com/ecosystem/bridge/deploy-bridge/deploy-bridge-chains/)** the bridge, this is the BRID assigned during deployment.
* If you **[leased](https://docs.chromia.com/ecosystem/bridge/bridge-lease/)** a bridge, you should have received this information.

note

If you're using the Economy Chain Bridge, use the [Economy BRID](https://explorer.chromia.com/mainnet/15C0CA99BEE60A3B23829968771C50E491BD00D2E3AE448580CD48A8D71E7BBA)
and the corresponding EVM-side contract addresses. For assistance, contact the Chromia support team.

## 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:

Terminal

```
cd chromia-bridge-demo/bridgefrontend
```

## Set up the frontend configuration file

Create a `.env` file:

Terminal

```
cp .env.example .env
```

Next, edit the `.env` file with the required values:

INI

```
VITE_BRID=<BRIDGE_DEMO_BRID>
VITE_BRIDGE_ADDRESS=0x<YOUR_BRIDGE_EVM_ADDRESS>
VITE_TOKEN_ADDRESS=0x<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:

Terminal

```
npm install
```

## Start the frontend app

Launch the development server with the command:

Terminal

```
npm run dev
```

![Bridge demo frontend running](https://docs.chromia.com/img/bridge_demo_frontend.png)

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.

1. Open MetaMask and **ensure you are on the BSC Testnet.**
2. Click on **Import Token**.
3. Enter the **token contract address**: `<YOUR_TOKEN_EVM_ADDRESS>`.
4. 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.

![Bridge demo UI](https://docs.chromia.com/img/bridge_demo_ui.png)

## Initialize FT4 account

1. Click **Setup** to create an FT4 account linked to your EVM account.
2. If the page reloads, click **Login**.

note

This frontend demo does not save its internal state or track transactions as a production environment would. If you
refresh the page, it will lose all information about ongoing transactions.

However, you can still bridge tokens again after a reload; just start a new flow from the beginning.

## Approve token spending

info

The **test ALICE token contract** has **18 decimal places**, meaning **3000 tokens** must be entered as:

Terminal

```
3000000000000000000000
```

1. Enter the value needed to approve **spending 3000 tokens**.
2. Click **Approve spending of 3e+21 tokens by the Bridge**.
3. Confirm the action in MetaMask.

## Bridge tokens from EVM to Chromia

1. To bridge **3000 tokens**, enter the following value:

   Terminal

   ```
   3000000000000000000000
   ```
2. Click **Bridge 3e+21 tokens to Chromia**.
3. 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:

Terminal

```
export NODE=https://node0.testnet.chromia.com
```

Terminal

```
export ER=<EVENT_RECEIVER_BRID>
```

Terminal

```
export BRIDGE=<BRIDGE_DEMO_BRID>
```

* **`NODE`**: The URL of the Chromia node that handles transactions and queries.
* **`ER`**: The RID of the `event_receiver` blockchain, which tracks token deposits and withdrawals.
* **`BRIDGE`**: The RID of the `bridge` blockchain, which manages token bridging between Chromia and EVM.

## Verify token transfer

1. Ensure that **3000 tokens have been deducted** from your MetaMask balance.
2. Check the latest deposits on Chromia by running:

   Terminal

   ```
   chr query --api-url $NODE -brid $BRIDGE eif.hbridge.get_erc20_deposits filter=[null,null,null,null,null] page_size=null page_cursor=null
   ```
3. Check your FT4 account balance. Use the values retrieved from the previous step to complete the following command:

   Terminal

   ```
   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

1. To bridge **1500 tokens** back, enter the following value:

   Terminal

   ```
   1500000000000000000000
   ```
2. Click **Bridge 1.5e+21 tokens to EVM** and confirm the action in MetaMask.
3. Check for the withdrawal event by running:

   Terminal

   ```
   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
   ```
4. Click **Request Withdraw from EVM** and confirm the transaction in MetaMask.
5. Click **Withdraw from bridge** and confirm with MetaMask.
6. 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.

[View this page on docs.chromia.com](https://docs.chromia.com/ecosystem/bridge/deploy-bridge/interact-with-frontend/)Content mirrored from the live docs
