Suiet Wallet Kit

repository·main·Indexed 41 days ago

https://github.com/suiet/wallet-kit

A React-based toolkit for simplifying wallet connectivity for DApps on the Sui network. It leverages the Sui Wallet Standard for automatic wallet detection and provides a suite of React Providers, hooks (such as useAccountBalance and useSuinsName), and UI components like ConnectButton, ConnectModal, and WalletInfo. The package also includes @suiet/wallet-sdk, a platform-agnostic JavaScript SDK for interacting with Sui wallets.

Tokens
38.2K
Snippets
109
Records
155
Agent score
53%

What's inside Suiet Wallet Kit

  1. Overview of Suiet wallet sdk

    main
    The @suiet/wallet-sdk provides easy-to-use utilities for interacting with Sui wallets. It is designed using JavaScript Object-Oriented Programming (OOP) principles and is platform and framework agnostic, meaning it can be used in various environments (browser, Node.js, etc.) and with different frontend frameworks.
  2. Overview of Suiet wallet kit

    main

    Suiet wallet kit is a React toolkit designed for DApps to interact with Sui wallets easily. It provides React Providers, Hooks, and UI components to facilitate connections between DApps and wallet extensions.

    Key features include:

    • Sui Wallet Standard Support: Automatically detects all installed wallets in a user's browser that implement the Sui Wallet Standard, eliminating the need to manually import specific wallet adapters.
    • Integration & Customization: Offers both ready-to-use integration solutions and hooks for custom implementations.
  3. Handle Sui Wallet rebranding to Slush Wallet

    main

    Due to rebranding in the Sui ecosystem, the Suiet Wallet Kit has updated its terminology and presets.

    • Sui Wallet extension is now Slush Wallet.
    • Stashed Web Wallet is now Slush Web Wallet.

    To accommodate these changes, the wallet kit now includes Slush Wallet in its presets and provides a new hook for registering the web wallet.

  4. Understand the JsonRpcProvider vs Sui JSON-RPC

    main

    The JsonRpcProvider interface (accessed via useSuiProvider) is a thin wrapper around the low-level Sui JSON-RPC API.

    • Sui JSON-RPC: A low-level API where you must manually specify the RPC endpoint and the exact request/response structure for each method (e.g., using cURL).
    • JsonRpcProvider: Provides a high-level developer experience with useful methods and strong TypeScript typings, abstracting away the raw RPC details.
  5. Handle Kit and Wallet errors

    main

    Errors in the Sui SDK follow a BaseError structure, which includes a message, a code (of type ErrorCode), and optional details.

    There are two main error categories:

    1. KitError: Errors originating from the internal logic of the @suiet/wallet-kit.
    2. WalletError: Errors originating from third-party wallet providers.
  6. Recommended transaction workflow for DApps

    main

    The recommended workflow for executing transactions has shifted to prioritize low latency and data consistency by moving execution from the wallet to the DApp. This approach supports the ecosystem's migration toward GraphQL and indexer-backed APIs.

    The recommended flow:

    1. Construct: Build the transaction using the Transaction builder API.
    2. Sign: Sign the transaction using the sui:signTransaction feature. The Wallet Kit automatically manages whether to call sui:signTransaction or sui:signTransactionBlock based on the wallet's implementation.
    3. Execute: The DApp executes the transaction using its own RPC provider (GraphQL or JSON-RPC). This avoids the latency and synchronization issues of using the wallet's RPC.
    4. Report: The DApp invokes the sui:reportTransactionEffects feature with the transaction effects after successful execution. This allows wallets to cache effects, ensuring transaction building continues even if the wallet's RPC node hasn't indexed the transaction yet.
  7. Understand the BEM naming rule for Suiet Wallet Kit CSS

    main

    The Suiet Wallet Kit uses the BEM (Block Element Modifier) naming convention for its CSS classes. This ensures consistent and predictable styling. The structure follows the pattern: .wkit-[block]__[element]--[modifier].

    To target a specific block, use the wkit- prefix followed by the block name. For example, to style a button, use the class wkit-button.

    <div className="wkit-button">...</div>
  8. Integrate a wallet with Suiet Kit

    main

    To ensure your wallet is auto-detected and recognized as a standard wallet by the Suiet Kit, your wallet adapter must support @mysten/wallet-standard v0.5.0 or higher.

    Specifically, your adapter must implement the following features:

    • standard:connect
    • standard:events
    • sui:signAndExecuteTransactionBlock
    // a valid wallet adapter should have the following features
    {
      // ...
      features: {
        "standard:connect": () => {},
        "standard:events": () => {},
        "sui:signAndExecuteTransactionBlock": () => {},
      }
    }
  9. Customize components for dark mode using CSS variables

    main

    You can customize the theme of @suiet/wallet-kit components to support dark mode by overriding color-related CSS variables.

    To support users who have dark mode enabled at the system level, wrap your variable overrides in the @media (prefers-color-scheme: dark) media query. Alternatively, you can use the [data-theme='dark']:root selector if your application manages theme state via a data attribute.

    Important: Your dark mode CSS rules must be imported or declared AFTER the default @suiet/wallet-kit CSS file to ensure your overrides take precedence.

    @media (prefers-color-scheme: dark) {
      :root {
        --wkit-accent-hs: 166, 91%;
        --wkit-on-accent-rgb: 255, 255, 255;
        --wkit-bg-rgb: 40, 40, 40;
        --wkit-on-bg-rgb: 241, 241, 241;
      }
    }
  10. Display and format connected wallet information

    main

    When displaying wallet information in your UI, you can use the following patterns:

    1. Connection Status: Access wallet.status to show if the user is connected.
    2. Account Address: Use wallet.account.address to get the full hex string. To avoid UI clutter, use the addressEllipsis utility function to show a shortened version (e.g., 0x123...abcd).
    3. Chain/Network: Access wallet.chain.name to identify which Sui network (e.g., mainnet, testnet, devnet) the wallet is currently using.
    import {
      useWallet,
      addressEllipsis,
    } from "@suiet/wallet-kit";
    
    export default function App() {
      const wallet = useWallet();
    
      return (
        <div>
          <p>Status: {wallet.status}</p>
          {wallet?.account && (
            <p>Address: {addressEllipsis(wallet.account.address)}</p>
          )}
          <p>Network: {wallet.chain.name}</p>
        </div>
      );
    }