Wallet

The useWallet hook provides a unified interface for managing wallet connections in a VeChain application, supporting multiple connection methods including social logins (via Privy), direct wallet connections (via DappKit), and cross-application connections.

This will be the hook you will use more frequently and it provides quite a few useful informations.

Usage

import { useWallet } from "@vechain/vechain-kit"; 

function MyComponent = () => {
    const {
        account,
        connectedWallet,
        smartAccount,
        privyUser,
        connection,
        disconnect
    } = useWallet();
    
    return <></>
}

Types

export type Wallet = {
    address: string;
    domain?: string;
    image: string;
} | null;

Return values

account: Wallet

The primary account being used. This will be either:

  • The smart account (if connected via Privy)

  • The wallet address (if connected via DappKit)

smartAccount: SmartAccount

Information about the user's smart account:

  • address: The smart account address

  • domain: Associated VeChain domain name

  • image: Generated avatar image

  • isDeployed: Whether the smart account is deployed; smart accounts can be deployed on demand to avoid spending money on non active users. Learn more about smart accounts here.

  • isActive: Whether this is the currently active account

  • version: Smart account contract version

When the user is connected with Privy account will always be equal to the smartAccount.

connectedWallet: Wallet

The currently connected wallet, regardless of connection method (can be both a Privy Embedded Wallet or a self custody Wallet connected trough VeWorld or Sync2):

  • address: Wallet address

  • domain: Associated VeChain domain name

  • image: Generated avatar image

privyUser: User | null

The Privy user object if connected via Privy, null otherwise

connection: ConnectionState

Current connection state information:

  • isConnected: Overall connection status

  • isLoading: Whether connection is in progress

  • isConnectedWithSocialLogin: Connected via Privy (no crossapp)

  • isConnectedWithDappKit: Connected via DappKit

  • isConnectedWithCrossApp: Connected via cross-app

  • isConnectedWithPrivy: Connected via Privy (social or cross-app)

  • isConnectedWithVeChain: Connected with VeChain cross-app

  • source: Connection source information

  • isInAppBrowser: Whether your app is running in VeWorld app browser

  • nodeUrl: Current node URL (if provided by you in the provider, otherwise default in use by VeChain Kit)

  • delegatorUrl: Fee delegation service URL setted by you in the provider

  • chainId: Current chain ID

  • network: Network type (mainnet/testnet/custom)

disconnect(): Promise<void>

This function terminates the current wallet connection, ensuring cleanup of connection details and triggering necessary event listeners for state updates.

Connection Sources

The hook supports three main connection types:

  1. Social Login (privy): Authentication via social providers with your own APP_ID

  2. Wallet Connection (wallet): Direct wallet connection via DappKit

  3. Cross-App (privy-cross-app): Connection through ecosystem integration

Events

The hook dispatches a wallet_disconnected event when the wallet is disconnected, which can be used to trigger UI updates in dependent components.

Last updated

Was this helpful?