### Install Sui SDK Dependency
Source: https://kit.suiet.app/docs/QuickStart
Installs the `@mysten/sui` package, which is a required dependency for interacting with the Sui blockchain. Ensure this is installed alongside the wallet kit.
```shell
npm install @mysten/sui
```
```shell
yarn add @mysten/sui
```
```shell
pnpm install @mysten/sui
```
--------------------------------
### Install Suiet Wallet Kit
Source: https://kit.suiet.app/docs/QuickStart
Installs the `@suiet/wallet-kit` npm package using npm, yarn, or pnpm. This is the first step to integrate Suiet Wallet Kit into your project.
```shell
npm install @suiet/wallet-kit
```
```shell
yarn add @suiet/wallet-kit
```
```shell
pnpm install @suiet/wallet-kit
```
--------------------------------
### Interact with Wallet Capabilities
Source: https://kit.suiet.app/docs/QuickStart
Shows how to use the `useWallet` hook to access connected wallet information and perform actions like signing messages or executing transactions. It includes examples for `signAndExecuteTransaction` and `signPersonalMessage`.
```javascript
import { useWallet } from '@suiet/wallet-kit';
import { Transaction } from "@mysten/sui/transactions";
import { useEffect } from 'react';
const App = () => {
const wallet = useWallet();
useEffect(() => {
if (!wallet.connected) return;
console.log('connected wallet name: ', wallet.name);
console.log('account address: ', wallet.account?.address);
console.log('account publicKey: ', wallet.account?.publicKey);
}, [wallet.connected]);
// Launch a move call for the connected account via wallet
async function handleMoveCall() {
const tx = new Transaction();
const packageObjectId = "0x1";
tx.moveCall({
target: `${packageObjectId}::nft::mint`,
arguments: [tx.pure.string("Example NFT")],
});
await wallet.signAndExecuteTransaction({ transaction: tx });
}
// Launch a move call for the connected account via wallet
async function handleSignMessage() {
await wallet.signPersonalMessage({
message: new TextEncoder().encode("Hello World"),
});
}
return (
<>
{/* Your UI elements */}
>
);
};
```
--------------------------------
### Install Suiet Wallet Kit and Sui SDK
Source: https://kit.suiet.app/docs/tutorial/connect-dapp-with-wallets
Installs the necessary packages for Suiet Wallet Kit and the official Typescript SDK `@mysten/sui` using npm. This is a prerequisite for integrating wallet functionality into a DApp.
```bash
npm install @mysten/sui @suiet/wallet-kit
```
--------------------------------
### Install Suiet Wallet Kit v0.1.0
Source: https://kit.suiet.app/docs/category/migration
Command to install version 0.1.0 of the Suiet Wallet Kit. This is useful for users needing to revert to or test compatibility with this specific older version.
```bash
npm install @suiet/wallet-kit@0.1
```
--------------------------------
### Basic ConnectButton Usage in React
Source: https://kit.suiet.app/docs/components/ConnectButton
Demonstrates the basic integration of the `ConnectButton` component within a `WalletProvider` context. This setup allows users to initiate wallet connections easily. Ensure `@suiet/wallet-kit` is installed and imported correctly.
```javascript
import { ConnectButton, WalletProvider } from '@suiet/wallet-kit';
function App() {
return (
Connect Wallet
);
}
```
--------------------------------
### Use ConnectButton Component
Source: https://kit.suiet.app/docs/QuickStart
Demonstrates how to easily integrate the `ConnectButton` component into your React application's UI. This button handles wallet connection and disconnection flows.
```javascript
import { ConnectButton } from '@suiet/wallet-kit';
const App = () => {
return (
<>
{/* ... rest of your app */}
>
);
};
```
--------------------------------
### Wrap App with WalletProvider
Source: https://kit.suiet.app/docs/QuickStart
Wraps your main React application component with `WalletProvider` to enable wallet functionalities. It also includes importing the default Suiet CSS for styling.
```javascript
import { WalletProvider } from '@suiet/wallet-kit';
import '@suiet/wallet-kit/style.css';
// For React 18 projects
ReactDOM.createRoot(document.getElementById('root')).render(
);
```
--------------------------------
### Wrap App with WalletProvider
Source: https://kit.suiet.app/docs/tutorial/hooks-only
Demonstrates how to wrap the main application component with `WalletProvider` to provide context for wallet data and functions. This is the initial setup step for using Suiet Kit hooks.
```javascript
import{WalletProvider}from'@suiet/wallet-kit';
functionRootComponent(){
return(
);
}
```
--------------------------------
### ConnectModal Usage Example
Source: https://kit.suiet.app/docs/components/ConnectModal
Demonstrates how to use the ConnectModal component with a custom trigger button. It shows how to manage the modal's open state and handle connection events. This example assumes you have a custom button component named 'YourOwnButton'.
```javascript
import { useWallet, ConnectModal } from '@suiet/wallet-kit';
import { useState } from 'react';
function App() {
const { connected } = useWallet();
const [showModal, setShowModal] = useState(false);
if (connected) {
return ;
}
return (
// wrap your own button as the trigger of the modal
setShowModal(open)}
>
);
}
```
--------------------------------
### Setup WalletProvider in React App
Source: https://kit.suiet.app/docs/tutorial/connect-dapp-with-wallets
Wraps the main React application with the `WalletProvider` from `@suiet/wallet-kit`. This makes wallet states and functions accessible throughout the application, enabling wallet interactions.
```javascript
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { WalletProvider } from "@suiet/wallet-kit";
import App from "./App";
const rootElement = document.getElementById("root");
const root = createRoot(rootElement);
// wrap your app with WalletProvider
root.render(
);
```
--------------------------------
### Comprehensive Error Handling Example
Source: https://kit.suiet.app/docs/Hooks/useSuinsName
An example combining the retrieval of the default name, loading state, and error handling. It prioritizes displaying an error message if resolution fails, otherwise shows the loading state or the resolved name.
```javascript
const{ defaultName, loading, error }=useSuinsName({ address, chain });
if(error){
// Log error for debugging but show user-friendly message
console.error('SuiNS resolution failed:', error);
returnName unavailable;
}
if(loading){
return Loading...;
}
return {defaultName || 'No name found'};
```
--------------------------------
### IDefaultWallet Example
Source: https://kit.suiet.app/docs/Types
Demonstrates how to create a custom wallet object conforming to the IDefaultWallet interface. It shows importing the type and assigning values to its properties.
```typescript
import IDefaultWallet from"@suiet/wallet-kit";
const myWallet: IDefaultWallet ={
name:"myWallet",
iconUrl:"external url or data url",
downloadUrl:{
browserExtension:"chrome extension store url...",
},
};
```
--------------------------------
### Basic Usage: WalletProvider in React
Source: https://kit.suiet.app/docs/components/WalletProvider
Demonstrates the fundamental way to integrate the WalletProvider into a React application. It shows how to import the provider and wrap the root component to make wallet functionalities available throughout the dApp. This setup is essential before using any other Suiet Kit hooks or components.
```javascript
import ReactDOM from 'react-dom';
import { WalletProvider } from '@suiet/wallet-kit';
function App() {
// Your application components
return (
My Suiet App
{/* Other components using Suiet Kit */}
);
}
function Root() {
// Wrap your app component with WalletProvider
return (
);
}
ReactDOM.render(, document.getElementById('root'));
```
--------------------------------
### Sign Transaction with useWallet Hook
Source: https://kit.suiet.app/docs/migration/upgradeTo0.2
Demonstrates how to use the new `signTransaction` method from the `useWallet` hook to sign a transaction block. This feature allows Dapp developers to obtain signatures for transactions.
```javascript
async function handleSignTransaction() {
const tx = new TransactionBlock();
tx.moveCall({
target: '0x2::nft::mint',
arguments: [
tx.pure('name'),
tx.pure('capy'),
tx.pure('https://cdn.britannica.com/94/194294-138-B2CF7780/overview-capybara.jpg?w=800&h=450&c=crop'),
],
});
// get the signature of the transaction
const { signature, transactionBytes } = await wallet.signTransactionBlock({
transactionBlock: tx,
});
}
```
--------------------------------
### Sign and Verify Personal Message
Source: https://kit.suiet.app/docs/Hooks/useWallet
Demonstrates how to sign a personal message using the wallet and then verify the signature. It highlights the use of TextEncoder for converting strings to Uint8Array, which is the required input format for signing operations. The example includes error handling for failed operations.
```javascript
import { useWallet } from '@suiet/wallet-kit';
import * as tweetnacl from 'tweetnacl';
function App() {
const wallet = useWallet();
async function handleSignMsg() {
try {
const msg = 'Hello world!';
// convert string to Uint8Array
const msgBytes = new TextEncoder().encode(msg);
const result = await wallet.signPersonalMessage({
message: msgBytes
});
// directly input the signed result for verification
const verifyResult = await wallet.verifySignedPersonalMessage(result);
if (!verifyResult) {
console.log('signPersonalMessage succeed, but verify signedMessage failed');
} else {
console.log('signPersonalMessage succeed, and verify signedMessage succeed!');
}
} catch (e) {
console.error('signPersonalMessage failed', e);
}
}
return (
);
}
```
--------------------------------
### Get Wallet Info with useWallet
Source: https://kit.suiet.app/docs/Hooks/useWallet
Demonstrates how to use the `useWallet` hook to retrieve the connection status, name, and account details of a connected Sui wallet. This is a fundamental step for interacting with the Sui blockchain via Suiet Kit.
```typescript
import { useWallet } from '@suiet/wallet-kit';
function App() {
const wallet = useWallet();
console.log('wallet status', wallet.status);
console.log('connected wallet name', wallet.name);
console.log('connected account info', wallet.account);
}
```
--------------------------------
### Executing Transactions with JsonRpcProvider
Source: https://kit.suiet.app/docs/Hooks/useSuiprovider
Illustrates a practical example of using the useSuiProvider hook to execute a transaction block. It shows how to call the executeTransactionBlock method with transaction details such as the transaction block data and signature, and how to handle the RPC response.
```typescript
function YourComponent() {
const { executeTransactionBlock } = useSuiProvider();
return (
);
}
```
--------------------------------
### Customize Suiet Wallet Kit Styles with CSS
Source: https://kit.suiet.app/docs/styling/customize
Provides examples of CSS rules to override default styles for components like buttons and account modals. These rules target specific class names provided by the Suiet Wallet Kit, allowing for granular control over the UI.
```css
.wkit-button {
height:64px; /* For example, override the height of the button */
}
/* Customize AccountModal */
.wkit-account-modal__content {
padding:24px0; /* Increase padding */
}
.wkit-account-modal__name {
color:#2563eb; /* Change name color to blue */
font-size:20px; /* Increase font size */
}
.wkit-account-modal__action-button {
border-radius:8px; /* Make buttons more rounded */
padding:12px16px; /* Increase button padding */
}
.wkit-account-modal__action-button--disconnect {
background-color:rgba(220,38,38,0.1); /* Custom disconnect button color */
}
```
--------------------------------
### Get Primary SuiNS Name
Source: https://kit.suiet.app/docs/Hooks/useSuinsName
Retrieves the primary SuiNS name for an address. This is the first name in the 'names' array or null if none are found. The example shows how to display this name or a fallback to the address itself.
```javascript
const{ defaultName }=useSuinsName({ address, chain });
// Display primary name or fallback to address
const displayName = defaultName ||`${address.slice(0,8)}...`;
```
--------------------------------
### Get All SuiNS Names
Source: https://kit.suiet.app/docs/Hooks/useSuinsName
Fetches an array containing all SuiNS names associated with the address. The first item in the array is considered the primary name. The example demonstrates checking if an address has multiple names.
```javascript
const{ names }=useSuinsName({ address, chain });
// Check if address has multiple names
if(names.length>1){
console.log('This address has multiple SuiNS names:', names);
}
```
--------------------------------
### Define New Wallet with Suiet Wallet Kit
Source: https://kit.suiet.app/docs/tutorial/customize-wallet-list
This snippet demonstrates how to define a custom wallet using the `defineWallet` function from the `@suiet/wallet-kit`. It shows how to provide wallet details like name, icon, and download URL, and then integrate it into the `WalletProvider` for use in your DApp. This is useful when the default wallet presets do not cover the wallets you need.
```typescript
import{
WalletProvider,
defineWallet,
}from'@suiet/wallet-kit';
// customized wallet must support @mysten/wallet-standard
constCustomizeWallet=defineWallet({
name:"myWallet",
iconUrl:"external url or data url",
downloadUrl:{
browserExtension:'download page url of chrome extension...'
},
})
ReactDOM.createRoot(document.getElementById('root')as HTMLElement).render(
)
```
--------------------------------
### Suiet Wallet Kit API References
Source: https://kit.suiet.app/docs/Hooks/useWallet
Comprehensive API references for the Suiet Wallet Kit hooks, covering wallet connection status, account management, transaction signing, and message verification.
```APIDOC
useWallet Hook:
Properties:
- name: string
Description: The name of the connected wallet adapter.
- connection status: boolean
Description: Indicates if the wallet is currently connected.
- account: object | null
Description: Information about the connected account, including address and public key.
- address: string | null
Description: The address of the connected wallet account.
- chains: Array