JavaScript/TypeScript
Complete JavaScript and TypeScript examples for integrating with NextBlock's gRPC API using @grpc/grpc-js and @solana/web3.js.
Overview
These examples demonstrate how to:
Establish secure gRPC connections with authentication
Submit single and batched transactions with proper tipping
Stream real-time tip floor data for dynamic tip optimization
Maintain persistent connections with keepalive mechanisms
Prerequisites
Install the required dependencies:
npm install @grpc/grpc-js @grpc/proto-loader
npm install @solana/web3.js @solana/spl-token
npm install typescript @types/node # For TypeScript support
# Generate JavaScript gRPC client from nextblock-proto
# See https://github.com/nextblock-ag/nextblock-proto for instructions
Examples
Core Examples
Connection - Establish gRPC connections with authentication
Submit Single Transaction - Send individual transactions with tips
Submit Batched Transactions - Send atomic transaction bundles
Tip Floor Stream - Stream real-time tip floor data
Keepalive - Maintain persistent connections
Quick Start
Generate gRPC client from nextblock-proto
Install dependencies using npm/yarn
Set up environment with API key and endpoint
Start with connection example to establish authenticated gRPC connection
Use tip floor streaming to optimize transaction tips dynamically
Submit transactions using single or batched submission methods
Key Features
TypeScript Support
All examples include full TypeScript type definitions for better development experience.
Modern JavaScript
Uses modern ES6+ features including async/await, destructuring, and modules.
Error Handling
Comprehensive error handling with retry logic and exponential backoff.
Connection Management
Persistent connections with keepalive, health monitoring, and automatic recovery.
Dynamic Tipping
Real-time tip optimization based on current network conditions from tip floor API.
Best Practices
Use TypeScript - Leverage type safety for better code quality
Enable TLS - Always use secure connections in production
Implement keepalive - Maintain persistent connections for better performance
Monitor tip floors - Use streaming API for dynamic tip adjustment
Handle errors gracefully - Implement proper retry logic with exponential backoff
Use environment variables - Store sensitive configuration securely
Choose appropriate endpoints - Use the closest endpoint for better latency
Bundle transactions - Use batched submissions for atomic operations
Last updated