UNPKG

@mysten/sui

Version:
94 lines (66 loc) 3.56 kB
# Sui Clients > Choose and configure gRPC, GraphQL, or JSON-RPC clients The Sui TypeScript SDK provides multiple client implementations for interacting with the Sui network. Each client connects to a different API but provides two levels of access: - **Native API** - Full access to everything the underlying API offers - **[Core API](/sui/clients/core)** - A consistent interface across all clients for common operations ## Available Clients | Client | API | | ------------------------------------------------------ | ------------------------------------------------------------------ | | [SuiGrpcClient](/sui/clients/grpc) (recommended) | [Full Node gRPC](https://docs.sui.io/references/fullnode-protocol) | | [SuiGraphQLClient](/sui/clients/graphql) | [GraphQL](https://docs.sui.io/references/sui-graphql) | | [SuiJsonRpcClient](/sui/clients/json-rpc) (deprecated) | [JSON-RPC (deprecated)](https://docs.sui.io/sui-api-ref) | All clients are compatible with Mysten SDKs like `@mysten/walrus`, `@mysten/seal` and `@mysten/suins`. For most application gRPC is a good default. The JSON RPC API has been deprecated and will be decommissioned soon. The GraphQL can be used for more advanced query patterns that can not be supported directly on full nodes (eg, querying for transactions or events with various filters). ## Quick Start ```typescript const client = new SuiGrpcClient({ network: 'mainnet', baseUrl: 'https://fullnode.mainnet.sui.io:443', }); // Use the native API for full access to transport-specific features const { response } = await client.ledgerService.getTransaction({ digest: '0x...' }); // Use the Core API for transport-agnostic operations const { object } = await client.core.getObject({ objectId: '0x...' }); ``` ## Native vs Core API ### Native API Each client exposes the full capabilities of its underlying transport. Use the native API when you need transport-specific features or want maximum control: ```typescript // gRPC - access various service clients to call any gRPC method const { response } = await grpcClient.stateService.listOwnedObjects({ owner: '0x...' }); // GraphQL - write type-safe custom queries using the graphql function const result = await graphqlClient.query({ query: graphql(` query { chainIdentifier } `), }); // JSON-RPC - call any JSON-RPC method const coins = await jsonRpcClient.getCoins({ owner: '0x...' }); ``` ### Core API All clients also implement the [Core API](/sui/clients/core) through `client.core`. This provides a consistent interface for common operations that works identically across all transports: ```typescript // These methods work the same on any client const { object } = await client.core.getObject({ objectId: '0x...' }); const balance = await client.core.getBalance({ owner: '0x...' }); await client.core.executeTransaction({ transaction, signatures }); ``` The Core API is essential for [building SDKs](/sui/sdk-building) that work with any client the user chooses. ## Client Extensions All clients support extensions through the `$extend` method, enabling SDKs like [@mysten/walrus](https://www.npmjs.com/package/@mysten/walrus) to add functionality: ```typescript const client = new SuiGrpcClient({ network: 'mainnet', baseUrl: '...' }).$extend(walrus()); await client.walrus.writeBlob({ ... }); ``` See [Building SDKs](/sui/sdk-building) for more on creating client extensions.