geyserstream-client-js is a JavaScript example for connecting to the BlockRazor Solana Geyser Stream over gRPC. It demonstrates how to authenticate with an x-token, configure Geyser subscription filters, and receive account, transaction, and block updates in Node.js.
The repository includes the JavaScript client example together with the Geyser and Solana storage Protocol Buffers definitions loaded at runtime by @grpc/proto-loader.
The example in example.js supports these Geyser Stream subscriptions:
| Subscription | Configuration | Example output |
|---|---|---|
| Accounts | subscribeAccounts, accountParams |
Slot, account public key, owner, and lamports |
| Transactions | subscribeTransactions, transactionParams |
Slot, signature, and vote status |
| Blocks | subscribeBlocks, blockParams |
Slot, blockhash, and transaction count |
The default configuration enables transaction subscriptions. Account and block subscriptions are disabled by default.
- Node.js
- npm
- A BlockRazor authentication token
- Access to the BlockRazor Geyser Stream service
git clone https://github.com/BlockRazorinc/geyserstream-client-js.git
cd geyserstream-client-jsnpm installOpen example.js and update the client configuration:
const clientConfig = {
host: 'geyserstream-tokyo.blockrazor.xyz:443',
token: ''
};Replace the empty token value with your BlockRazor authentication token.
Choose a commitment level and enable the subscriptions you want to receive:
const subscribeConfig = {
commitment: 'CONFIRMED',
subscribeAccounts: false,
subscribeBlocks: false,
subscribeTransactions: true,
// Filter configuration continues below in example.js
};The supported commitment values defined by the Proto file are:
PROCESSED
CONFIRMED
FINALIZED
node example.jsThe program prints the subscription request before sending it and logs each recognized update received from the stream.
Enable account updates with:
subscribeAccounts: trueConfigure the account subscription through accountParams:
accountParams: {
filterKey: 'account-filter-1',
owners: ['11111111111111111111111111111111'],
accounts: [],
filters: [],
nonemptyTxnSignature: false
}The example maps these fields to SubscribeRequestFilterAccounts:
| JavaScript field | Proto field |
|---|---|
owners |
owner |
accounts |
account |
filters |
filters |
nonemptyTxnSignature |
nonempty_txn_signature |
The default owner value is the Solana System Program address included in the source code.
For each account update, the example prints:
- Slot
- Account public key encoded with
bs58 - Account owner encoded with
bs58 - Lamport balance
Transaction subscriptions are enabled by default:
subscribeTransactions: trueThe transaction filter is configured through transactionParams:
transactionParams: {
filterKey: 'tx-filter-1',
vote: false,
failed: false,
accountInclude: [],
accountExclude: [],
accountRequired: [],
signature: null
}The example maps these values to SubscribeRequestFilterTransactions:
| JavaScript field | Proto field |
|---|---|
vote |
vote |
failed |
failed |
accountInclude |
account_include |
accountExclude |
account_exclude |
accountRequired |
account_required |
signature |
signature |
For each transaction update, the example prints:
- Slot
- Transaction signature encoded with
bs58 - Whether the transaction is a vote transaction
Enable block updates with:
subscribeBlocks: trueConfigure the block subscription through blockParams:
blockParams: {
filterKey: 'block-filter-1',
accountInclude: [],
includeTransactions: true,
includeAccounts: false,
includeEntries: false
}The example maps these fields to SubscribeRequestFilterBlocks:
| JavaScript field | Proto field |
|---|---|
accountInclude |
account_include |
includeTransactions |
include_transactions |
includeAccounts |
include_accounts |
includeEntries |
include_entries |
For each block update, the example prints:
- Slot
- Blockhash
- Number of transactions in the block update
createGeyserClient adds the configured token to the gRPC metadata as x-token:
const metadata = new grpc.Metadata();
metadata.add('x-token', token);The metadata is passed when the client opens the Subscribe stream:
const stream = client.Subscribe(metadata);The client creates SSL credentials using the system root certificates:
const sslCreds = grpc.credentials.createSsl();It then creates the generated Geyser client with the configured host and credentials:
new geyserProto.Geyser(host, sslCreds)The example loads proto/geyser.proto at runtime:
const PROTO_PATH = __dirname + '/proto/geyser.proto';
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
});The loaded geyser package is then used to construct the gRPC client.
The main flow in example.js is:
- Load the Geyser Proto definition.
- Define the commitment level and subscription filters.
- Define the gRPC host and authentication token.
- Create SSL credentials and
x-tokenmetadata. - Build a Geyser
SubscribeRequestfrom the enabled filters. - Open the bidirectional gRPC
Subscribestream. - Send the subscription request with
stream.write. - Handle account, transaction, and block updates.
- Log stream errors and stream completion events.
- End the stream when the process receives
SIGINT.
Updates other than Account, Transaction, and Block are reported as unknown update types by the current handler.
The example registers handlers for the gRPC response stream:
stream.on('data', (update) => handleUpdate(update));
stream.on('error', (err) => console.error('Stream error:', err));
stream.on('end', () => console.log('Stream ended'));Pressing Ctrl+C triggers the SIGINT handler, ends the stream, and exits the process:
process.on('SIGINT', () => {
console.log('Closing subscription...');
stream.end();
process.exit(0);
});The current example does not implement automatic reconnection after a stream error or end event.
The Geyser service in proto/geyser.proto defines these RPC methods:
service Geyser {
rpc Subscribe(stream SubscribeRequest)
returns (stream SubscribeUpdate) {}
rpc SubscribeReplayInfo(SubscribeReplayInfoRequest)
returns (SubscribeReplayInfoResponse) {}
rpc Ping(PingRequest)
returns (PongResponse) {}
rpc GetLatestBlockhash(GetLatestBlockhashRequest)
returns (GetLatestBlockhashResponse) {}
rpc GetBlockHeight(GetBlockHeightRequest)
returns (GetBlockHeightResponse) {}
rpc GetSlot(GetSlotRequest)
returns (GetSlotResponse) {}
rpc IsBlockhashValid(IsBlockhashValidRequest)
returns (IsBlockhashValidResponse) {}
rpc GetVersion(GetVersionRequest)
returns (GetVersionResponse) {}
}The included JavaScript example calls Subscribe. The other methods are defined in the Proto file and loaded client, but they are not called by example.js.
.
├── README.md
├── example.js # JavaScript Geyser Stream example
├── package.json
├── package-lock.json
└── proto/
├── geyser.proto # Geyser service and subscription definitions
└── solana-storage.proto # Solana block and transaction definitions
The repository declares these dependencies in package.json:
| Dependency | Usage in the repository |
|---|---|
@grpc/grpc-js |
gRPC client, credentials, metadata, and stream |
@grpc/proto-loader |
Runtime loading of the Geyser Proto definition |
@solana/web3.js |
Declared project dependency |
example.js also imports bs58 to encode account public keys, owners, and transaction signatures. In the current lockfile, bs58 is installed through the declared dependency tree rather than listed directly in package.json.
See the BlockRazor Geyser Stream JavaScript documentation for additional service information.
geyserstream-client-js is a Node.js example for connecting to the BlockRazor Solana Geyser Stream over gRPC and receiving filtered subscription updates.
The example builds subscriptions for accounts, transactions, and blocks. Its update handler prints selected fields from those three update types.
The transaction subscription is enabled by default. Account and block subscriptions remain disabled until their Boolean configuration values are changed to true.
The client sends the configured BlockRazor token in the x-token gRPC metadata field when it opens the subscription stream.
Yes. It creates SSL credentials with grpc.credentials.createSsl() and uses them when constructing the Geyser client.
The included Proto definition supports PROCESSED, CONFIRMED, and FINALIZED. The example uses CONFIRMED by default.
No. The current code logs stream errors and end events but does not open a replacement connection.