Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt

Use this file to discover all available pages before exploring further.

getSuiClient

Retrieves a SuiClient instance from a wallet account, allowing you to interact with the Sui blockchain.

Usage

import { getSuiClient, isSuiWalletAccount } from "@dynamic-labs-sdk/sui";
import { getPrimaryWalletAccount } from "@dynamic-labs-sdk/client";

const walletAccount = getPrimaryWalletAccount();

if (walletAccount && isSuiWalletAccount(walletAccount)) {
  const suiClient = await getSuiClient({ walletAccount });

  // Use the client to interact with the Sui blockchain
  const balance = await suiClient.getBalance({
    owner: walletAccount.address,
  });

  console.log("Balance:", balance);
}

Parameters

ParameterTypeDescription
walletAccountSuiWalletAccountThe wallet account to get the Sui client for
clientDynamicClient (optional)The Dynamic client instance. Only required when using multiple clients.

Returns

Promise<SuiClient> - A promise that resolves to a SuiClient instance from @mysten/sui.

Errors

ErrorDescription
NotSuiProviderErrorThrown if the wallet account’s provider is not a Sui provider

React

import { getSuiClient, isSuiWalletAccount } from '@dynamic-labs-sdk/sui';
import { useWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
import { useEffect, useState } from 'react';

function SuiBalance() {
  const walletAccounts = useWalletAccounts();
  const walletAccount = walletAccounts.find(isSuiWalletAccount);
  const [balance, setBalance] = useState(null);

  useEffect(() => {
    if (!walletAccount) return;
    getSuiClient({ walletAccount }).then(async (client) => {
      const bal = await client.getBalance({ owner: walletAccount.address });
      setBalance(bal);
    });
  }, [walletAccount]);

  return <p>SUI balance: {balance?.totalBalance ?? '...'}</p>;
}