gRPC Unary Methods
Standard request/response methods available alongside streaming subscriptions. These provide the same data as their JSON-RPC equivalents but with significantly lower latency through the Yellowstone Geyser plugin.
Available Methods
| Method | Description |
|---|---|
| GetLatestBlockhash | Returns the latest blockhash for transaction signing |
| GetBlockHeight | Returns the current block height |
| GetSlot | Returns the current slot |
| GetBlock | Returns full block data for a given slot |
| GetTransaction | Returns transaction details by signature |
| GetVersion | Returns the Geyser plugin version |
| GetGenesisHash | Returns the genesis hash |
| GetFeeForMessage | Returns the fee for a given message |
| IsBlockhashValid | Checks if a blockhash is still valid |
| Subscribe | Opens a bidirectional streaming subscription |
Commitment Levels
All unary methods accept an optional commitment parameter:
| Value | Level | Description |
|---|---|---|
0 | Processed | Fastest. Node has processed but not confirmed the block. |
1 | Confirmed | Supermajority of the cluster has voted on the block. |
2 | Finalized | Block is confirmed and the supermajority has rooted it. |
Quick Example
1const grpc = require('@grpc/grpc-js');
2const protoLoader = require('@grpc/proto-loader');
3
4const packageDef = protoLoader.loadSync('geyser.proto', {
5 keepCase: true, longs: String, enums: String, defaults: true, oneofs: true
6});
7const proto = grpc.loadPackageDefinition(packageDef).geyser;
8const client = new proto.Geyser('[IP_ADDRESS]:[PORT]', grpc.credentials.createInsecure());
9
10// Get the latest blockhash
11client.getLatestBlockhash({ commitment: 1 }, (err, response) => {
12 if (err) { console.error(err); return; }
13 console.log('Blockhash:', response.blockhash);
14 console.log('Last valid block height:', response.last_valid_block_height);
15});
16
17// Get current slot
18client.getSlot({ commitment: 1 }, (err, response) => {
19 if (err) { console.error(err); return; }
20 console.log('Current slot:', response.slot);
21});