Network Configuration
RPC Endpoints
Section titled “RPC Endpoints”import { RPC_URLS } from '@filoz/synapse-sdk'
// MainnetRPC_URLS.mainnet.websocket // wss://wss.node.glif.io/apigw/lotus/rpc/v1RPC_URLS.mainnet.http // https://api.node.glif.io/rpc/v1
// Calibration TestnetRPC_URLS.calibration.websocket // wss://wss.calibration.node.glif.io/apigw/lotus/rpc/v1RPC_URLS.calibration.http // https://api.calibration.node.glif.io/rpc/v1
GLIF Authorization
Section titled “GLIF Authorization”For higher rate limits with GLIF endpoints:
import { Synapse } from '@filoz/synapse-sdk'
// Using GLIF authorization with private keyconst synapse = await Synapse.create({ privateKey: '0x...', rpcURL: 'https://api.node.glif.io/rpc/v1', authorization: 'Bearer YOUR_GLIF_TOKEN'})
Connection Management
Section titled “Connection Management”WebSocket vs HTTP
Section titled “WebSocket vs HTTP”The SDK supports both WebSocket and HTTP connections:
- WebSocket (recommended): Better performance for multiple operations, real-time updates, lower latency
- HTTP: Simpler setup, stateless, better for single operations
// WebSocket connection (recommended)const synapse = await Synapse.create({ privateKey: '0x...', rpcURL: RPC_URLS.calibration.websocket})
// HTTP connectionconst synapse = await Synapse.create({ privateKey: '0x...', rpcURL: RPC_URLS.calibration.http})
Cleaning Up Connections
Section titled “Cleaning Up Connections”When using WebSocket connections, it’s important to properly close them when your application is done:
// Get the provider instanceconst provider = synapse.getProvider()
// Clean up the connectionif (provider && typeof provider.destroy === 'function') { await provider.destroy()}
This is especially important for:
- CLI tools: Ensures the process can exit cleanly
- Test suites: Prevents hanging tests and resource leaks
- Server applications: Frees resources when shutting down
- Long-running applications: Allows graceful reconnection if needed
Connection Best Practices
Section titled “Connection Best Practices”- Reuse connections: Create a single Synapse instance and reuse it for multiple operations
- Handle disconnections: Implement reconnection logic for long-running applications
- Clean up on exit: Always destroy connections when your application terminates
// Example: Proper cleanup in a Node.js applicationprocess.on('SIGINT', async () => { console.log('Shutting down...') const provider = synapse.getProvider() if (provider && typeof provider.destroy === 'function') { await provider.destroy() } process.exit(0)})
Network Details
Section titled “Network Details”Filecoin Mainnet
Section titled “Filecoin Mainnet”- Chain ID: 314
- USDFC Contract:
0x80B98d3aa09ffff255c3ba4A241111Ff1262F045
Filecoin Calibration Testnet
Section titled “Filecoin Calibration Testnet”- Chain ID: 314159
- USDFC Contract:
0xb3042734b608a1B16e9e86B374A3f3e389B4cDf0