The SuiClient: your app's post office clerk
- Audience: Developers new to the Sui blockchain.
- Prerequisites: Basic understanding of blockchain concepts (wallets, transactions).
- Goal: Understand the role of the
SuiClientin the app architecture.
Introductionโ
In the Sui ecosystem, your app can't speak directly to the blockchain network. It requires an intermediary to handle communication protocols, data fetching, and transaction submission.
The SuiClient is the primary interface in the Sui TypeScript SDK for this purpose.
The architecture: The "Post office" analogyโ
Think of the Sui Network as a massive, global postal system.
- Your App is a customer at the counter.
- The
SuiClientis the Post Office Clerk.
You rely on the clerk to interact with the system. You can't sort the mail or drive the delivery trucks yourself; you must make requests through the clerk.
- Image
- Code
- ASCII
flowchart LR
A["Your App<br/>(Customer)"] -->|Requests Service| B("SuiClient<br/>(Clerk)")
B -->|Processes Request| C["Sui Network Node<br/>(Postal System)"]
C -->|Delivers Result| B
B -->|Hands Over Item| A
โโโโโโโโโโโโโโโโ Requests Service โโโโโโโโโโโโโโโโ Processes Request โโโโโโโโโโโโโโโโโโโโ
โ Your App โโโโโโโโโโโโโโโโโโโบ โ SuiClient โโโโโโโโโโโโโโโโโโโบ โ Sui Network Node โ
โ (Customer) โโโโโโโโโโโโโโโโโโโ โ (Clerk) โโโโโโโโโโโโโโโโโโโ โ (Postal System) โ
โโโโโโโโโโโโโโโโ Hands Over Item โโโโโโโโโโโโโโโโ Delivers Result โโโโโโโโโโโโโโโโโโโโ
Connecting to the networkโ
Just as a clerk works at a specific branch, a SuiClient instance connects to a specific network environment via a Remote Procedure Call (RPC) endpoint.
When you initialize the client, you define which environment it targets:
| Network | Description | Use Case |
|---|---|---|
| Mainnet | The live production network. Real assets, real value. | Production apps. |
| Testnet | Public test network. Mirrors Mainnet versioning. | Staging and integration testing. |
| Devnet | Experimental network. Wiped frequently. | Rapid prototyping and public testing. |
| Localnet | Local test network running on your machine. | Offline development and testing. |
Core capabilitiesโ
The SuiClient handles two distinct categories of operations. Understanding the difference is critical for app design.
1. Read operations (queries)โ
These are requests to look up existing data on the ledger.
- Cost: Free (no gas fees).
- Security: No wallet signature required.
- Mechanism: The client queries the node's local database and returns the result immediately.
- Examples:
getObject(): Fetching non-fungible token (NFT) metadata.getBalance(): Checking a wallet's funds.
2. Write operations (transactions)โ
These are requests to change the state of the ledger.
- Cost: Requires SUI tokens (measured in MIST) for gas fees.
- Security: Requires a cryptographic signature from a user's wallet.
- Mechanism: The client submits the signed transaction through the RPC fullnode, which relays it to the validator network for execution and consensus.
- Examples:
- Transferring coins.
- Minting NFTs.
- Modifying on-chain game data.
Next stepsโ
Now that you understand the architecture, the next step is to perform a Read Operation. The next guide, How to fetch object data, provides a script to query live data from the Sui devnet.