Sui utilities for TypeScript, Node, and React.
The suitcase-core package provides utilities for all TypeScript environments (browser, server, etc).
- Installation:
pnpm add @polymedia/suitcase-core - Source code: src/core
generateRandomAddress()- Generate a random Sui address (for development only).removeAddressLeadingZeros()- Remove leading zeros from a Sui address (lossless).shortenAddress()- Abbreviate a Sui address for display purposes (lossy).validateAndNormalizeAddress()- Validate a Sui address and return its normalized form, ornullif invalid.
apiRequestIndexer()- Make a request to the Indexer.xyz API (NFTs).
balanceToString()- Convert a bigint to a string, scaled down to the specified decimals.stringToBalance()- Convert a string to a bigint, scaled up to the specified decimals.formatBalance()- Format a bigint into a readable string, scaled down to the specified decimals.formatNumber()- Format a number into a readable string.
-
class SuiClientBase- Abstract class for building Sui SDK clients.fetchAndParseObjs()- Fetch and parse objects from the RPC and cache them.fetchAndParseTxs()- Fetch and parse transactions from the RPC.signTx()- Sign a transaction.executeTx()- Execute a transaction.signAndExecuteTx()- Sign and execute a transaction.
-
class SuiEventFetcher- Fetch Sui events and parse them into custom objects.fetchEvents()- Fetch the latest events. Every time the function is called it looks for events that took place since the last call.
-
class SuiMultiClient- Make many RPC requests using multiple endpoints.executeInBatches()- ExecuteSuiClientRPC operations in parallel using multiple endpoints.testEndpoints()- Test the latency of various Sui RPC endpoints.
devInspectAndGetExecutionResults()- CallSuiClient.devInspectTransactionBlock()and return the execution results.devInspectAndGetReturnValues()- CallSuiClient.devInspectTransactionBlock()and return the deserialized return values.fetchDynamicFields()- Get dynamic object fields owned by an object. If limit is not specified, fetch all DOFs.getCoinOfValue()- Get aCoin<T>of a given value from the owner. Handles coin merging and splitting.getSuiObjectRef()- Fetch the latest version of an object and return itsSuiObjectRef.
class CoinMetaFetcher- Fetch coin metadata from the RPC and cache it.getCoinMeta()- Fetch metadata for a single coin.getCoinMetas()- Fetch metadata for multiple coins.
type CoinMeta- LikeCoinMetadatafrom@mysten/sui, but includes the cointype.
const MAX_U64- The maximum value for a 64-bit unsigned integer.const NORMALIZED_0x0_ADDRESS- The normalized 0x0 address (0x000…000).const NORMALIZED_SUI_TYPE- The normalized SUI type (0x000…002::sui::SUI).const REGEX_ADDRESS- Match a Sui address.const REGEX_ADDRESS_NORMALIZED- Match a normalized Sui address.const REGEX_MODULE_NAME- Match a Sui module name.const REGEX_STRUCT_NAME- Match a Sui struct name.const REGEX_TYPE_BASIC- Match a Sui type without generic parameters (e.g.0x123::module::Struct).const RPC_QUERY_MAX_RESULTS- Maximum number of results returned by a single Sui RPC request.
anyToStr()- Attempts to convert any kind of value into a readable string.parseMoveAbort()- Parse a Move abort string into its different parts.class TxErrorParser- Parse transaction errors and convert them into user-friendly messages.
requestSuiFromFaucet()- Get SUI from the faucet on localnet/devnet/testnet.
formatBps()- Return a human-readable string from a number of basis points.formatDate()- Return a human-readable date string from a timestamp in milliseconds.formatDuration()- Return a human-readable string from a number of milliseconds.formatTimeDiff()- Return a human-readable string with the time difference between two timestamps.urlToDomain()- Return the domain from a URL.shortenDigest()- Return a shortened version of a transaction digest.
chunkArray()- Split an array into multiple chunks of a certain size.chunkString()- Split a string into multiple chunks of a certain size.makeRanges()- Generate an array of ranges of a certain size between two numbers.sleep()- Wait for a number of milliseconds.
pairFromSecretKey()- Build aKeypairfrom a secret key string likesuiprivkey1....
type ObjectDisplay- A Sui object display with common properties and arbitrary ones.objResToBcs()- Validate aSuiObjectResponseand return its.data.bcs.bcsBytes.objResToContent()- Validate aSuiObjectResponseand return its.data.content.objResToDisplay()- Validate aSuiObjectResponseand return its.data.display.dataornull.newEmptyDisplay()- Create anObjectDisplayobject with all fields set tonull.
objResToFields()- Validate aSuiObjectResponseand return its.data.content.fields.objResToId()- Validate aSuiObjectResponseand return its.data.objectId.objResToOwner()- Validate aSuiObjectResponseand return its owner: an address, object ID, "shared" or "immutable".objResToRef()- Validate aSuiObjectResponseand return its{.data.objectId, .data.digest, .data.version}.
const RPC_ENDPOINTS- A list of public RPCs for Sui mainnet, testnet, and devnet.measureRpcLatency()- Measure Sui RPC latency by making requests to various endpoints.newLowLatencySuiClient()- Instantiate SuiClient using the RPC endpoint with the lowest latency.
type NestedResult- An item in the array returned by aTransaction.moveCall()call.type ObjectInput- Either aTransactionObjectInputor aSuiObjectRef.type SignTx- A function that can sign aTransaction.getArgVal<T>()- Get the value of aSuiCallArg(transaction input). If the argument is a pure value, return it. If the argument is an object, return its ID.newSignTx()- Create aSignTxfunction that uses aSignerto sign aTransaction.newSignAndExecuteTx()- Create a function that signs and executes aTransaction.objectArg()- Transform anObjectInputinto an argument forTransaction.moveCall().txResToData()- Validate aSuiTransactionBlockResponseof theProgrammableTransactionkind and return its.transaction.data.TransferModule- Build transactions for thesui::transfermodule.public_freeze_object()public_share_object()public_transfer()
type OwnerKind<K>- AnObjectOwnerof a specific kind.isOwnerKind()- Type guard to check if anObjectOwneris of a specific kind.
type ArgKind<K>- ASuiArgumentof a specific kind.isArgKind()- Type guard to check if aSuiArgumentis of a specific kind.
type ObjChangeKind<K>- ASuiObjectChangeof a specific kind.isObjChangeKind()- Type guard to check if aSuiObjectChangeis of a specific kind.
isSuiObjectRef()- Type guard to check if an object is aSuiObjectRef.
type ParsedDataKind<K>- ASuiParsedDataof a specific kind.isParsedDataKind()- Type guard to check if aSuiParsedDatais of a specific kind.
type TxKind<K>- ASuiTransactionof a specific kind.isTxKind()- Type guard to check if aSuiTransactionis of a specific kind.
const NETWORK_NAMES-["mainnet", "testnet", "devnet", "localnet"].type NetworkName-"mainnet" | "testnet" | "devnet" | "localnet".type PaginatedResponse<T>- A paginated response from a Sui RPC call.type ReceivingRef- The return type ofTransaction.receivingRef().
type SuiExplorerItem- A Sui explorer item type (address/object/package/tx/coin).makePolymediaUrl()- Build an explorer.polymedia.app URL.makeSuiscanUrl()- Build a suiscan.xyz URL.makeSuivisionUrl()- Build a suivision.xyz URL.
The suitcase-node package provides utilities for Node.js projects (command line tools, server side code, etc).
- Installation:
pnpm add @polymedia/suitcase-node - Source code: src/node
getActiveAddress()- Get the current active address (sui client active-address).getActiveKeypair()- Build aEd25519Keypairobject for the current active address by loading the secret key from~/.sui/sui_config/sui.keystore.getActiveEnv()- Get the active Sui environment fromsui client active-env.setupSuiTransaction()- Initialize objects to execute Sui transactions blocks using the current Sui active network and address.executeSuiTransaction()- Execute a transaction block withshowEffectsandshowObjectChangesset totrue.
fileExists()- Check if a file exists in the filesystem.getFileName()- Extract the file name from a module URL, without path or extension.readCsvFile()- Read a CSV file and parse each line into an object.readJsonFile()- Read a JSON file and parse its contents into an object.readTsvFile()- Read a TSV file and parse each line into an object.writeCsvFile()- Write objects into a CSV file.writeJsonFile()- Write an object's JSON representation into a file.writeTextFile()- Write a string into a file.writeTsvFile()- Write objects into a TSV file.
parseArguments()- Parse command line arguments and show usage instructions.promptUser()- Display a query to the user and wait for their input. Return true if the user entersy.suppressSuiVersionMismatchWarnings()- Suppress "Client/Server api version mismatch" warnings.
The suitcase-react package provides components for React web apps.
- Installation:
pnpm add @polymedia/suitcase-react - Source code: src/react
