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
Types
Return values
account: Wallet
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
smartAccount: SmartAccount
Information about the user's smart account:
address
: The smart account addressdomain
: Associated VeChain domain nameimage
: Generated avatar imageisDeployed
: 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 accountversion
: Smart account contract version
When the user is connected with Privy account
will always be equal to the smartAccount
.
connectedWallet: Wallet
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 addressdomain
: Associated VeChain domain nameimage
: Generated avatar image
privyUser: User | null
privyUser: User | null
The Privy user object if connected via Privy, null otherwise
connection: ConnectionState
connection: ConnectionState
Current connection state information:
isConnected
: Overall connection statusisLoading
: Whether connection is in progressisConnectedWithSocialLogin
: Connected via Privy (no crossapp)isConnectedWithDappKit
: Connected via DappKitisConnectedWithCrossApp
: Connected via cross-appisConnectedWithPrivy
: Connected via Privy (social or cross-app)isConnectedWithVeChain
: Connected with VeChain cross-appsource
: Connection source informationisInAppBrowser
: Whether your app is running in VeWorld app browsernodeUrl
: 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 providerchainId
: Current chain IDnetwork
: Network type (mainnet/testnet/custom)
disconnect(): Promise<void>
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:
Social Login (
privy
): Authentication via social providers with your own APP_IDWallet Connection (
wallet
): Direct wallet connection via DappKitCross-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?