Relayer for the cross-chain NFT bridge between Ethereum Virtual Machine (EVM) and Solana blockchain networks.
- Overview
- Architecture
- Flow
- Components
- Technical Implementation
- Configuration
- Installation Guide
- Development
- Security Considerations
- Troubleshooting
- FAQ
- License
Bridge-Relayer facilitates the transfer of NFTs between Solana and EVM-compatible blockchains. It is a service that listens for events on both chains and facilitates the transfer of assets between them.
The bridge consists of several components:
- API Server: Provides HTTP endpoints to initiate bridge transfers and query their status.
- Request Processor: Handles the lifecycle of bridge requests from initiation to completion.
- Solana Client: Monitors Solana blockchain for bridge events and processes token transfers from Solana.
- EVM Client: Monitors EVM-compatible blockchains for bridge events and processes token transfers from EVM chains.
- Storage: Persistent storage for bridge requests and their statuses.
- User initiates a transfer request via the API
- The bridge validates the request and locks the token on the source chain
- The bridge monitors for events confirming the token has been locked
- Once confirmed, the bridge mints the token on the destination chain
- Bridge monitors for events confirming the token’s creation.
- The request is marked as completed
- User calls
/bridge/solana-to-evm
endpoint with token mint, token account, and destination EVM address - Bridge creates a request and initiates a Solana transaction to lock the token
- Bridge listens for
NewRequestEvent
from the Solana program - When event is detected, bridge verifies token ownership and updates request status
- Bridge retrieves token metadata from Solana
- Bridge mints a new token on the EVM chain with the same metadata
- Bridge listens for
TokenMinted
event from the EVM contract - When event is detected, bridge updates request status to completed
- User calls
/bridge/evm-to-solana
endpoint with token contract, token ID, token owner, and destination Solana address - Bridge creates a request and initiates an EVM transaction to lock the token
- Bridge listens for
NewRequest
event from the EVM contract - When event is detected, bridge verifies token ownership and updates request status
- Bridge retrieves token metadata from EVM
- Bridge mints a new token on Solana with the same metadata
- Bridge listens for
TokenMintedEvent
from the Solana program - When event is detected, bridge updates request status to completed
Provides HTTP endpoints for interacting with the bridge:
/bridge/evm-to-solana
: Initiate a transfer from EVM to Solana/bridge/solana-to-evm
: Initiate a transfer from Solana to EVM/bridge/pending-requests
: Get a list of pending transfer requests/bridge/completed-requests
: Get a list of completed transfer requests/bridge/requests/{id}
: Get details about a specific request
For Solana to EVM transfers:
{
"token_mint": "Solana token mint address",
"token_account": "User's token account address",
"origin_network": "SOLANA",
"destination_account": "Destination EVM address"
}
For EVM to Solana transfers:
{
"token_contract": "EVM token contract address",
"token_id": "Token ID",
"token_owner": "Token owner's EVM address",
"origin_network": "EVM",
"destination_account": "Destination Solana address"
}
Handles interactions with the Solana blockchain:
- Monitors for bridge events using Solana's WebSocket API
- Processes token transfers from Solana to EVM
- Mints tokens on Solana when transferred from EVM
- Verifies token ownership and metadata
The bridge listens for two main events from the Solana program:
NewRequestEvent
: Triggered when a user initiates a transfer from SolanaTokenMintedEvent
: Triggered when a token is minted on Solana
Handles interactions with EVM-compatible blockchains:
- Monitors for bridge events using EVM's WebSocket API
- Processes token transfers from EVM to Solana
- Mints tokens on EVM when transferred from Solana
- Verifies token ownership and metadata
The bridge listens for two main events from the EVM contract:
NewRequest
: Triggered when a user initiates a transfer from EVMTokenMinted
: Triggered when a token is minted on EVM
Provides persistent storage for bridge requests and their statuses using RocksDB:
- Stores bridge requests with their current status
- Maintains lists of pending and completed requests
- Provides efficient lookup for request data
Manages the lifecycle of bridge requests:
- Creates new requests
- Updates request statuses
- Processes pending requests
- Handles error recovery for failed requests
A bridge request can be in one of the following states:
RequestReceived
: Initial state when a request is createdTokenReceived
: Token has been locked on the source chainTokenMinted
: Token has been minted on the destination chainCompleted
: Transfer has been completed successfullyCanceled
: Transfer has been canceled due to an error
Defines common data structures used throughout the bridge:
BRequest
: Bridge request data structureInputRequest
: Input data for creating a bridge requestStatus
: Enum representing the status of a bridge requestChains
: Enum representing the supported blockchainsTxMessage
: Message structure for inter-component communication
The bridge uses Tokio channels for communication between components:
tx_evm
andrx_evm
: Channels for sending messages to the EVM processortx_sol
andrx_sol
: Channels for sending messages to the Solana processor
The bridge uses Tokio for asynchronous processing:
- Each component runs in its own task
- Event listeners run continuously in the background
- Request processing is handled asynchronously
The bridge includes mechanisms for error handling and recovery:
- Failed requests are retried automatically
- Pending requests are processed on startup
- Requests can be canceled if they cannot be completed
The bridge is configured using environment variables:
DB_PATH
: Path to the RocksDB databasePORT
: API PortEVM_RPC
: RPC URL for the EVM blockchainEVM_WS
: WebSocket URL for the EVM blockchainEVM_PK
: Private key for the EVM walletEVM_BRIDGE_CONTRACT
: Address of the bridge contract on the EVM blockchainSOLANA_WALLET
: Path to the Solana wallet keypairSOLANA_RPC
: RPC URL for the Solana blockchainSOLANA_WS
: WebSocket URL for the Solana blockchainSOLANA_BRIDGE_PROGRAM
: Address of the bridge program on SolanaSOLANA_BRIDGE_ACCOUNT
: Address of the bridge account on Solana
- Rust 1.80+ and Cargo
- RocksDB dependencies:
librocksdb-dev
,libclang-dev
-
Clone the repository:
git clone https://github.com/soljesty/solana-evm-nft-bridge-relayer.git cd solana-evm-nft-bridge-relayer
-
Install dependencies:
sudo apt-get update sudo apt-get install -y librocksdb-dev libclang-dev
-
Create a
.env
file based on the example:cp .env.example .env
Edit .env with your configuration
- Set the
RUST_LOG
environment variable to control log levels:export RUST_LOG=info
- Start the bridge:
cargo run
- Build the project:
cargo build --release
- Run the bridge:
./target/release/Bridge_Relayer
The project is organized as a Rust workspace with multiple crates:
bin/bridge_relayer
: Main executablecrates/api
: API servercrates/requests
: Request processingcrates/evm
: EVM clientcrates/solana
: Solana clientcrates/storage
: Storage layercrates/types
: Common data types
The project includes unit tests for each component (more to be added):
- Run tests with
cargo test
- Private keys are stored in environment variables and should be kept secure
- The bridge uses secure RPC connections to the blockchains
- Token ownership is verified before processing transfers
- Error handling prevents double-spending and other security issues
This codebase is provided as-is. Users should perform their own security audits before using in production.
- Solana RPC Connection Failures: Ensure your Solana RPC endpoint is correct and accessible. Try using a different RPC provider if issues persist.
- EVM WebSocket Disconnects: The bridge automatically attempts to reconnect when WebSocket connections drop. Check your network stability and EVM node health.
- Insufficient Gas: Ensure the EVM wallet has enough funds for gas fees.
- Solana Transaction Errors: Check that the Solana wallet has enough SOL for transaction fees.
Q: Is the bridge bidirectional?
A: Yes, the bridge supports transfers in both directions: from Solana to EVM and from EVM to Solana.
Q: Which EVM chains are supported?
A: The bridge is designed to work with any EVM-compatible blockchain, including Ethereum, Polygon, Binance Smart Chain, and others. You'll need to deploy the bridge contract on your target EVM chain.
Q: Can I transfer any NFT?
A: The bridge supports transfer of NFTs that conform to the standard token interfaces on each chain (e.g., ERC-721 on EVM chains and SPL tokens on Solana).
Q: How does the bridge handle network fees?
A: The bridge operator pays for the gas fees on the destination chain. Users only pay for the transaction fees on the source chain when initiating a transfer.
Q: Is the bridge custodial?
A: Yes, the bridge takes custody of tokens during the transfer process. Tokens are locked in the bridge contract/program on the source chain.
Q: How are token attributes preserved across chains?
A: The bridge transfers metadata along with the token, ensuring that attributes, images when minted on the destination chain.
GNU License - See LICENSE file for details.