Skip to content

penumbra-zone/vite-rpc-example

Repository files navigation

Penumbra rpc request demo

This repo is an example of how to use bufbuild libraries to query penumbra nodes. Run example via:

npm install
npm run develop
# View code implementation in src/

Guide to connecting to making rpc requests to penumbra nodes

Install deps

npm install --save @connectrpc/connect-web @connectrpc/connect @penumbra-zone/protobuf

Choose a transport

It's quite likely you'll want to use a GrpcWebTransport if you are issuing http requests.

import { createGrpcWebTransport } from "@connectrpc/connect-web";

const transport = createGrpcWebTransport({
  baseUrl: GRPC_ENDPOINT, // Your grpc endpoint you'd like to issue requests to
});

Import a service that you'd like to query

Option A: You'd like to query an rpc method from the following services:

If so, you can import them from @penumbra-zone/protobuf. This removes the need to add the buf custom registry. Example:

import { TendermintProxyService } from "@penumbra-zone/protobuf";

Option B: You'd like to query another service not specified above.

# Set your registry
npm config set @buf:registry https://buf.build/gen/npm/v1/

# Install the generated sdk. Example from cosmos/interchain-security. 
# The npm link can be found in the sdk tab of buf build: https://buf.build/cosmos/interchain-security/sdks
npm install @buf/cosmos_interchain-security.connectrpc_es@latest

Instantiate & query

With the transport & service, you can construct a client and make rpc requests:

import { createGrpcWebTransport } from "@connectrpc/connect-web";
import { createPromiseClient } from "@connectrpc/connect";
import { TendermintProxyService } from "@penumbra-zone/protobuf";

const GRPC_ENDPOINT = "https://penumbra.stakewith.binary.builders";
const transport = createGrpcWebTransport({
  baseUrl: GRPC_ENDPOINT,
});
export const tendermintClient = createPromiseClient(
  TendermintProxyService,
  transport,
);
const statusResponse = await tendermintClient.getStatus({});

Example from a service not in @penumbra-zone/protobuf:

import { Query } from "@buf/cosmos_interchain-security.connectrpc_es/interchain_security/ccv/consumer/v1/query_connect";

const GRPC_ENDPOINT = "https://penumbra.stakewith.binary.builders";
const transport = createGrpcWebTransport({
  baseUrl: GRPC_ENDPOINT,
});
const icsClient = createPromiseClient(Query, transport);
const paramsResponse = await icsClient.queryParams({});

Issuing RPC requests to Prax

Interested in writing a frontend that interacts with Prax?

Use the @penumbra-zone/client npm package.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published