Yellowstone gRPC quickstart

Published . Updated .

From an empty account to transactions printing in your terminal. You need a Solana wallet holding USDC and a server to run the client on.

Endpoint: fra.machgrpc.xyz:10000, plaintext gRPC (no TLS), standard Yellowstone interface. There is no API key and no header: the stream opens because the address it comes from is on your allowlist.

Client examples: Node.js, Go, Rust.

1. Top up and register your IP

  1. Ask us on Discord to get set up. The plan is $300 / month, flat, paid in USDC. If you already have access, open the console at https://app.machgrpc.xyz/, connect a wallet and top up.
  2. On the server that will connect -- not your laptop -- print its IPv4 egress address:

    curl -4 https://checkip.amazonaws.com
  3. Register that address in the console. One address per account.

2. Verify with grpcurl

grpcurl -plaintext fra.machgrpc.xyz:10000 list

If it prints a list of services, the network path and the allowlist both work. If grpcurl cannot connect, no client will: see Troubleshooting.

3. Run a client

Each program is complete. It subscribes to all non-vote, successful transactions and prints the signature, the fee payer and the second account key. Pick one.

Node.js

mkdir mach-quickstart && cd mach-quickstart
npm init -y
npm i @triton-one/yellowstone-grpc bs58

Save as index.mjs:

// index.mjs - npm i @triton-one/yellowstone-grpc bs58
import Client, { CommitmentLevel } from '@triton-one/yellowstone-grpc'
import bs58 from 'bs58'

const ENDPOINT = 'http://fra.machgrpc.xyz:10000'

async function main() {
  // The second argument is the x-token. There is none:
  // your registered IP is the credential.
  const client = new Client(ENDPOINT, undefined, {})
  const stream = await client.subscribe()

  stream.on('data', (update) => {
    const info = update.transaction?.transaction
    if (!info) return
    const keys = info.transaction.message.accountKeys
    // Key 0 is the fee payer. On a plain transfer, key 1 is the recipient.
    console.log(
      bs58.encode(info.signature),
      'from', bs58.encode(keys[0]),
      'to', bs58.encode(keys[1]),
    )
  })
  stream.on('error', (err) => {
    console.error(err)
    process.exit(1)
  })

  stream.write({
    transactions: { all: { vote: false, failed: false } },
    commitment: CommitmentLevel.CONFIRMED,
    accounts: {}, slots: {}, blocks: {}, blocksMeta: {}, entry: {},
    accountsDataSlice: [], transactionsStatus: {},
  })
}

main().catch((err) => {
  console.error(err)
  process.exit(1)
})
node index.mjs

Go

mkdir mach-quickstart && cd mach-quickstart
go mod init mach-quickstart
go get github.com/rpcpool/yellowstone-grpc/examples/golang \
       google.golang.org/grpc github.com/mr-tron/base58

Save as main.go:

// main.go - go get github.com/rpcpool/yellowstone-grpc/examples/golang \
//              google.golang.org/grpc github.com/mr-tron/base58
package main

import (
	"context"
	"log"

	"github.com/mr-tron/base58"
	pb "github.com/rpcpool/yellowstone-grpc/examples/golang/proto"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

const endpoint = "fra.machgrpc.xyz:10000"

func main() {
	// Plaintext, and no per-RPC credentials of any kind: the port speaks gRPC
	// directly, and your registered IP is the whole of the authorisation.
	conn, err := grpc.NewClient(
		endpoint,
		grpc.WithTransportCredentials(insecure.NewCredentials()),
	)
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	stream, err := pb.NewGeyserClient(conn).Subscribe(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	vote, failed := false, false
	err = stream.Send(&pb.SubscribeRequest{
		Transactions: map[string]*pb.SubscribeRequestFilterTransactions{
			"all": {Vote: &vote, Failed: &failed},
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	for {
		update, err := stream.Recv()
		if err != nil {
			log.Fatal(err)
		}
		tx := update.GetTransaction()
		if tx == nil {
			continue
		}
		info := tx.GetTransaction()
		keys := info.GetTransaction().GetMessage().GetAccountKeys()
		// Key 0 is the fee payer. On a plain transfer, key 1 is the recipient.
		log.Printf("%s from %s to %s",
			base58.Encode(info.GetSignature()),
			base58.Encode(keys[0]),
			base58.Encode(keys[1]))
	}
}
go run .

Rust

cargo new mach-quickstart && cd mach-quickstart
cargo add yellowstone-grpc-client yellowstone-grpc-proto \
          bs58 anyhow futures tokio --features tokio/full

Replace src/main.rs with:

// src/main.rs - cargo add yellowstone-grpc-client yellowstone-grpc-proto \
//                          bs58 anyhow futures tokio --features tokio/full
use std::collections::HashMap;

use futures::StreamExt;
use yellowstone_grpc_client::GeyserGrpcClient;
use yellowstone_grpc_proto::prelude::{
    subscribe_update::UpdateOneof, SubscribeRequest, SubscribeRequestFilterTransactions,
};

const ENDPOINT: &str = "http://fra.machgrpc.xyz:10000";

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // No x_token: your registered IP is the credential.
    let mut client = GeyserGrpcClient::build_from_shared(ENDPOINT)?
        .connect()
        .await?;

    let mut transactions = HashMap::new();
    transactions.insert(
        "all".to_owned(),
        SubscribeRequestFilterTransactions {
            vote: Some(false),
            failed: Some(false),
            ..Default::default()
        },
    );

    let request = SubscribeRequest { transactions, ..Default::default() };
    let (_sink, mut stream) = client.subscribe_with_request(Some(request)).await?;

    while let Some(update) = stream.next().await {
        if let Some(UpdateOneof::Transaction(tx)) = update?.update_oneof {
            let Some(info) = tx.transaction else { continue };
            let message = info.transaction.unwrap().message.unwrap();
            let keys = message.account_keys;
            // Key 0 is the fee payer. On a plain transfer, key 1 is the recipient.
            println!(
                "{} from {} to {}",
                bs58::encode(info.signature).into_string(),
                bs58::encode(&keys[0]).into_string(),
                bs58::encode(&keys[1]).into_string()
            );
        }
    }
    Ok(())
}
cargo run --release

What you should see

A continuous stream of lines, one per transaction (Go adds a timestamp in front):

<signature> from <fee payer> to <second account key>

That is every non-vote, successful transaction on the chain. To narrow it to what you need, add server-side filters to the same SubscribeRequest: see Yellowstone gRPC filters.

Troubleshooting

SymptomCauseFix
Hangs, times out, or connection refusedYou connect from an address other than the registered one. Behind NAT, a cloud NAT gateway, a VPN or a proxy, the server goes out as the gateway's address.Run curl -4 https://checkip.amazonaws.com on the machine that runs the client and register what it prints.
first record does not look like a TLS handshake, or another TLS errorThe client uses TLS against a plaintext endpoint.grpcurl -plaintext; an http:// endpoint in Node and Rust; insecure.NewCredentials() in Go.
Works from one server, not from a secondOne address per account.Send the second server out through the registered address, or change the registration.
Config still carries an x-token or authorization header from another providerLeft over from a previous setup.Remove it. The allowlist is the only credential.

Mach gRPC

Mach gRPC provides a Yellowstone-compatible Geyser gRPC stream, self-serve at $300 / month flat, paid in USDC, with access by IP allowlist. A shred stream is also available; access is arranged on Discord.

  • Test it first. A short trial is available before you commit. Ask us for the details.
  • Migration support in your first month. We help you move your setup over.

Ask us on Discord.