llms.txt
@mysten/sui v2.0 and a new dApp Kit are here! Check out the migration guide
Mysten Labs SDKs
MigrationsMigrate to 2.0

Migrating from JSON-RPC

Move JSON-RPC code, removed in 3.0, to shared gRPC and GraphQL top-level methods

SuiJsonRpcClient was removed in @mysten/sui 3.0. This guide still applies when moving JSON-RPC code to gRPC or GraphQL; see Migrate to 3.0 for the other 3.0 changes.

For most application code, migrate from SuiJsonRpcClient to SuiGrpcClient and call the gRPC client's top-level methods. Use SuiGraphQLClient when the code needs custom indexed queries, historical object versions, or custom GraphQL selection sets. Standard transaction and event queries are available directly on both clients.

Create one client for the transport you want to use. Application code should usually call top-level methods like client.getObject() and client.listTransactions(). SDKs and libraries should accept ClientWithCoreApi and call client.core.<method>().

Choosing a target client

ClientUse For
SuiGrpcClientStandard reads, writes, simulations, transaction/event queries, and streams
SuiGraphQLClientThe same shared methods plus custom indexed queries and historical object versions

Quick migration to gRPC

Replace SuiJsonRpcClient with SuiGrpcClient:

- import { SuiJsonRpcClient, getJsonRpcFullnodeUrl } from '@mysten/sui/jsonRpc';
+ import { SuiGrpcClient } from '@mysten/sui/grpc';

- const client = new SuiJsonRpcClient({
-   url: getJsonRpcFullnodeUrl('mainnet'),
-   network: 'mainnet',
- });
+ const client = new SuiGrpcClient({
+   baseUrl: 'https://fullnode.mainnet.sui.io:443',
+   network: 'mainnet',
+ });

Full node hosts commonly expose both JSON-RPC and gRPC. When migrating, pass the full node endpoint as baseUrl instead of url, and verify the protocol and port used by your node provider.

Use top-level methods in apps

The gRPC and GraphQL clients expose top-level methods for the common client API. These methods use the same options and response shapes as client.core, with transport-specific additions where the transport can expose more data.

This includes transaction and event methods. Use getTransaction, waitForTransaction, listTransactions, and listEvents directly instead of dropping down to a raw gRPC service or a custom GraphQL query for standard queries.

const { object } = await client.getObject({
	objectId: '0x...',
	include: { content: true, display: true },
});

const { balance } = await client.getBalance({
	owner: '0x...',
});

const result = await client.signAndExecuteTransaction({
	transaction,
	signer,
	include: { effects: true, balanceChanges: true },
});

For SDKs and shared libraries, accept ClientWithCoreApi and use client.core so the caller can provide either SuiGrpcClient or SuiGraphQLClient:

import type { ClientWithCoreApi } from '@mysten/sui/client';

export async function readObject(client: ClientWithCoreApi, objectId: string) {
	return client.core.getObject({
		objectId,
		include: { content: true },
	});
}

Method replacements

Replace legacy JSON-RPC method names with the gRPC top-level method when one exists. In SDK code, use the same replacement under client.core.

JSON-RPC MethodApp Code Replacement
getObjectgetObject
multiGetObjectsgetObjects
getOwnedObjectslistOwnedObjects for an exact StructType filter
getCoinslistCoins
getAllBalancesPaginate listBalances and map its normalized response
getBalancegetBalance
getCoinMetadatagetCoinMetadata
getDynamicFieldslistDynamicFields
getDynamicFieldObjectgetDynamicField or getDynamicObjectField, depending on field kind
getTransactionBlockgetTransaction
multiGetTransactionBlocksMultiple getTransaction calls
executeTransactionBlockexecuteTransaction
waitForTransactionwaitForTransaction
dryRunTransactionBlocksimulateTransaction
devInspectTransactionBlocksimulateTransaction with the sender set and checksEnabled: false
queryTransactionBlockslistTransactions
queryEventslistEvents
getNormalizedMoveFunctiongetMoveFunction
getMoveFunctionArgTypesNo direct equivalent; getMoveFunction returns normalized signatures
resolveNameServiceAddressresolveNameServiceAddress (returns { address })
resolveNameServiceNamesNo direct equivalent for listing every name assigned to an address

The JSON-RPC getDynamicFieldObject method returned an object for both field kinds. For a regular dynamic field, it returned the 0x2::dynamic_field::Field<Name, Value> object. For a dynamic object field, it derived the wrapper field, extracted its child ID, and returned the referenced child object instead of the wrapper.

The replacement APIs expose these operations separately. getDynamicField returns a normalized field entry and its BCS-encoded value. getDynamicObjectField derives the wrapper, extracts the child ID, and loads the referenced object. If the field kind is not known in advance, call listDynamicFields and check whether its $kind is DynamicField or DynamicObject. SDKs can call the same methods through client.core.

const page = await client.listDynamicFields({ parentId });

for (const field of page.dynamicFields) {
	if (field.$kind === 'DynamicObject') {
		const { object } = await client.getDynamicObjectField({
			parentId,
			name: field.name,
			include: { content: true },
		});

		console.log(object.objectId, object.content);
	} else {
		const { dynamicField } = await client.getDynamicField({
			parentId,
			name: field.name,
		});

		console.log(dynamicField.value.type, dynamicField.value.bcs);
	}
}

The dynamic object field wrapper remains accessible through getDynamicField. Wrap the name type explicitly and pass the original name BCS bytes:

const { dynamicField } = await client.getDynamicField({
	parentId,
	name: {
		type: `0x2::dynamic_object_field::Wrapper<${fieldName.type}>`,
		bcs: fieldName.bcs,
	},
});

console.log(dynamicField.fieldId, dynamicField.childId);

getMoveFunction exposes normalized parameter signatures, but it does not reproduce the legacy Pure, Object, and object-access classifications from getMoveFunctionArgTypes. Likewise, defaultNameServiceName and raw gRPC nameService.reverseLookupName return only the configured default name; they do not replace the paginated list returned by resolveNameServiceNames. Keep a legacy endpoint or use an application indexer when those exact results are required.

const { address } = await client.resolveNameServiceAddress({
	name: 'example.sui',
});

Protocol config, system state, and the chain identifier are top-level methods too:

const { protocolConfig } = await client.getProtocolConfig();
const { systemState } = await client.getCurrentSystemState();
const { chainIdentifier } = await client.getChainIdentifier();

Object and coin reads

Migrating getObject

getObject throws when the object does not exist or cannot be read, where JSON-RPC returned { error }. Catch ObjectError and check its reason ('notFound', 'deleted' or 'unknown'), or use getObjects, which returns per-object errors in place instead of throwing.

import { ObjectError } from '@mysten/sui/client';

try {
	const { object } = await client.getObject({ objectId });
	console.log(object.version);
} catch (error) {
	if (!(error instanceof ObjectError) || error.reason !== 'notFound') throw error;
	// the object does not exist
}

Migrating getOwnedObjects

- const { data } = await jsonRpcClient.getOwnedObjects({
-   owner: '0xabc...',
-   filter: { StructType: '0x2::coin::Coin<0x2::sui::SUI>' },
-   options: { showContent: true },
- });
+ const { objects } = await client.listOwnedObjects({
+   owner: '0xabc...',
+   type: '0x2::coin::Coin<0x2::sui::SUI>',
+   include: { content: true },
+ });

Only the legacy StructType filter maps directly to listOwnedObjects.type. Legacy package, module, owner, object ID, version, and boolean-composition filters do not have top-level Core equivalents. A custom GraphQL ObjectFilter can cover package, module, and owner-kind cases. For the remaining filters, use an indexer or paginate and filter the normalized results in application code.

Migrating getCoins

- const coins = await jsonRpcClient.getCoins({
-   owner: '0xabc...',
-   coinType: '0x2::sui::SUI',
- });
+ const coins = await client.listCoins({
+   owner: '0xabc...',
+   coinType: '0x2::sui::SUI',
+ });

An account can hold its balance as an address balance with no coin objects, so listCoins can return nothing for an account with funds. Use getBalance or listBalances to read the total.

Migrating getBalance

- const { totalBalance } = await jsonRpcClient.getBalance({ owner: '0xabc...' });
+ const { balance } = await client.getBalance({ owner: '0xabc...' });
+ const totalBalance = balance.balance; // coinBalance + addressBalance

Migrating getAllBalances

Unlike getAllBalances, listBalances is paginated. It also returns normalized balance, coinBalance, and addressBalance fields instead of the legacy CoinBalance shape with coinObjectCount, totalBalance, and lockedBalance. Follow cursor while hasNextPage is true and map the result explicitly if existing code depends on the legacy shape.

Migrating object include options

- const object = await jsonRpcClient.getObject({
-   id: objectId,
-   options: {
-     showBcs: true,
-     showContent: true,
-     showDisplay: true,
-   },
- });
+ const { object } = await client.getObject({
+   objectId,
+   include: {
+     content: true,
+     json: true,
+     display: true,
+   },
+ });

Use include.content for BCS-encoded Move struct bytes. It is the most stable cross-transport shape for parsing application data.

Transaction execution and simulation

Legacy JSON-RPC methods accept serialized transaction blocks as base64 strings. executeTransaction accepts bytes, while simulateTransaction accepts bytes or a Transaction, so decode existing strings before passing them to the new client:

import { Transaction } from '@mysten/sui/transactions';
import { fromBase64 } from '@mysten/sui/utils';

Migrating getTransactionBlock

- const result = await jsonRpcClient.getTransactionBlock({
-   digest,
-   options: {
-     showEffects: true,
-     showEvents: true,
-     showInput: true,
-   },
- });
+ const result = await client.getTransaction({
+   digest,
+   include: {
+     effects: true,
+     events: true,
+     transaction: true,
+   },
+ });

Both SuiGrpcClient and SuiGraphQLClient expose getTransaction. SDKs can make the same request through client.core.getTransaction.

For multiple digests, call the same top-level method for each transaction:

- const results = await jsonRpcClient.multiGetTransactionBlocks({
-   digests,
-   options: { showEffects: true },
- });
+ const results = await Promise.all(
+   digests.map((digest) =>
+     client.getTransaction({
+       digest,
+       include: { effects: true },
+     }),
+   ),
+ );

The raw gRPC ledgerService.batchGetTransactions method remains available when an application specifically needs the transport's batch wire API, but it is not required for ordinary client code.

Migrating executeTransactionBlock

- const result = await jsonRpcClient.executeTransactionBlock({
-   transactionBlock: bytes,
-   signature,
-   options: {
-     showEffects: true,
-     showEvents: true,
-   },
- });
+ const result = await client.executeTransaction({
+   transaction: fromBase64(bytes),
+   signatures: [signature],
+   include: {
+     effects: true,
+     events: true,
+   },
+ });

- const status = result.effects?.status.status;
+ const tx = result.Transaction ?? result.FailedTransaction;
+ const success = tx.status.success;

Migrating signAndExecuteTransaction

- const result = await jsonRpcClient.signAndExecuteTransaction({
-   transaction,
-   signer,
-   options: { showEffects: true },
- });
+ const result = await client.signAndExecuteTransaction({
+   transaction,
+   signer,
+   include: { effects: true },
+ });

+ if (result.$kind === 'FailedTransaction') {
+   throw new Error(result.FailedTransaction.status.error?.message ?? 'Transaction failed');
+ }

Migrating waitForTransaction

- const result = await jsonRpcClient.waitForTransaction({
-   digest,
-   options: { showEffects: true },
-   timeout: 60_000,
-   pollInterval: 2_000,
- });
+ const result = await client.waitForTransaction({
+   digest,
+   include: { effects: true },
+   timeout: 60_000,
+   pollSchedule: [0, 2_000],
+ });

waitForTransaction is a top-level method on both SuiGrpcClient and SuiGraphQLClient. It can also accept the result of executeTransaction or signAndExecuteTransaction through its result option.

Migrating dryRunTransactionBlock

- const result = await jsonRpcClient.dryRunTransactionBlock({
-   transactionBlock: tx,
- });
+ const result = await client.simulateTransaction({
+   transaction: fromBase64(tx),
+   include: {
+     effects: true,
+     balanceChanges: true,
+   },
+ });

Migrating devInspectTransactionBlock

- const result = await jsonRpcClient.devInspectTransactionBlock({
-   sender: '0xabc...',
-   transactionBlock: tx,
- });
- const returnValues = result.results?.[0]?.returnValues;
+ const transaction = Transaction.fromKind(tx);
+ transaction.setSender('0xabc...');
+ const result = await client.simulateTransaction({
+   transaction,
+   checksEnabled: false,
+   include: { commandResults: true },
+ });
+ const returnValues = result.commandResults?.[0]?.returnValues;

Transaction and event queries

listTransactions and listEvents are first-class methods on SuiGrpcClient, SuiGraphQLClient, and the Core API. Application code should call the top-level method on its chosen client. Reusable SDK code should call the same method through client.core.

Migrating queryTransactionBlocks

- const result = await jsonRpcClient.queryTransactionBlocks({
-   filter: { FromAddress: '0xabc...' },
-   options: { showEffects: true },
-   limit: 10,
- });
- const digests = result.data.map((tx) => tx.digest);
+ const page = await client.listTransactions({
+   filter: { sender: '0xabc...' },
+   include: { effects: true },
+   limit: 10,
+   order: 'descending',
+ });
+ const digests = page.transactions.map(
+   (tx) => (tx.Transaction ?? tx.FailedTransaction).digest,
+ );

Common transaction filter mappings:

JSON-RPC FiltergRPC/GraphQL Top-Level Filter
FromAddresssender
MoveFunctionfunction
ToAddress, FromOrToAddressaffectedAddress: transactions the address sent or paid gas for, or that changed its objects or balance. Unlike ToAddress, it also returns transactions the address sent.
ChangedObject, AffectedObjectaffectedObject
CheckpointstartCheckpoint / endCheckpoint. endCheckpoint is exclusive, so { Checkpoint: n } becomes startCheckpoint: n, endCheckpoint: BigInt(n) + 1n

The response contains normalized transaction results plus ledger-position cursors:

for (const result of page.transactions) {
	const transaction = result.Transaction ?? result.FailedTransaction;
	console.log(transaction.digest, result.$kind);
}

const nextPage = page.hasNextPage
	? await client.listTransactions({
			filter: { sender: '0xabc...' },
			include: { effects: true },
			before: page.endCursor,
			limit: 10,
		})
	: null;

The legacy JSON-RPC transaction and event queries default to descending order, while listTransactions and listEvents default to ascending order. Pass order: 'descending' when preserving the legacy default.

Migrating queryEvents

- const result = await jsonRpcClient.queryEvents({
-   query: { MoveEventType: '0x2::coin::CoinCreated' },
-   limit: 10,
-   order: 'descending',
- });
+ const result = await client.listEvents({
+   filter: { eventType: '0x2::coin::CoinCreated' },
+   limit: 10,
+   order: 'descending',
+ });
+ for (const event of result.events) {
+   console.log(event.eventType, event.transactionDigest, event.json);
+ }

Common event filter mappings:

JSON-RPC FiltergRPC/GraphQL Top-Level Filter
Sendersender
MoveModuleemitModule: 'package::module'
MoveEventModuleeventType: 'package::module'
MoveEventTypeeventType: 'package::module::Event'

emitModule matches the package version and module of the transaction's Move call that emitted the event, so after an upgrade it needs the new version's ID. Filter by eventType to match events from every version: a type keeps the ID of the package version that defined it, so only a type added in an upgrade carries that upgrade's ID.

Event fields map as follows:

JSON-RPC fieldEvent field
id.txDigesttransactionDigest
id.eventSeq (string)eventIndex (number)
typeeventType
transactionModulemodule
parsedJsonjson
bcs (encoded string)bcs (Uint8Array)
timestampMsNone; use checkpoint and listCheckpoints
packageId, senderUnchanged

The top-level query methods handle pagination and cursor normalization. They also accept combined predicates, affectedAddress and affectedObject filters, and startCheckpoint/endCheckpoint ranges (see Querying). For filters beyond that, such as OR or negated predicates, use the raw ledgerService on SuiGrpcClient or a custom GraphQL query.

Use after: result.endCursor to continue an ascending query and before: result.endCursor to continue a descending query. startCursor identifies the first item in a page and can be used with after to poll for newer transactions or events.

Native gRPC replacements

Some JSON-RPC methods map to gRPC service clients rather than top-level methods:

JSON-RPC MethodgRPC Replacement
getCheckpointledgerService.getCheckpoint
getCheckpointsclient.listCheckpoints for summaries; ledgerService.listCheckpoints for full checkpoint contents
getLatestCheckpointSequenceNumberclient.listCheckpoints({ order: 'descending', limit: 1 }), then read sequenceNumber
getCurrentEpochledgerService.getEpoch with no epoch argument
getCommitteeInfoledgerService.getEpoch with committee in the read mask
getLatestSuiSystemStateclient.getCurrentSystemState or ledgerService.getEpoch
getProtocolConfigclient.getProtocolConfig or ledgerService.getEpoch
getTotalSupplystateService.getCoinInfo and read treasury.totalSupply
getNormalizedMoveModulemovePackageService.getPackage
getNormalizedMoveModulesByPackagemovePackageService.getPackage
getNormalizedMoveStructmovePackageService.getDatatype
import { SuiGrpcClient } from '@mysten/sui/grpc';

const client = new SuiGrpcClient({
	baseUrl: 'https://fullnode.mainnet.sui.io:443',
	network: 'mainnet',
});

const {
	checkpoints: [latest],
} = await client.listCheckpoints({ order: 'descending', limit: 1 });

// The summary has no transactions; read them from the full checkpoint.
const { response } = await client.ledgerService.getCheckpoint({
	checkpointId: { oneofKind: 'sequenceNumber', sequenceNumber: BigInt(latest.sequenceNumber) },
	readMask: { paths: ['transactions.digest'] },
});

console.log(response.checkpoint?.transactions.map((transaction) => transaction.digest));

Subscriptions

Replace JSON-RPC websocket subscriptions with ledger streams, available on both clients. They take the same filters as listTransactions and listEvents, reconnect automatically, and resume from a saved token:

JSON-RPC MethodReplacement
subscribeTransactionstreamTransactions
subscribeEventstreamEvents
for await (const frame of client.streamEvents({
	filter: { eventType: '0x2::coin::CoinCreated' },
})) {
	console.log(frame.event.eventType, frame.event.json, frame.resumeToken);
}

For filters the Core API does not express, SuiGrpcClient streams accept a native gRPC filter as grpcFilter (see gRPC options). The raw subscriptionService remains available; see Subscriptions.

When to use GraphQL

Use SuiGraphQLClient when the replacement needs a custom indexed query, a historical object version, or a custom selection set. Standard transaction and event history does not require a custom GraphQL query; call graphqlClient.listTransactions() or graphqlClient.listEvents() directly.

JSON-RPC MethodAlternative
getEpochsGraphQL epochs query
tryGetPastObjectGraphQL object(address:, version:) query
getStakesNo current gRPC/Core/GraphQL equivalent; use a staking indexer
getStakesByIdsNo current gRPC/Core/GraphQL equivalent; use a staking indexer
getNetworkMetricsUse an indexer or analytics-specific GraphQL schema
getAddressMetricsUse an indexer or analytics-specific GraphQL schema
getMoveCallMetricsUse an indexer or analytics-specific GraphQL schema
import { SuiGraphQLClient } from '@mysten/sui/graphql';
import { graphql } from '@mysten/sui/graphql/schema';

const graphqlClient = new SuiGraphQLClient({
	url: 'https://graphql.mainnet.sui.io/graphql',
	network: 'mainnet',
});

const historicalObjectQuery = graphql(`
	query GetObjectAtVersion($id: SuiAddress!, $version: UInt53!) {
		object(address: $id, version: $version) {
			address
			version
			digest
			asMoveObject {
				contents {
					type {
						repr
					}
					bcs
				}
			}
		}
	}
`);

const result = await graphqlClient.query({
	query: historicalObjectQuery,
	variables: {
		id: '0x123...',
		version: 42,
	},
});

Validator APY

There is no direct SDK replacement for getValidatorsApy. There is no canonical definition of validator APY, so compute the metric from validator staking-pool exchange rates or use an application-specific indexer.

Two reference implementations:

Treat whichever formula you adopt as a definition of validator APY, not the definition.

Response format differences

gRPC and GraphQL top-level methods return the Core API response format, which differs from legacy JSON-RPC response shapes.

// Transaction result access
- const status = result.effects?.status?.status;
+ const tx = result.Transaction ?? result.FailedTransaction;
+ const success = tx.status.success;

// Include options
- { showEffects: true, showEvents: true }
+ { effects: true, events: true }

See the @mysten/sui migration guide for transaction executor response changes.

Client extensions

Client extensions work with SuiGrpcClient and any client that implements ClientWithCoreApi:

import { deepbook } from '@mysten/deepbook-v3';
import { suins } from '@mysten/suins';
import { SuiGrpcClient } from '@mysten/sui/grpc';

const client = new SuiGrpcClient({
	baseUrl: 'https://fullnode.mainnet.sui.io:443',
	network: 'mainnet',
}).$extend(deepbook({ address: myAddress }), suins());

await client.deepbook.checkManagerBalance(manager, asset);
await client.suins.getNameRecord('example.sui');

See also

On this page