Skip to Content
dApps

Getting Started

Request permission before signing, select a connected account, and read the active chain. These examples use @mysten/[email protected], matching @mysten/[email protected] accepted by the current provider.

Learn how to detect, connect, and interact with Sui using OneKey’s provider.

OneKey implements the Sui Wallet Standard, for compatible wallet-standard integrations.


Provider Detection

// Detect OneKey Sui provider const provider = window.$onekey?.sui if (!provider) { throw new Error('OneKey Sui provider not detected') }

Check Permissions

// Check if already connected const hasPermission = await provider.hasPermissions() if (hasPermission) { const accounts = await provider.getAccounts() console.log('Connected accounts:', accounts) }

Request Connection

// Request permissions to connect const result = await provider.requestPermissions() if (result) { const accounts = await provider.getAccounts() console.log('Connected:', accounts[0].address) }

Account Context for Signing

Install @mysten/[email protected]. The injected provider’s getAccounts() returns AccountInfo[], not the WalletAccount required by signing methods. The following helper obtains the full account through Wallet Standard. Call it from a user action after wallet registration; handle rejection and reconnect after account or network changes.

import { getWallets, isWalletWithRequiredFeatureSet } from '@mysten/wallet-standard' async function connectSuiAccount() { const wallet = getWallets().get().find(wallet => wallet.name === 'OneKey Wallet') if (!wallet || !isWalletWithRequiredFeatureSet(wallet)) { throw new Error('OneKey Sui Wallet Standard is not available') } const { accounts } = await wallet.features['standard:connect'].connect() const [account] = accounts const chain = await provider.getActiveChain() if (!account || !chain || !account.chains.includes(chain)) { throw new Error('No connected Sui account for the active chain') } return { account, chain } }

Get Accounts

const accounts = await provider.getAccounts() accounts.forEach(account => { console.log({ address: account.address, // Sui address publicKey: account.publicKey, // Public key (hex string) }) })

Get Active Chain

const chain = await provider.getActiveChain() console.log('Active chain:', chain) // e.g., 'sui:testnet'

Check Connection Status

const isConnected = provider.isConnected() console.log('Connected:', isConnected)

Disconnect

await provider.disconnect()

Event Listeners

Listen for Account Changes

provider.onAccountChange((account) => { if (account) { console.log('Account changed:', account.address) } else { console.log('Disconnected') } })

Listen for Network Changes

provider.onNetworkChange((network) => { console.log('Network changed:', network) })

Using with Sui Wallet Kit

This React example uses the compatible package versions pinned below:

npm install @mysten/[email protected] @mysten/[email protected] @tanstack/react-query@^5
import { SuiClientProvider, WalletProvider } from '@mysten/dapp-kit' import { getFullnodeUrl } from '@mysten/sui/client' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' const queryClient = new QueryClient() const networks = { mainnet: { url: getFullnodeUrl('mainnet') }, testnet: { url: getFullnodeUrl('testnet') }, } function App() { return ( <QueryClientProvider client={queryClient}> <SuiClientProvider networks={networks} defaultNetwork="mainnet"> <WalletProvider> <YourApp /> </WalletProvider> </SuiClientProvider> </QueryClientProvider> ) }

OneKey is automatically detected through the Sui Wallet Standard.

Last updated on