gRPC Gateway JSON REST

In irishub v1.0.0, the node continues to serve a REST server. However, the existing routes present in version v0.16.3 and earlier are now marked as deprecated, and new routes have been added via gRPC-gateway.

API Port, Activation and Configuration

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

  • api.enable = true|false field defines if the REST server should be enabled. Defaults to true.
  • 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 ~/.iris/config/app.toml, along with comments, please refer to that file directly.

gRPC-gateway REST Routes

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 IRIShub offers REST routes via gRPC-gateway.

gRPC-gatewayopen in new window is a tool to expose gRPC endpoints as REST endpoints. For each RPC endpoint defined in a Protobuf service, the SDK offers a REST equivalent. For instance, querying token list could be done via the /irismod.token.Query/Tokens gRPC endpoint, or alternatively via the gRPC-gateway /irismod/token/tokens REST endpoint: both will return the same result. For each RPC method defined in a Protobuf service, the corresponding REST endpoint is defined as an option:

+++ https://github.com/irisnet/irismod/blob/master/proto/token/query.proto#L22

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.

Swagger

A Swaggeropen in new window (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 ~/.iris/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 IRIShub's Swagger generation scriptopen in new window is a good place to start.

API Endpoints

IRIShub API Endpoints

API EndpointsDescriptionLegacy REST Endpoint
GET /cosmos/auth/v1beta1/accounts/{address}Return account details based on addressGET /auth/accounts/{address}
GET /cosmos/auth/v1beta1/paramsQuery all parameters
GET /cosmos/bank/v1beta1/balances/{address}Query the balance of all coins for a single accountGET /bank/balances/{address}
GET /cosmos/bank/v1beta1/balances/{address}/{denom}Query the balance of a single coin for a single account
GET /cosmos/bank/v1beta1/denoms_metadataQuery the client metadata for all registered coin denominations
GET /cosmos/bank/v1beta1/denoms_metadata/{denom}Query the client metadata of a given coin denomination
GET /cosmos/bank/v1beta1/paramsQuery the parameters of bank module
GET /cosmos/bank/v1beta1/supplyQuery the total supply of all coinsGET /bank/total
GET /cosmos/bank/v1beta1/supply/{denom}Query the supply of a single coinGET /bank/total/{denom}
GET /cosmos/distribution/v1beta1/community_poolQuery the community pool coinsGET /distribution/community_pool
GET /cosmos/distribution/v1beta1/delegators/{delegator_address}/rewardsQuery the total rewards accrued by each validatorGET /distribution/delegators/{delegatorAddr}/rewards
GET /cosmos/distribution/v1beta1/delegators/{delegator_address}/rewards/{validator_address}Query the total rewards accrued by a delegationGET /distribution/delegators/{delegatorAddr}/rewards/{validatorAddr}
GET /cosmos/distribution/v1beta1/delegators/{delegator_address}/validatorsQuery the validators of a delegator
GET /cosmos/distribution/v1beta1/delegators/{delegator_address}/withdraw_addressQuery withdraw address of a delegatorGET /distribution/delegators/{delegatorAddr}/withdraw_address
GET /cosmos/distribution/v1beta1/paramsQuery params of the distribution moduleGET /distribution/parameters
GET /cosmos/distribution/v1beta1/validators/{validator_address}/commissionQuery accumulated commission for a validator
GET /cosmos/distribution/v1beta1/validators/{validator_address}/outstanding_rewardsQuery rewards of a validator addressGET /distribution/validators/{validatorAddr}/outstanding_rewards
GET /cosmos/distribution/v1beta1/validators/{validator_address}/slashesQuery slash events of a validator
GET /cosmos/evidence/v1beta1/evidenceQuery all evidence
GET /cosmos/evidence/v1beta1/evidence/{evidence_hash}Query evidence based on evidence hash
GET /cosmos/gov/v1beta1/params/{params_type}Query all parameters of the gov moduleGET /gov/parameters/{params_type}
GET /cosmos/gov/v1beta1/proposalsQuery all proposals based on given statusGET /gov/proposals
GET /cosmos/gov/v1beta1/proposals/{proposal_id}Query proposal details based on ProposalIDGET /gov/proposals/{proposal-id}
GET /cosmos/gov/v1beta1/proposals/{proposal_id}/depositsQuery all deposits of a single proposalGET /gov/proposals/{proposal-id}/deposits
GET /cosmos/gov/v1beta1/proposals/{proposal_id}/deposits/{depositor}Query single deposit information based proposalID, depositAddrGET /gov/proposals/{proposal-id}/deposits/{depositor}
GET /cosmos/gov/v1beta1/proposals/{proposal_id}/tallyQuery the tally of a proposal voteGET /gov/proposals/{proposal-id}/tally
GET /cosmos/gov/v1beta1/proposals/{proposal_id}/votesQuery votes of a given proposalGET /gov/proposals/{proposal-id}/votes
GET /cosmos/gov/v1beta1/proposals/{proposal_id}/votes/{voter}Query voted information based on proposalID, voterAddrGET /gov/proposals/{proposal-id}/votes/{voter}
GET /cosmos/params/v1beta1/paramsQuery a specific parameter of a module, given its subspace and key
GET /cosmos/slashing/v1beta1/paramsQuery the parameters of slashing moduleGET /slashing/parameters
GET /cosmos/slashing/v1beta1/signing_infosQuery signing info of all validatorsGET /slashing/signing_infos
GET /cosmos/slashing/v1beta1/signing_infos/{cons_address}Query the signing info of given cons address
GET /cosmos/staking/v1beta1/delegations/{delegator_addr}Query all delegations of a given delegator addressGET /staking/delegators/{delegatorAddr}/delegations
GET /cosmos/staking/v1beta1/delegators/{delegator_addr}/redelegationsQuery redelegations of given addressGET /staking/redelegations
GET /cosmos/staking/v1beta1/delegators/{delegator_addr}/unbonding_delegationsQuery all unbonding delegations of a given delegator addressGET /staking/delegators/{delegatorAddr}/unbonding_delegations
GET /cosmos/staking/v1beta1/delegators/{delegator_addr}/validatorsQuery all validators info for given delegator addressGET /staking/delegators/{delegatorAddr}/validators
GET /cosmos/staking/v1beta1/delegators/{delegator_addr}/validators/{validator_addr}Query validator info for given delegator validator pairGET /staking/delegators/{delegatorAddr}/validators/{validatorAddr}
GET /cosmos/staking/v1beta1/historical_info/{height}Query the historical info for given height
GET /cosmos/staking/v1beta1/paramsQuery the staking parametersGET /staking/parameters
GET /cosmos/staking/v1beta1/poolQuery the pool infoGET /staking/pool
GET /cosmos/staking/v1beta1/validatorsQuery all validators that match the given statusGET /staking/validators
GET /cosmos/staking/v1beta1/validators/{validator_addr}Query validator info for given validator addressGET /staking/validators/{validatorAddr}
GET /cosmos/staking/v1beta1/validators/{validator_addr}/delegationsQuery delegate info for given validatorGET /staking/validators/{validatorAddr}/delegations
GET /cosmos/staking/v1beta1/validators/{validator_addr}/delegations/{delegator_addr}Query delegate info for given validator delegator pairGET /staking/delegators/{delegatorAddr}/delegations/{validatorAddr}
GET /cosmos/staking/v1beta1/validators/{validator_addr}/delegations/{delegator_addr}/unbonding_delegationQuery unbonding info for given validator delegator pairGET /staking/delegators/{delegatorAddr}/unbonding_delegations/{validatorAddr}
GET /cosmos/staking/v1beta1/validators/{validator_addr}/unbonding_delegationsQuery unbonding delegations of a validatorGET /staking/validators/{validatorAddr}/unbonding_delegations
GET /cosmos/upgrade/v1beta1/applied_plan/{name}Query a previously applied upgrade plan by its name
GET /cosmos/upgrade/v1beta1/current_planQuery the current upgrade plan
GET /cosmos/upgrade/v1beta1/upgraded_consensus_state/{last_height}Query the consensus state that will serve as a trusted kernel for the next version of this chain
GET /ibc/core/channel/v1beta1/channelsQuery all the IBC channels of a chain
GET /ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}Query an IBC channel
GET /ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/client_stateQuery for the client state for the channel associated with the provided channel identifiers
GET /ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/consensus_state/revision/{revision_number}/height/{revision_height}Query for the consensus state for the channel associated with the provided channel identifiers
GET /ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/next_sequenceReturn the next receive sequence for a given channel
GET /ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_acknowledgementsReturn all the packet acknowledgements associated with a channel
GET /ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_acks/{sequence}Query a stored packet acknowledgement hash
GET /ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitmentsReturn all the packet commitments hashes associated with a channel
GET /ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/{packet_ack_sequences}/unreceived_acksReturn all the unreceived IBC acknowledgements associated with a channel and sequences
GET /ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/{packet_commitment_sequences}/unreceived_packetsReturn all the unreceived IBC packets associated with a channel and sequences
GET /ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/{sequence}Query a stored packet commitment hash
GET /ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_receipts/{sequence}Query if a given packet sequence has been received on the Queryd chain
GET /ibc/core/channel/v1beta1/connections/{connection}/channelsQuery all the channels associated with a connection end
GET /ibc/client/v1beta1/paramsQuery all parameters of the ibc client
GET /ibc/core/client/v1beta1/client_statesQuery all the IBC light clients of a chain
GET /ibc/core/client/v1beta1/client_states/{client_id}Query an IBC light client
GET /ibc/core/client/v1beta1/consensus_states/{client_id}Query all the consensus state associated with a given client
GET /ibc/core/client/v1beta1/consensus_states/{client_id}/revision/{revision_number}/height/{revision_height}Query a consensus state associated with a client state at a given height
GET /ibc/core/connection/v1beta1/client_connections/{client_id}Query the connection paths associated with a client state
GET /ibc/core/connection/v1beta1/connectionsQuery all the IBC connections of a chain
GET /ibc/core/connection/v1beta1/connections/{connection_id}Query an IBC connection end
GET /ibc/core/connection/v1beta1/connections/{connection_id}/client_stateQuery the client state associated with the connection
GET /ibc/core/connection/v1beta1/connections/{connection_id}/consensus_state/revision/{revision_number}/height/{revision_height}Query the consensus state associated with the connection
GET /ibc/applications/transfer/v1beta1/denom_tracesQuery all denomination traces
GET /ibc/applications/transfer/v1beta1/denom_traces/{hash}Query a denomination trace information
GET /ibc/applications/transfer/v1beta1/paramsQuery all parameters of the ibc-transfer module
GET /irismod/token/paramsQuery the token parameters
GET /irismod/token/tokensReturn the token list
GET /irismod/token/tokens/{denom}Return token with token name
GET /irismod/token/tokens/{symbol}/feesReturn the fees to issue or mint a token
GET /irismod/token/total_burnReturn all burnt coins
GET /irismod/htlc/htlcs/{hash_lock}Query the HTLC by the specified hash lock
GET /irismod/coinswap/liquidities/{denom}Return the total liquidity available for the provided denomination
GET /irismod/nft/collections/{denom_id}Query the NFTs by the specified denom
GET /irismod/nft/collections/{denom_id}/supplyQuery the total supply by a given denom
GET /irismod/nft/denomsQuery all the denoms
GET /irismod/nft/denoms/{denom_id}Query the definition by a given denom ID
GET /irismod/nft/nftsQuery the NFTs by the specified owner
GET /irismod/nft/nfts/{denom_id}/{token_id}Query the NFT by the given denom ID and token ID
GET /irismod/service/bindings/{service_name}Return all service Bindings with service name and owner
GET /irismod/service/bindings/{service_name}/{provider}Return service Binding with service name and provider
GET /irismod/service/contexts/{request_context_id}Return the request context
GET /irismod/service/definitions/{service_name}Return service definition
GET /irismod/service/fees/{provider}Return the earned service fee of one provider
GET /irismod/service/owners/{owner}/withdraw-addressReturn the withdraw address of the binding owner
GET /irismod/service/paramsQuery the service parameters
GET /irismod/service/requests/{request_context_id}/{batch_counter}Return all requests of one service call batch
GET /irismod/service/requests/{request_id}Return the request
GET /irismod/service/requests/{service_name}/{provider}Return all requests of one service with provider
GET /irismod/service/responses/{request_context_id}/{batch_counter}Return all responses of one service call batch
GET /irismod/service/responses/{request_id}Return the response of one request
GET /irismod/service/schemas/{schema_name}Return the schema
GET /irismod/oracle/feedsQuery the feed list
GET /irismod/oracle/feeds/{feed_name}Query the feed
GET /irismod/oracle/feeds/{feed_name}/valuesQuery the feed value
GET /irismod/random/queueQuery the random request queue
GET /irismod/random/randoms/{req_id}Query the random result
GET /irismod/record/records/{record_id}Query the record by the given record ID
GET /irishub/mint/paramsQuery the mint parameters
GET /irishub/guardian/supersReturn all Supers

Tendermint API Endpoints

API EndpointsDescriptionLegacy REST Endpoint
GET /cosmos/base/tendermint/v1beta1/blocks/latestReturn the latest block.GET /blocks/latest
GET /cosmos/base/tendermint/v1beta1/blocks/{height}Query block for given height.GET /blocks/{height}
GET /cosmos/base/tendermint/v1beta1/node_infoQuery the current node info.GET /node_info
GET /cosmos/base/tendermint/v1beta1/syncingQuery node syncing.GET /syncing
GET /cosmos/base/tendermint/v1beta1/validatorsets/latestQuery latest validator-set.GET /validatorsets/latest
GET /cosmos/base/tendermint/v1beta1/validatorsets/{height}Query validator-set at a given height.GET /validatorsets/{height}
POST /cosmos/tx/v1beta1/simulateSimulate executing a transaction for estimating gas usage.
GET /cosmos/tx/v1beta1/txsFetch txs by event.GET /txs
POST /cosmos/tx/v1beta1/txsBroadcast transaction.POST /txs
GET /cosmos/tx/v1beta1/txs/{hash}Fetch a tx by hash.GET /txs/{hash}

Generating and Signing Transactions

It is not possible to generate or sign a transaction using REST, only to broadcast one. You can generating and signing transactions using gRPC Client.

Broadcasting Transactions

Broadcasting a transaction using the gRPC-gateway REST endpoint cosmos/tx/v1beta1/txs can be done by sending a POST request as follows, where the txBytes are the protobuf-encoded bytes of a signed transaction:

curl -X POST \
    -H "Content-Type: application/json" \
    -d'{"tx_bytes":"{{txBytes}}","mode":"BROADCAST_MODE_SYNC"}' \
    "localhost:1317/cosmos/tx/v1beta1/txs"

Querying Transactions

Querying transactions using the gRPC-gateway REST endpoint can be done by sending a GET request as follows:

  • Query tx by hash: /cosmos/tx/v1beta1/txs/{hash}

    curl -X GET \
        -H "accept: application/json" \
        "http://localhost:1317/cosmos/tx/v1beta1/txs/{hash}"
    
  • Query tx by events: /cosmos/tx/v1beta1/txs

    curl -X GET \
        -H "accept: application/json" \
        "http://localhost:1317/cosmos/tx/v1beta1/txs?events={event_content}"