Server-Side Usage
Server-Side Usage
Section titled “Server-Side Usage”The BridgeSDKServer class is designed for secure backend integrations. It requires both apiKey and secretKey to authenticate, and exposes the same sdk.bridge methods available in the frontend SDK.
Initialization
Section titled “Initialization”import { BridgeSDKServer } from '@voidaisdk/bridge-sdk';
const serverSdk = new BridgeSDKServer({ apiKey: 'YOUR_PUBLIC_API_KEY', secretKey: 'YOUR_SECRET_KEY', environment: 'mainnet', // 'devnet' | 'testnet' | 'mainnet'});
await serverSdk.ready;Authentication Flow
Section titled “Authentication Flow”When BridgeSDKServer is initialized, the SDK automatically:
- Calls
POST /api/v1/auth/loginwith yourapiKeyandsecretKey. - Receives a JWT Access Token.
- Attaches the JWT to all subsequent API requests.
- Refreshes the token automatically before expiry.
Accessing Tenant Data
Section titled “Accessing Tenant Data”After successful initialization, retrieve the tenant metadata associated with your API key:
const keyData = serverSdk.getValidatedApiKeyData();
if (keyData) { console.log('Tenant ID:', keyData.tenantId); console.log('Project Name:', keyData.name);}This data is parsed from the JWT obtained during login.
Backend API Access
Section titled “Backend API Access”The serverSdk.bridge property provides the full BridgeSDK interface — all bridge, swap, CCIP, and transaction methods are available server-side.
// Cancel a pending bridge swapconst result = await serverSdk.bridge.cancelBridgeSwap({ uuid: 'transaction-uuid', fromToken: 'wtao', toToken: 'tao',});console.log('Cancelled:', result.success);
// Fetch recent transactionsconst history = await serverSdk.bridge.getRecentTransactions(1, 50);console.log('Total transactions:', history.totalItems);Common Use Cases
Section titled “Common Use Cases”| Use Case | Description |
|---|---|
| Payment Verification | Confirm a user has successfully bridged assets before unlocking content or fulfilling an order. |
| Transaction History | Fetch and display cross-chain history in your own dashboard or data pipeline. |
| Automated Bridging | Programmatically initiate bridge requests for custodial wallets or backend workflows. |
| Fee Monitoring | Periodically fetch transaction data to reconcile accumulated tenant fees. |
Environment Variables (Recommended)
Section titled “Environment Variables (Recommended)”VOID_API_KEY=your_public_api_keyVOID_SECRET_KEY=your_secret_keyVOID_ENVIRONMENT=mainnetconst serverSdk = new BridgeSDKServer({ apiKey: process.env.VOID_API_KEY, secretKey: process.env.VOID_SECRET_KEY, environment: process.env.VOID_ENVIRONMENT as 'mainnet' | 'testnet' | 'devnet',});