#tendermint #cosmos #blockchain #rpc-client

bin+lib tendermint-rpc

tendermint-rpc contains the core types returned by a Tendermint node's RPC endpoint. All networking related features are feature guarded to keep the dependencies small in cases where only the core types are needed

53 releases (26 breaking)

0.40.0 Oct 23, 2024
0.38.1 Jul 23, 2024
0.35.0 Mar 14, 2024
0.34.0 Oct 2, 2023
0.15.0 Jul 20, 2020

#5 in #tendermint

Download history 9168/week @ 2024-08-16 8633/week @ 2024-08-23 10361/week @ 2024-08-30 11244/week @ 2024-09-06 10962/week @ 2024-09-13 11332/week @ 2024-09-20 12039/week @ 2024-09-27 11629/week @ 2024-10-04 10271/week @ 2024-10-11 8368/week @ 2024-10-18 8814/week @ 2024-10-25 8599/week @ 2024-11-01 6772/week @ 2024-11-08 8550/week @ 2024-11-15 8166/week @ 2024-11-22 6979/week @ 2024-11-29

31,820 downloads per month
Used in 103 crates (30 directly)

Apache-2.0

1.5MB
31K SLoC

Crate Docs

See the repo root for build status, license, rust version, etc.

tendermint-rpc

A Rust implementation of the core types returned by a Tendermint node's RPC endpoint. These can be used to deserialize JSON-RPC responses.

All networking related features will be feature guarded to keep the dependencies small in cases where only the core types are needed.

Documentation

See documentation on crates.io.

Client

This crate optionally provides access to different types of RPC client functionality and different client transports based on which features you select when using it.

Several client-related features are provided at present:

  • http-client - Provides HttpClient, which is a basic RPC client that interacts with remote Tendermint nodes via JSON-RPC over HTTP or HTTPS. This client does not provide Event subscription functionality. See the Tendermint RPC for more details.
  • websocket-client - Provides WebSocketClient, which provides full client functionality, including general RPC functionality as well as Event] subscription functionality. Can be used over secure (wss://) and unsecure (ws://) connections.

CLI

A tendermint-rpc console application is provided for testing/experimentation purposes. To build this application:

# From the tendermint-rpc crate's directory
cd rpc
cargo build --bin tendermint-rpc --features cli

# To run directly and show usage information
cargo run --bin tendermint-rpc --features cli -- --help

# To install the binary to your Cargo binaries path
# (should be globally accessible)
cargo install --bin tendermint-rpc --features cli --path .

The application sends its logs to stderr and its output to stdout, so it's relatively easy to capture RPC output.

Usage examples: (assuming you've installed the binary)

# Check which RPC commands/endpoints are supported.
tendermint-rpc --help

# Query the status of the Tendermint node bound to tcp://127.0.0.1:26657
tendermint-rpc status

# Submit a transaction to the key/value store ABCI app via a Tendermint node
# bound to tcp://127.0.0.1:26657
tendermint-rpc broadcast-tx-async somekey=somevalue

# Query the value associated with key "somekey" (still assuming a key/value
# store ABCI app)
tendermint-rpc abci-query somekey

# To use an HTTP/S proxy to access your RPC endpoint
tendermint-rpc --proxy-url http://yourproxy:8080 abci-query somekey

# To set your HTTP/S proxy for multiple subsequent queries
export HTTP_PROXY=http://yourproxy:8080
tendermint-rpc abci-query somekey

# Subscribe to receive new blocks (must use the WebSocket endpoint)
# Prints out all incoming events
tendermint-rpc -u ws://127.0.0.1:26657/websocket subscribe "tm.event='NewBlock'"

# If you want to execute a number of queries against a specific endpoint and
# don't feel like re-typing the URL over and over again, just set the
# TENDERMINT_RPC_URL environment variable
export TENDERMINT_RPC_URL=ws://127.0.0.1:26657/websocket
tendermint-rpc subscribe "tm.event='Tx'"

Mock Clients

Mock clients are included when either of the http-client or websocket-client features are enabled to aid in testing. This includes MockClient, which implements both Client and SubscriptionClient traits.

Testing

The RPC types are directly tested through the integration tests. These tests use fixtures taken from running Tendermint nodes to ensure compatibility without needing access to a running node during testing. All of these fixtures were generated manually, and automatic regeneration of the fixtures is on our roadmap.

To run these tests locally:

# From within the rpc crate
cargo test --all-features

The RPC client is also indirectly tested through the Tendermint integration tests, which happens during CI. All of these tests require a running Tendermint node, and are therefore ignored by default. To run these tests locally:

# In one terminal, spin up a Tendermint node
docker pull tendermint/tendermint:latest
docker run -it --rm -v "/tmp/tendermint:/tendermint" \
    tendermint/tendermint init
docker run -it --rm -v "/tmp/tendermint:/tendermint" \
    -p 26657:26657 \
    tendermint/tendermint node --proxy_app=kvstore

# In another terminal, run the ignored Tendermint tests to connect to the node
# running at tcp://127.0.0.1:26657
cd ../tendermint
cargo test --all-features -- --ignored

Dependencies

~8–22MB
~328K SLoC