Skip to main content

Client Example

Basic implementation steps for building a cross-chain bridge using the Metalayer client directly.

1. Initialize Client

Set up the Metalayer client with your API key to access bridge functionality.

2. Get Supported Chains

Fetch available chains to determine valid bridge routes for your application.

3. Get Tokens

Retrieve token information for the chains you want to support in your bridge interface.

4. Request Quote

Get bridge quotes based on user selections to show routing options and fees.

5. Execute Transaction

Execute the bridge transaction by processing each step in the quote with your wallet client.

6. Monitor Status

Track the bridge transaction progress to provide status updates to users.

React Hook Example

Basic implementation steps for building a cross-chain bridge using Metalayer SDK hooks. For detailed hook configuration and provider setup, see Hooks.

1. Get Supported Chains

Fetch the list of supported chains to populate source and destination chain selectors in your UI. This data enables users to choose which networks they want to bridge between.

2. Get Tokens

Retrieve available tokens organized by chain to build token selection lists. Use this data to create filtered token dropdowns that update based on the user’s selected source and destination chains.

3. Get Quote

Request bridge quotes based on user selections from your UI. This provides routing options, fees, and estimated completion times for the bridge transaction.

4. Execute Transaction

Execute the bridge transaction using the selected quote. This typically involves multiple steps like token approvals followed by the actual bridge transaction, with each step requiring user wallet confirmation.

5. Monitor Status

Track the bridge transaction progress to provide real-time status updates to users. Use this to display progress indicators, completion confirmations, or error states in your UI.