Solana to EVM Bridge

This guide demonstrates how to execute a token bridge from solana network to EVM-compatible chains using the Compass API. The example covers the complete workflow from connecting a wallet to monitoring transaction status.

Overview

The implementation follows these key steps:

  1. Wallet Connection

  2. Quote Retrieval

  3. Transaction Creation

  4. Step-by-Step Execution

  5. Status Monitoring

Implementation Details

Prerequisites

  • Phantom or any solana compatible wallet

  • Integrator ID from Compass

  • Solana Web3.js library

API Endpoints

The example uses the following endpoints:

/quotes

This endpoint fetches quotes from available liquidity sources and responds with quotes that are sorted by best output amount by default. The first item in the quotes array is the recommended quote.

Request Parameters

Example Request

Example Response

View full quotes response

/createTx

This endpoint fetches the transaction steps for the selected quote . Since this is s solana to EVM bridge example, the transaction step includes bridge step. The response includes steps that need to be executed.The Step object includes a step ID and step type (bridge).

Request Parameters

Example Request

Example Response

View full createTx API response

/nextTx

This endpoint fetches the transaction data that needs to be executed for the selected step. The transaction data includes the transaction parameters for the step. Since this is an Solana to EVM bridge example, the transaction data includes the txnSol object field in the transaction data.

Note: The transaction data is specific to the step type. For example, if the step type is bridge, the transaction data includes the bridge parameters. Moreover, the next step data will be available only if the previous step is executed successfully.

Request Parameters

Example Request

Example Response

View full nextTx API response

/status

This endpoint fetches the transaction status for the selected step once the transaction step is submitted to the blockchain. The transaction status includes: the status of the transaction, the source transaction hash, the source transaction URL, the destination transaction hash, the destination transaction URL, the output amount received, and the output token details.

View full status API documentation

Transaction Status Codes

  • in-progress: Transaction is pending

  • success: Transaction completed successfully

  • partial-success: If output amount token is different from the destination token, the transaction is partial success.

  • failed: Transaction failed

Request Parameters

Example Request

Example Response

Code Example

In the code example below, we use plain JavaScript for simplicity, but the code is framework-agnostic and can be easily adapted to React, Next.js, Vite, or any other JavaScript framework. Simply modify the syntax and component structure to match your chosen framework's conventions.

NodeJS Implementation

Browser Implementation with Phantom Wallet

Common Implementation

Usage Notes

  1. For browser implementation:

    • Make sure Phantom wallet extension is installed

    • Handle wallet connection states and user interactions appropriately

  2. For NodeJS implementation:

    • Ensure you have the required environment variables (SOLANA_PRIVATE_KEY, RPC_URL)

    • Handle errors and cleanup appropriately

  3. Common considerations:

    • Replace 'your-integrator-id' with your actual integrator ID

    • Implement proper error handling and loading states

    • Add appropriate UI feedback for transaction status

Last updated

Was this helpful?