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:
Wallet Connection
Quote Retrieval
Transaction Creation
Step-by-Step Execution
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.
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).
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.
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.
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
For browser implementation:
Make sure Phantom wallet extension is installed
Handle wallet connection states and user interactions appropriately
For NodeJS implementation:
Ensure you have the required environment variables (SOLANA_PRIVATE_KEY, RPC_URL)
Handle errors and cleanup appropriately
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
let requestParams = {
fromChainId: "sol", // Source blockchain network ID (Solana), for chain IDs reference: "/chains" api endpoint
toChainId: "137", // Destination blockchain network ID (Solana), for chain IDs reference: "/chains" api endpoint
fromAssetAddress: "So11111111111111111111111111111111111111112", // Source token contract address, for token addresses reference: "/tokens" api endpoint
toAssetAddress: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", // Destination token contract address, for token addresses reference: "/tokens" api endpoint
inputAmountDisplay: "0.1", // Amount of source token(Solana) to bridge, this is the amount that will be transferred from the source token chain to the destination token chain, typically received as input from the user
userWalletAddress: "4sd..", // User's wallet address
recipient: "0x..", // Recipient's wallet address
};
GET /quotes?fromChainId=sol&toChainId=137&fromAssetAddress=So11111111111111111111111111111111111111112&toAssetAddress=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&inputAmountDisplay=0.1&userWalletAddress=4sd..&recipient=0x..
let requestParams = {
routeId: quoteResponse.data.quotes[0].routeId, // routeId is available in the selected quote response
stepId: createTxResponse.data.steps[0].stepId, // stepId is available in the createTx steps[] response
};
GET /nextTx?routeId=a1b2c3d4-e5f6-g7h8-i9j0&stepId=step_12345
let requestParams = {
routeId: quoteResponse.data.quotes[0].routeId, // routeId is available in the selected quote response
stepId: createTxResponse.data.steps[0].stepId, // stepId is available in the createTx steps[] response
txnHash: nextTxResponse.data.txnData.txnSol.hash, // pass the txnHash that is received from the wallet provider once the transaction is signed successfully by the user
};
GET /status?routeId=a1b2c3d4-e5f6-g7h8-i9j0&stepId=step_12345&txnHash=0x1234...abcd