# gRPC, REST, and Tendermint Endpoints

### An Overview of All Endpoints <a href="#an-overview-of-all-endpoints" id="an-overview-of-all-endpoints"></a>

Each node exposes the following endpoints for users to interact with a node, each endpoint is served on a different port. Details on how to configure each endpoint is provided in the endpoint's own section.

* the gRPC server (default port: `9090`),
* the REST server (default port: `1317`),
* the Tendermint RPC endpoint (default port: `26657`).

The node also exposes some other endpoints, such as the Tendermint P2P endpoint, or the [Prometheus endpoint (opens new window)](https://docs.tendermint.com/master/nodes/metrics.html#metrics), which are not directly related to the Cosmos SDK. Please refer to the [Tendermint documentation (opens new window)](https://docs.tendermint.com/master/tendermint-core/using-tendermint.html#configuration)for more information about these endpoints.

### [#](https://docs.cosmos.network/master/core/grpc_rest.html#grpc-server)gRPC Server <a href="#grpc-server" id="grpc-server"></a>

In the Cosmos SDK, Protobuf is the main [encoding](https://docs.cosmos.network/master/core/encoding) library. This brings a wide range of Protobuf-based tools that can be plugged into the Cosmos SDK. One such tool is [gRPC (opens new window)](https://grpc.io/), a modern open-source high performance RPC framework that has decent client support in several languages.

Each module exposes a [Protobuf `Query` service](https://docs.cosmos.network/master/building-modules/messages-and-queries.html#queries) that defines state queries. The `Query` services and a transaction service used to broadcast transactions are hooked up to the gRPC server via the following function inside the application:

Copy // RegisterGRPCServer registers gRPC services directly with the gRPC // server. RegisterGRPCServer(grpc.Server)

Note: It is not possible to expose any [Protobuf `Msg` service](https://docs.cosmos.network/master/building-modules/messages-and-queries.html#messages) endpoints via gRPC. Transactions must be generated and signed using the CLI or programmatically before they can be broadcasted using gRPC. See [Generating, Signing, and Broadcasting Transactions](https://docs.cosmos.network/master/run-node/txs.html) for more information.

The `grpc.Server` is a concrete gRPC server, which spawns and serves all gRPC query requests and a broadcast transaction request. This server can be configured inside `~/.simapp/config/app.toml`:

* `grpc.enable = true|false` field defines if the gRPC server should be enabled. Defaults to `true`.
* `grpc.address = {string}` field defines the address (really, the port, since the host should be kept at `0.0.0.0`) the server should bind to. Defaults to `0.0.0.0:9090`.

`~/.simapp` is the directory where the node's configuration and databases are stored. By default, it's set to `~/.{app_name}`.

Once the gRPC server is started, you can send requests to it using a gRPC client. Some examples are given in our [Interact with the Node](https://docs.cosmos.network/master/run-node/interact-node.html#using-grpc) tutorial.

An overview of all available gRPC endpoints shipped with the Cosmos SDK is [Protobuf documentation (opens new window)](https://buf.build/cosmos/cosmos-sdk).

### [#](https://docs.cosmos.network/master/core/grpc_rest.html#rest-server)REST Server <a href="#rest-server" id="rest-server"></a>

Cosmos SDK supports REST routes via gRPC-gateway.

All routes are configured under the following fields in `~/.simapp/config/app.toml`:

* `api.enable = true|false` field defines if the REST server should be enabled. Defaults to `false`.
* `api.address = {string}` field defines the address (really, the port, since the host should be kept at `0.0.0.0`) the server should bind to. Defaults to `tcp://0.0.0.0:1317`.
* some additional API configuration options are defined in `~/.simapp/config/app.toml`, along with comments, please refer to that file directly.

#### [#](https://docs.cosmos.network/master/core/grpc_rest.html#grpc-gateway-rest-routes)gRPC-gateway REST Routes <a href="#grpc-gateway-rest-routes" id="grpc-gateway-rest-routes"></a>

If, for various reasons, you cannot use gRPC (for example, you are building a web application, and browsers don't support HTTP2 on which gRPC is built), then the Cosmos SDK offers REST routes via gRPC-gateway.

[gRPC-gateway (opens new window)](https://grpc-ecosystem.github.io/grpc-gateway/)is a tool to expose gRPC endpoints as REST endpoints. For each gRPC endpoint defined in a Protobuf `Query` service, the Cosmos SDK offers a REST equivalent. For instance, querying a balance could be done via the `/cosmos.bank.v1beta1.QueryAllBalances` gRPC endpoint, or alternatively via the gRPC-gateway `"/cosmos/bank/v1beta1/balances/{address}"` REST endpoint: both will return the same result. For each RPC method defined in a Protobuf `Query` service, the corresponding REST endpoint is defined as an option:

Copy // AllBalances queries the balance of all coins for a single account. rpc AllBalances(QueryAllBalancesRequest) returns (QueryAllBalancesResponse) { option (google.api.http).get = "/cosmos/bank/v1beta1/balances/{address}";

For application developers, gRPC-gateway REST routes needs to be wired up to the REST server, this is done by calling the `RegisterGRPCGatewayRoutes` function on the ModuleManager.

#### [#](https://docs.cosmos.network/master/core/grpc_rest.html#swagger)Swagger <a href="#swagger" id="swagger"></a>

A [Swagger (opens new window)](https://swagger.io/)(or OpenAPIv2) specification file is exposed under the `/swagger` route on the API server. Swagger is an open specification describing the API endpoints a server serves, including description, input arguments, return types and much more about each endpoint.

Enabling the `/swagger` endpoint is configurable inside `~/.simapp/config/app.toml` via the `api.swagger` field, which is set to true by default.

For application developers, you may want to generate your own Swagger definitions based on your custom modules. The Cosmos SDK's [Swagger generation script (opens new window)](https://github.com/cosmos/cosmos-sdk/blob/v0.46.0-rc1/scripts/protoc-swagger-gen.sh)is a good place to start.

### [#](https://docs.cosmos.network/master/core/grpc_rest.html#tendermint-rpc)Tendermint RPC <a href="#tendermint-rpc" id="tendermint-rpc"></a>

Independently from the Cosmos SDK, Tendermint also exposes a RPC server. This RPC server can be configured by tuning parameters under the `rpc` table in the `~/.simapp/config/config.toml`, the default listening address is `tcp://0.0.0.0:26657`. An OpenAPI specification of all Tendermint RPC endpoints is available [here (opens new window)](https://docs.tendermint.com/master/rpc/).

Some Tendermint RPC endpoints are directly related to the Cosmos SDK:

* `/abci_query`: this endpoint will query the application for state. As the `path` parameter, you can send the following strings:
  * any Protobuf fully-qualified service method, such as `/cosmos.bank.v1beta1.QueryAllBalances`. The `data` field should then include the method's request parameter(s) encoded as bytes using Protobuf.
  * `/app/simulate`: this will simulate a transaction, and return some information such as gas used.
  * `/app/version`: this will return the application's version.
  * `/store/{path}`: this will query the store directly.
  * `/p2p/filter/addr/{port}`: this will return a filtered list of the node's P2P peers by address port.
  * `/p2p/filter/id/{id}`: this will return a filtered list of the node's P2P peers by ID.
* `/broadcast_tx_{aync,async,commit}`: these 3 endpoint will broadcast a transaction to other peers. CLI, gRPC and REST expose [a way to broadcast transations](https://docs.cosmos.network/master/core/transactions.html#broadcasting-the-transaction), but they all use these 3 Tendermint RPCs under the hood.

### [#](https://docs.cosmos.network/master/core/grpc_rest.html#comparison-table)Comparison Table <a href="#comparison-table" id="comparison-table"></a>

| Name           | Advantages                                                                                                                                                                   | Disadvantages                                                                                                        |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| gRPC           | <p>- can use code-generated stubs in various languages<br>- supports streaming and bidirectional communication (HTTP2)<br>- small wire binary sizes, faster transmission</p> | <p>- based on HTTP2, not available in browsers<br>- learning curve (mostly due to Protobuf)</p>                      |
| REST           | <p>- ubiquitous<br>- client libraries in all languages, faster implementation<br></p>                                                                                        | <p>- only supports unary request-response communication (HTTP1.1)<br>- bigger over-the-wire message sizes (JSON)</p> |
| Tendermint RPC | - easy to use                                                                                                                                                                | - bigger over-the-wire message sizes (JSON)                                                                          |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stafihub.io/welcome-to-stafihub/chain/grpc-rest-and-tendermint-endpoints.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
