core

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2026 License: Apache-2.0, UNKNOWN not legal advice Imports: 0 Imported by: 0

README

Tendermint RPC

Pagination

Requests that return multiple items will be paginated to 30 items by default. You can specify further pages with the ?page parameter. You can also set a custom page size up to 100 with the ?per_page parameter.

Documentation

Overview

Introduction

Tendermint supports the following RPC protocols:

* URI over HTTP * JSONRPC over HTTP * JSONRPC over websockets

Tendermint RPC is built using our own RPC library which contains its own set of documentation and tests. See it here: https://github.com/gnolang/gno/tree/master/tm2/pkg/bft/rpc/lib

## Configuration

RPC can be configured by tuning parameters under `[rpc]` table in the `$TMHOME/config/config.toml` file or by using the `--rpc.X` command-line flags.

Default rpc listen address is `tcp://0.0.0.0:26657`. To set another address, set the `laddr` config parameter to desired value. CORS (Cross-Origin Resource Sharing) can be enabled by setting `cors_allowed_origins`, `cors_allowed_methods`, `cors_allowed_headers` config parameters.

## Arguments

Arguments which expect strings or byte arrays may be passed as quoted strings, like `"abc"` or as `0x`-prefixed strings, like `0x616263`.

## URI/HTTP

```bash curl 'localhost:26657/broadcast_tx_sync?tx="abc"' ```

> Response:

```json

{
	"error": "",
	"result": {
		"hash": "2B8EC32BA2579B3B8606E42C06DE2F7AFA2556EF",
		"log": "",
		"data": "",
		"code": "0"
	},
	"id": "",
	"jsonrpc": "2.0"
}

```

## JSONRPC/HTTP

JSONRPC requests can be POST'd to the root RPC endpoint via HTTP (e.g. `http://localhost:26657/`).

```json

{
	"method": "broadcast_tx_sync",
	"jsonrpc": "2.0",
	"params": [ "abc" ],
	"id": "dontcare"
}

```

## JSONRPC/websockets

JSONRPC requests can be made via websocket. The websocket endpoint is at `/websocket`, e.g. `localhost:26657/websocket`.

## More Examples

See the various bash tests using curl in `test/`, and examples using the `Go` API in `rpc/client/`.

## Get the list

An HTTP Get request to the root RPC endpoint shows a list of available endpoints.

```bash curl 'localhost:26657' ```

> Response:

```plain Available endpoints: /abci_info /dump_consensus_state /genesis /net_info /num_unconfirmed_txs /status /health /unconfirmed_txs /unsafe_flush_mempool /unsafe_stop_cpu_profiler /validators

Endpoints that require arguments: /abci_query?path=_&data=_&prove=_ /block?height=_ /blockchain?minHeight=_&maxHeight=_ /broadcast_tx_async?tx=_ /broadcast_tx_commit?tx=_ /broadcast_tx_sync?tx=_ /commit?height=_ /dial_seeds?seeds=_ /dial_persistent_peers?persistent_peers=_ /tx?hash=_&prove=_ /unsafe_start_cpu_profiler?filename=_ /unsafe_write_heap_profile?filename=_ ```

Endpoints

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consensus

type Consensus interface {
	GetConfigDeepCopy() *cnscfg.ConsensusConfig
	GetState() sm.State
	GetValidators() (int64, []*types.Validator)
	GetLastHeight() int64
	GetRoundStateDeepCopy() *cstypes.RoundState
	GetRoundStateSimple() cstypes.RoundStateSimple
}

type Environment

type Environment struct {
	// external, thread-safe interfaces
	ProxyAppQuery appconn.Query

	// interfaces defined in types and above
	StateDB      dbm.DB
	BlockStore   sm.BlockStore
	Consensus    Consensus
	P2PPeers     peers
	P2PTransport transport

	// objects
	PubKey      crypto.PubKey
	GenDoc      *types.GenesisDoc // cache the genesis structure
	EventSwitch events.EventSwitch
	Mempool     mempl.Mempool
	GetFastSync func() bool // avoids dependency on consensus pkg

	Logger *slog.Logger
	Config cfg.RPCConfig // value, not pointer — TimeoutBroadcastTxCommit must be stable
	// contains filtered or unexported fields
}

---------------------------------------------- Environment holds all per-node state that RPC handlers operate on. One Environment is created per Node instance, replacing the package-level globals this package used previously. All fields are expected to be populated before Start is called; individual handlers may only need a subset (tests construct partial Environments).

func (*Environment) ABCIInfo

func (env *Environment) ABCIInfo(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error)

ABCIInfo gets some info about the application.

func (*Environment) ABCIQuery

func (env *Environment) ABCIQuery(ctx *rpctypes.Context, path string, data []byte, height int64, prove bool) (*ctypes.ResultABCIQuery, error)

ABCIQuery queries the application for some information.

func (*Environment) Block

func (env *Environment) Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error)

Block returns the block at the given height. If no height is provided, it fetches the latest block.

func (*Environment) BlockResults

func (env *Environment) BlockResults(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlockResults, error)

BlockResults gets ABCIResults at a given height. If no height is provided, it fetches results for the latest block. Results are for the height of the block containing the txs.

func (*Environment) BlockchainInfo

func (env *Environment) BlockchainInfo(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)

BlockchainInfo gets block headers for minHeight <= height <= maxHeight. Block headers are returned in descending order (highest first).

Returns at most 20 items.

func (*Environment) BroadcastTxAsync

func (env *Environment) BroadcastTxAsync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error)

BroadcastTxAsync returns right away, with no response. Does not wait for CheckTx nor DeliverTx results.

If you want to be sure that the transaction is included in a block, you can subscribe for the result using JSONRPC via a websocket. See https://docs.tendermint.com/v0.34/tendermint-core/subscription.html

func (*Environment) BroadcastTxCommit

func (env *Environment) BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)

BroadcastTxCommit returns with the responses from CheckTx and DeliverTx.

IMPORTANT: use only for testing and development. In production, use BroadcastTxSync or BroadcastTxAsync.

CONTRACT: only returns error if mempool.CheckTx() errs, we timeout waiting for tx to commit, or the Environment was not started.

func (*Environment) BroadcastTxSync

func (env *Environment) BroadcastTxSync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error)

BroadcastTxSync returns with the response from CheckTx. Does not wait for DeliverTx result.

func (*Environment) Commit

func (env *Environment) Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, error)

Commit returns the block commit at the given height. If no height is provided, it fetches the commit for the latest block.

func (*Environment) ConsensusParams

func (env *Environment) ConsensusParams(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultConsensusParams, error)

ConsensusParams returns the consensus parameters at the given block height. If no height is provided, it fetches the current consensus params.

func (*Environment) ConsensusState

func (env *Environment) ConsensusState(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error)

ConsensusState returns a concise summary of the consensus state. UNSTABLE.

func (*Environment) DumpConsensusState

func (env *Environment) DumpConsensusState(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error)

DumpConsensusState dumps consensus state. UNSTABLE.

func (*Environment) Genesis

func (env *Environment) Genesis(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error)

Genesis returns the genesis file.

func (*Environment) Health

func (env *Environment) Health(ctx *rpctypes.Context) (*ctypes.ResultHealth, error)

Health returns node health. Returns empty result (200 OK) on success, no response in case of an error.

func (*Environment) NetInfo

func (env *Environment) NetInfo(ctx *rpctypes.Context) (*ctypes.ResultNetInfo, error)

NetInfo returns network info.

func (*Environment) NumUnconfirmedTxs

func (env *Environment) NumUnconfirmedTxs(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error)

NumUnconfirmedTxs returns the number of unconfirmed transactions.

func (*Environment) Routes

func (env *Environment) Routes(unsafe bool) map[string]*rpc.RPCFunc

Routes builds the RPC route map for this Environment. Each route binds a method value on env, so requests dispatch to this specific Environment's state without going through package globals.

If unsafe is true, the "unsafe_*" routes (mempool flush, CPU/heap profiler) are included.

func (*Environment) Start

func (env *Environment) Start() error

Start initializes any per-Environment background services. Currently this only creates and starts the txDispatcher if EventSwitch is non-nil. Start is idempotent but panics if called after Stop.

func (*Environment) Status

func (env *Environment) Status(ctx *rpctypes.Context, heightGtePtr *int64) (*ctypes.ResultStatus, error)

Status returns Tendermint status including node info, pubkey, latest block hash, app hash, block height and time.

`heightGte` optionally returns 409 if the latest chain height is less than it, which is useful for readyness probes.

func (*Environment) Stop

func (env *Environment) Stop() error

Stop tears down the services started by Start. It should be called before the associated EventSwitch is stopped so the txDispatcher goroutine exits via its own Quit channel rather than racing evsw.Quit(). Stop is idempotent.

func (*Environment) Tx

func (env *Environment) Tx(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultTx, error)

Tx allows you to query the transaction results. `nil` could mean the transaction is in the mempool, invalidated, or was not sent in the first place.

func (*Environment) UnconfirmedTxs

func (env *Environment) UnconfirmedTxs(ctx *rpctypes.Context, limit int) (*ctypes.ResultUnconfirmedTxs, error)

UnconfirmedTxs gets unconfirmed transactions (maximum ?limit entries) including their number.

func (*Environment) UnsafeFlushMempool

func (env *Environment) UnsafeFlushMempool(ctx *rpctypes.Context) (*ctypes.ResultUnsafeFlushMempool, error)

UnsafeFlushMempool removes all transactions from the mempool.

func (*Environment) UnsafeStartCPUProfiler

func (env *Environment) UnsafeStartCPUProfiler(ctx *rpctypes.Context, filename string) (*ctypes.ResultUnsafeProfile, error)

UnsafeStartCPUProfiler starts a pprof profiler using the given filename.

func (*Environment) UnsafeStopCPUProfiler

func (env *Environment) UnsafeStopCPUProfiler(ctx *rpctypes.Context) (*ctypes.ResultUnsafeProfile, error)

UnsafeStopCPUProfiler stops the running pprof profiler.

func (*Environment) UnsafeWriteHeapProfile

func (env *Environment) UnsafeWriteHeapProfile(ctx *rpctypes.Context, filename string) (*ctypes.ResultUnsafeProfile, error)

UnsafeWriteHeapProfile dumps a heap profile to the given filename.

func (*Environment) Validators

func (env *Environment) Validators(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultValidators, error)

Validators returns the validator set at the given block height. If no height is provided, it fetches the current validator set. Note the validators are sorted by their address — this is the canonical order for the validators in the set as used in computing their Merkle root.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL