Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Clients

What this teaches: when to use HttpClient and when to use WsClient, and what each one is wired to under the hood.

Mental model

The SDK ships two transports:

  • HttpClient — one-shot queries and transaction broadcast over GraphQL and REST. Cloneable, no live connection.
  • WsClient — GraphQL subscriptions over graphql-transport-ws. Cheap factory value; the actual socket lives in a Session.

There is no shared "Client" abstraction. Pick the one that matches the call pattern.

HttpClient

HttpClient wraps a reqwest::Client. It is Debug + Clone; cloning shares the underlying connection pool — pass it around freely.

It implements four upstream query traits, which is where the queries live:

  • QueryClientquery_app, query_store, simulate.
  • BlockClientquery_block, query_block_outcome (REST, not GraphQL).
  • BroadcastClientbroadcast_tx.
  • SearchTxClientsearch_tx.

Bringing the traits into scope is what unlocks the methods:

use {
    anyhow::Result,
    dango_sdk::HttpClient,
    grug::{BlockClient, BroadcastClient, QueryClient, SearchTxClient},
};
 
#[tokio::main]
async fn main() -> Result<()> {
    let client = HttpClient::new("https://api-mainnet.dango.zone")?;
    let block  = client.query_block(None).await?;
    println!("height: {}", block.info.height);
    Ok(())
}

Extension methods on HttpClient

Because HttpClient implements QueryClient, the QueryClientExt blanket trait lights up a suite of convenience methods:

MethodWhat it does
query_app_configFetch the typed AppConfig.
query_balanceFetch a single denom balance for an address.
query_balancesFetch all balances for an address.
query_supplyFetch total supply for one denom.
query_suppliesFetch total supplies.
query_wasm_smartRun a typed smart query on a contract.
query_wasm_rawRead a raw storage slot from a contract.
query_codeFetch a Wasm bytecode by hash.
query_codesList uploaded code hashes.
query_contractFetch a contract's info.
query_contractsList contracts.

See the QueryClientExt reference for full signatures.

Pagination

HttpClient ships own pagination helpers on top of the GraphQL connection types:

  • paginate_all — generic forward/backward loop driven by closures.
  • paginate_accounts, paginate_transfers, paginate_transactions, paginate_blocks, paginate_events, paginate_messages — typed wrappers for each indexer connection.

Use the typed wrappers when the query type matches; use paginate_all when shaping a custom traversal.

WsClient

WsClient holds nothing but a parsed Url. Cloning is free.

Two ways to consume it:

  • WsClient::connectSession. Open one socket and multiplex multiple subscriptions over it. Drop the Session and every derived stream to close the connection.
  • WsClient::subscribe. Open a dedicated socket for one subscription. Drop the stream to close.

Subscription items are Result<Response<T>, WsError>. The first error variant WsError::Closed ends the stream. See Subscriptions for which entry point to pick.

Lifecycle

  • HttpClient has no Drop hook. Reuse one instance for the lifetime of the program.
  • WsClient is a config object; copy it freely.
  • Session runs a background tokio task spawned by connect. The last Session clone drops it via a Close command. See Session.

Next