The bridge operates as a bi-directional token transfer system between Solana and Stacks blockchains, utilizing a monitor-and-execute pattern. When a token transfer occurs on Solana, the bridge's monitoring system (implemented in SplToStxBridge.js) detects the change through Solana's WebSocket connection, tracking token account balance changes in real-time. Upon detecting a transfer, the system captures the transaction details, including the amount and recipient address, and adds it to a processing queue. Each queued transfer is then processed sequentially, with the bridge initiating a corresponding token transfer on the Stacks blockchain using the configured contract (Krypto). The bridge ensures transaction integrity through multiple verification steps: it first confirms the Solana transaction's completion, verifies the token amounts, and then executes the Stacks transfer using the makeContractCall function. For reverse transfers (initiated through Bridge.js), the process begins with a Stacks transaction, waiting for confirmation before executing the corresponding Solana transfer. The system implements retry mechanisms and error handling to manage network issues or failed transactions, with configurable delays between transfers to prevent rate limiting. The bridge maintains state through a combination of last processed slots and previous balance tracking, ensuring no double-processing of transactions occurs. All transfers are logged and can be monitored through the bridge's comprehensive logging system, with transaction IDs provided for both chains to enable cross-chain transaction tracking.
- Real-time monitoring of Solana token transfers
- Automated corresponding token minting/transfers on Stacks
- Queue-based transfer processing with retry mechanisms
- Support for custom token contracts
- Interactive transfer mode for manual operations
- Robust error handling and transaction verification
- Node.js (v14 or higher)
- Solana CLI tools
- Stacks CLI tools
- Active Solana DevNet account
- Active Stacks TestNet account
- Clone the repository:
[git clone [repository-url]](https://github.com/Itshbhere/SPL-Token)
cd solana-stacks-bridge- Install dependencies:
npm install- Create configuration files:
my-solana-wallet.json: Your Solana wallet keypairtoken-info.json: Token contract information
The bridge requires several configuration parameters:
{
solanaWalletAddress: "your-solana-wallet-address",
solanaTokenMintAddress: "your-token-mint-address",
stacksPrivateKey: "your-stacks-private-key",
stacksContractAddress: "your-stacks-contract-address",
stacksContractName: "your-contract-name"
}token-info.json:
{
"mintAddress": "your-token-mint-address"
}my-solana-wallet.json: Contains your Solana wallet keypair (keep secure)
-
TokenBridge Class (
SplToStxBridge.js)- Handles Solana token monitoring
- Manages transfer queue
- Executes Stacks transfers
-
DualTokenTransfer Class (
Bridge.js)- Manages bi-directional transfers
- Handles interactive transfer mode
- Provides balance checking utilities
-
Solana Token Transfer Detection:
Token Transfer → Monitor Detection → Queue Addition → Stacks Transfer -
Bi-directional Transfer:
User Input → Validation → Stacks Transfer → Verification → Solana Transfer
const bridge = new TokenBridge({
solanaWalletAddress: "your-address",
solanaTokenMintAddress: "your-token-mint",
stacksPrivateKey: "your-private-key",
stacksContractAddress: "your-contract-address",
stacksContractName: "your-contract-name",
});
await bridge.initialize();Run the interactive transfer script:
node Bridge.jsFollow the prompts to:
- Enter Stacks recipient address
- Enter Solana recipient address
- Enter transfer amount
-
Private Key Management
- Store private keys securely
- Never commit private keys to version control
- Use environment variables for sensitive data
-
Transaction Verification
- Implement proper transaction confirmation checks
- Verify balances before transfers
- Handle failed transactions appropriately
-
Rate Limiting
- Built-in delays between transfers
- Queue-based processing to prevent overload
The bridge implements comprehensive error handling:
-
Transaction Failures
- Automatic retry mechanism
- Queue reintegration for failed transfers
- Configurable retry attempts
-
Network Issues
- Connection error handling
- Automatic reconnection attempts
- Timeout handling
-
Invalid Inputs
- Address validation
- Balance verification
- Amount validation
The bridge provides detailed logging:
- Transaction details
- Error messages
- Balance updates
- Queue status
Monitor:
- Connection status
- Queue processing
- Transaction confirmations
- Balance reconciliation
- Set up local environment:
npm install-
Configure test networks:
- Solana DevNet
- Stacks TestNet
-
Run tests:
npm test-
Update configuration for production:
- Network endpoints
- Contract addresses
- Security parameters
-
Deploy monitoring system
-
Set up logging infrastructure
-
Configure alerts
Common issues and solutions:
-
Connection Failures
- Verify network endpoints
- Check API keys
- Confirm network status
-
Transaction Errors
- Verify balance sufficiency
- Check gas fees
- Confirm address validity
-
Queue Issues
- Monitor queue length
- Check processing status
- Verify retry mechanism
- Fork the repository
- Create feature branch
- Submit pull request
- Follow coding standards
- Include tests
[Specify License]
For support:
- Create GitHub issue
- Contact maintainers
- Check documentation
- Solana team
- Stacks team
- Community contributors