This connection type is often used by organizations like VeBetterDAO, Cleanify, and Greencart. When connected, users can back up their embedded wallets, sign transactions without confirmation prompts, and add login methods. By connecting with Privy, developers use their personal APP_ID and CLIENT_ID to create their own app on Privy.
Pros of self hosting Privy:
No UI confirmations on users transactions
Allow your users to backup their keys and update security settings directly in your app
Targetted social login methods
Cons:
Price
Responsibilities to correctly secure your Privy account, since it contains access to user's wallet settings
Your users will need to login into other apps through ecosystem mode
2) Privy Cross App
When users integrate VeChain-kit using "Login with VeChain" and "Ecosystem" logins (eg: Mugshot and Greencart), this will be the default connection type. It is easily recognizable because login and wallet activities will open a secured popup window where the owner of the wallet will approve the actions.
With this type of connection, you can have social login in your app without actually paying Privy.
3) Self-custody wallets
This connection type allows login with self custody wallets, and is using the dapp-kit package under the hood.
The available wallets are: VeWorld mobile, VeWorld extension, Sync2, and Wallet Connect for VeWorld mobile.
Other wallets are available when login in with VeChain, such as Metamask, Rabby, Phantom, Coinbase Wallet, and Ranibow.
That will use Privy under the hood though, which means the connection type will be "privy-cross-app".
If you want to use vechain-kit but do not care about social login then you can skip the first login modal and directly show the "Connect Wallet" modal like this:
import { useDAppKitWalletModal } from '@vechain/vechain-kit';
export const LoginComponent = () => {
const { open: openWalletModal } = useDAppKitWalletModal();
return (
<Button onClick={openWalletModal}>
Open only "Connect Wallet"
</Button>
)}
When your app is opened inside VeWorld mobile wallet, VeWorld is always enforced as a login choice.
VeChain Kit V2
VeChain Kit is a comprehensive library designed to make building VeChain applications fast and straightforward. It offers:
Seamless Wallet Integration: Support for VeWorld, Sync2, WalletConnect, VeChain Embedded Wallet, and social logins (powered by Privy).
Unified Ecosystem Accounts: Leverage Privy’s Ecosystem feature to give users a single wallet across multiple dApps, providing a consistent identity within the VeChain network.
Developer-Friendly Hooks: Easy-to-use React Hooks that let you read and write data on the VeChainThor blockchain.
Pre-Built UI Components: Ready-to-use components (e.g., TransactionModal) to simplify wallet operations and enhance your users’ experience.
Multi-Language Support: Built-in i18n for a global audience.
Token Operations: Send tokens, check balances, manage VET domains, and more—all in one place.
Easier Integration
We provide a standardized “kit” that quickly integrates social logins and VeChain Smart Accounts—without the hassle of manual contract deployment or configuration.
This version of the kit deprecated the use of in favour of the .
It may have some breaking changes based on how you integrated the kit inside your app. Please read more in details what changed from V1 and how to migrate to version 2 in .
If you have an app with some custom login (eg: login with email, login with google, etc.) and you want to use this kit and migrate your users you will need to:
3) Toggle the "Pregenerate EVM Wallet" so an embedded wallet will be created and associated to the user.
4) If your users where logging in with social you may need to ask them to associate that social login method after they login first time with their email.
Installation
To add the package to your React app, you need to install the kit with all its peer dependencies as following:
Only supported on React and Next.js
React query, chakra and dapp-kit are peer dependencies.
yarn add @tanstack/react-query@"^5.64.2" @chakra-ui/react@"^2.8.2" @vechain/dapp-kit-react@"2.1.0-rc.1" @vechain/vechain-kit
// or
npm i @tanstack/react-query@"^5.64.2" @chakra-ui/react@"^2.8.2" @vechain/dapp-kit-react@"2.1.0-rc.1" @vechain/vechain-kit
Setup Privy (optional)
If you have your own Privy app, you can pass an additional prop with your settings.
4) Use the useSendTransaction() hook from @vechain/vechain-kit to send your transactions to the network.
Read how to use the hook here.
6) If you use useConnex() by importing from dapp-kit, import it from vechain-kit.
7) If you are using certificate signing to authenticate your users with your backend to issue a jwt/session token you will need to switch to use signTypedData instead, since Privy and Smart Accounts does not support the VeChain certificate authentication signature type. Read how to do here.
8) Double-check your yarn.lock to see that all the @vechain/dapp-kit-react@vechain/dapp-kit and @vechain/dapp-kit-uiinstalls are using the the 1.5.0 version.
Remove all installations of @vechain/dapp-kit @vechain/dapp-kit-ui and @vechain/dapp-kit-react from your app. If you need some specific hooks or methods from dapp-kit you can import them directly from the @vechain/vechain-kit.
Blockchain Hooks
useCurrentBlock()
Fetches the current block from the blockchain with automatic updates.
When a user initiates a connection through Privy, either directly or via cross-app integration, a secure wallet is immediately created for them. Privy implements a sophisticated key management technique known as key splitting, specifically using Shamir’s secret sharing method. This approach ensures that users retain full custody of their wallets without needing to manage any secret keys themselves. Importantly, neither Privy nor any integrated application ever accesses the user's keys; these secrets are only reconstituted directly on the user's device during the signing of messages or transactions. This process guarantees the utmost security and privacy for the user's onchain activities.
This type of wallet created by Privy is called Embedded Wallet.
Seamless Wallet Integration
Users benefit from an intuitively integrated wallet management experience that aligns seamlessly with their existing accounts, removing any unnecessary technical barriers. Applications built with Privy can generate wallets automatically for new accounts, such as those registered with an email address or phone number, even before the user logs in for the first time. Additionally, Privy provides users with the option to export their wallet keys, serving as an escape mechanism should they choose to transition away from Privy’s services at any point.
Privy embedded wallets are portable and can be used by any app––even apps not using Privy. Privy’s cross application wallet system supports interoperability with simple user experiences accessible to everyone, and seamlessly integrates with other Privy integrations and wallet connector solutions like RainbowKit and wagmi.
Sample cross app wallet flow
Embedded wallets can be backed up by the user through the VeChain Kit modal in the Settings page.
Many login methods can be attached to the Embedded Wallet.
Breaking Changes Overview
This provides a high-level summary of all breaking changes in VeChain Kit v2. For detailed information on each topic, please refer to the specific guides linked below.
Major Breaking Changes
1. Connex Removal
useConnex is completely removed and replaced with useThor
This affects all blockchain interactions throughout your application
2. New Contract Interaction Patterns
Introduction of useCallClause for reading contract data
New executeMultipleClausesCall for batch operations
Complete rewrite of transaction patterns
3. Updated Transaction Building
New useBuildTransaction hook with improved type safety
Better error handling and transaction status tracking
4. Module Removal
Entire VeBetterDAO module removed
Several utility modules deprecated
See Removed Features →
5. Hook Restructuring
Many hooks moved to new locations for better organization
Import paths have changed significantly
See Hook Relocations →
Quick Decision Guide
Next Steps
Read the complete removal list to check if you use any removed features
Review the API migration patterns for code examples
Follow the migration checklist step by step
Getting Help
GitHub Issues:
Documentation:
Community:
Intro
The kit provides hooks for developers to interact with smart contracts like VeBetterDAO, VePassport, veDelegate, and price oracles.
The hooks in this package provide a standardized way to interact with various blockchain and web services. All hooks are built using (formerly React Query), which provides powerful data-fetching and caching capabilities.
Common Features
Every hook in the @api directory returns a consistent interface that includes:
data: The fetched data
isLoading: Boolean indicating if the request is in progress
isError: Boolean indicating if the request failed
error: Error object if the request failed
refetch: Function to manually trigger a new fetch
isRefetching: Boolean indicating if a refetch is in progress
Additionally, these hooks integrate with TanStack Query's global features:
Automatic background refetching
Cache invalidation
Optimistic updates
Infinite queries (for pagination)
Parallel queries
Query retrying
Query polling
Query Invalidation
All hooks use consistent query key patterns, making it easy to invalidate related queries. For example:
Caching Behavior
By default, most queries are configured with:
staleTime: How long the data remains "fresh"
cacheTime: How long inactive data remains in cache
refetchInterval: For automatic background updates (if applicable)
These can be customized using TanStack Query's global configuration or per-hook options.
Styling Issues
VeChain Kit uses Chakra UI internally, which can cause styling conflicts with other CSS frameworks and custom styles.
Common Problems
CSS framework styles being overridden by VeChain Kit
VeChain Kit components not rendering correctly due to missing Chakra setup
Theme conflicts when your app also uses Chakra UI
Unexpected styling on images, buttons, or form elements
Quick Fixes
Install Chakra UI as a peer dependency even if you don't use it directly
Use CSS layers to control style precedence
Wrap your app in ChakraProvider with ColorModeScript
Issues in This Section
Setting up Chakra UI properly and resolving conflicts when your app also uses Chakra.
Using CSS layers to resolve conflicts with Tailwind, Bootstrap, and other CSS frameworks.
Can't find your issue? Search our or ask on .
Fee Delegation
VeChain Kit includes built-in fee delegation handling. If you already have fee delegation in your app, you must remove it to avoid conflicts.
Problem
Using both your own fee delegation and VeChain Kit's delegation causes:
Transaction failures
Double delegation attempts
Multiple signatures on transactions
Incorrect transaction format
Solution
Remove Existing Fee Delegation
Remove all custom fee delegation logic from your application:
Remove fee delegation middleware
Remove delegation signing logic
Remove any custom delegation providers
If you do not remove your own delegation then transactions could fail because your transaction will delegate 2 times, will have 2 signatures and an incorrect format.
Configure VeChain Kit Fee Delegation
Simply provide the delegation URL in the VeChainKitProvider:
Delegation Options
delegatorUrl: Your fee delegation service URL
delegateAllTransactions: Set to true to delegate fees for all transactions, including VeWorld users
Important Notes
VeChain Kit handles all delegation logic internally
No additional delegation setup required
Works automatically with all supported wallets
Verification
To verify that delegation is working correctly:
Check that transactions only have one delegation signature
Monitor your delegation service logs
Ensure transactions complete successfully
Common Errors
"Transaction has multiple delegations": You still have custom delegation code active. Remove all custom delegation logic.
"Delegation failed": Check that your delegation URL is correct and the service is running.
From DApp Kit
If you're coming from DApp Kit or SDK, you may have version conflicts from different versions installed across your project.
VeChain Kit includes DApp Kit functionality, but still requires @vechain/dapp-kit-react as a peer dependency for compatibility.
Problem
Multiple versions of DApp Kit packages can cause:
Version conflicts between different parts of your project
Runtime errors from competing implementations
Unexpected behaviour from mixed package versions
Solution
Completely Remove DApp Kit Packages
Remove all existing DApp Kit packages from your project:
Completely Remove DApp Kit Packages
VeChain Kit provides similar functionality with updated component names:
Clean Installation
After removing old packages:
Component Mapping
DApp Kit
VeChain Kit
Verification
Ensure clean migration:
No dapp-kit packages in package.json
All imports updated to use @vechain/vechain-kit
Component names updated to VeChain Kit equivalents
The hooks provide utility functions for interacting with the VeChain network and tokens:
Network Utility Hooks
useGetChainId: Retrieves the chain ID from the genesis block of the connected network
useGetNodeUrl: Returns the node URL being used, either custom or default for the network
Token Utility Hooks
useGetCustomTokenBalances: Fetches balances for multiple custom tokens for a given address, returning original, scaled, and formatted values
useGetCustomTokenInfo: Retrieves token information (name, symbol, decimals) for a custom token address.
Legal Documents Hook
useLegalDocuments: Retrieves the user's agreement status for required and optional legal documents, including terms of service, privacy policy, and cookie policy.
Usage Example
// Example usage of Utility hooks
import {
useGetChainId,
useGetNodeUrl,
useGetCustomTokenBalances,
useGetCustomTokenInfo,
useLegalDocuments
} from '@vechain/vechain-kit';
const ExampleComponent = () => {
const address = "0x..."; // User's wallet address
const tokenAddress = "0x..."; // Custom token address
// Get network information
const { data: chainId } = useGetChainId();
const nodeUrl = useGetNodeUrl();
// Get custom token information
const { data: tokenInfo } = useGetCustomTokenInfo(tokenAddress);
// Get token balances
const {
data: tokenBalances,
isLoading,
error
} = useGetCustomTokenBalances(address);
// Get legal documents data
const {
documentsNotAgreed,
documents,
agreements,
hasAgreedToRequiredDocuments,
} = useLegalDocuments();
console.log(
'Chain ID:', chainId,
'Node URL:', nodeUrl,
'Token Info:', tokenInfo,
'Token Balances:', tokenBalances,
'Has Agreed to Required Documents:', hasAgreedToRequiredDocuments,
'User Document Agreements:', agreements,
'Documents Not Agreed:', documentsNotAgreed,
'All Legal Documents:', documents
);
return (
// Your component JSX here
);
};
export default ExampleComponent;
/*
Note: These hooks require:
- A valid thor connection
- Appropriate network configuration
- Valid input parameters where applicable
The token-related hooks work with ERC20 tokens and return:
- Original values (raw from contract)
- Scaled values (adjusted for decimals)
- Formatted values (human-readable)
*/
Peer Dependencies
Ensure that your project's peer dependencies align with VeChain Kit's specifications. Mismatched versions can cause installation failures, runtime errors, or unexpected behaviour.
Common Issues
Package installation fails with peer dependency warnings
Runtime errors about missing dependencies
Version conflicts between VeChain Kit and your existing packages
To prompt users to review and accept your policies, like Terms and Conditions, Privacy Policy, or Cookie Policy, VeChainKit offers a simple plug-and-play solution.
You can avoid building your own if you haven't already.
By enabling also the tracking consent, you will allow VeChainKit to prompt your users to collect data to improve the kit.
When the legalDocuments option is configured, the users will see:
Left: A modal prompt when connecting their wallet, requiring them to review and accept required and optional legal documents.
Right: A summary view under Settings > General > Terms and Policies, showing which policies they’ve accepted and when.
Legal Docs ModalLegal Docs Summary View
Important
Legal document agreements are tied to the wallet address, document type, document version, and the url.
If the version of any document is updated, users will be prompted to accept it again.
Agreements are stored in the browser’s local storage, meaning acceptance is per browser and device.
As a result, users may be prompted again if they switch browsers, devices, or clear their local storage even if they've previously agreed on another setup.
import { VechainKitProvider } from '@vechain/vechain-kit';
export default function App({ Component, pageProps }: AppProps) {
return (
<VechainKitProvider
legalDocuments={{
allowAnalytics: true, // Enables optional consent for VeChainKit tracking
cookiePolicy: [
{
displayName: 'MyApp Policy', // (Optional) Custom display label
url: 'https://www.myapp.com/cookie-policy',
version: 1, // Increment to re-prompt users
required: false, // Optional: User sees a checkbox to opt in
},
],
privacyPolicy: [
{
url: 'https://www.myapp.com/privacy-policy',
version: 1, // Increment to re-prompt users
required: false, // Optional: can be skipped or rejected
},
],
termsAndConditions: [
{
displayName: 'MyApp T&C',
url: 'https://www.myapp.com/terms-and-conditions',
version: 1, // Increment to re-prompt users
required: true, // Required: must be accepted to proceed
},
],
}}
// ... other props
>
{children}
</VechainKitProvider>
);
}
Key Options
Option
Type
Required
Description
allowAnalytics
boolean
No
If true, prompts users with an optional tracking policy.
cookiePolicy
array
No
One or more cookie policy versions.
privacyPolicy
array
No
One or more privacy policy versions.
termsAndConditions
array
No
One or more T&C versions.
Transaction Modal
Use our pre built TransactionModal or TransactionToast components to show your users the progress and outcome of the transaction, or build your own UX and UI.
Usage example
'use client';
import {
useWallet,
useSendTransaction,
useTransactionModal,
TransactionModal,
getConfig
} from '@vechain/vechain-kit';
import { IB3TR__factory } from '@vechain/vechain-kit/contracts';
import { humanAddress } from '@vechain/vechain-kit/utils';
import { useMemo, useCallback } from 'react';
export function TransactionExamples() {
const { account } = useWallet();
const b3trMainnetAddress = getConfig("main").b3trContractAddress;
const clauses = useMemo(() => {
const B3TRInterface = IB3TR__factory.createInterface();
const clausesArray: any[] = [];
clausesArray.push({
to: b3trMainnetAddress,
value: '0x0',
data: B3TRInterface.encodeFunctionData('transfer', [
"0x0, // receiver address
'0', // 0 B3TR (in wei)
]),
comment: `This is a dummy transaction to test the transaction modal. Confirm to transfer ${0} B3TR to ${humanAddress("Ox0")}`,
abi: B3TRInterface.getFunction('transfer'),
});
return clausesArray;
}, [connectedWallet?.address]);
const {
sendTransaction,
status,
txReceipt,
resetStatus,
isTransactionPending,
error,
} = useSendTransaction({
signerAccountAddress: account?.address ?? '',
});
const {
open: openTransactionModal,
close: closeTransactionModal,
isOpen: isTransactionModalOpen,
} = useTransactionModal();
// This is the function triggering the transaction and opening the modal
const handleTransaction = useCallback(async () => {
openTransactionModal();
await sendTransaction(clauses);
}, [sendTransaction, clauses, openTransactionModal]);
const handleTryAgain = useCallback(async () => {
resetStatus();
await sendTransaction(clauses);
}, [sendTransaction, clauses, resetStatus]);
return (
<>
<button
onClick={handleTransactionWithModal}
isLoading={isTransactionPending}
isDisabled={isTransactionPending}
>
Send B3TR
</button>
<TransactionModal
isOpen={isTransactionModalOpen}
onClose={closeTransactionModal}
status={status}
txReceipt={txReceipt}
txError={error}
onTryAgain={handleTryAgain}
uiConfig={{
title: 'Test Transaction',
description: `This is a dummy transaction to test the transaction modal. Confirm to transfer ${0} B3TR to ${
account?.address
}`,
showShareOnSocials: true,
showExplorerButton: true,
isClosable: true,
}}
/>
</>
);
}
Profile Card
ProfileCard Component
The ProfileCard component provides a comprehensive display of user profile information, including avatar, domain, social links, and customization options.
Features
Customizable header with generated background
Avatar display with domain integration
Social links integration (Email, Website, Twitter/X)
// Example usage of ProfileCard component
import { ProfileCard } from '@vechain/vechain-kit';
const MyComponent = () => {
// Example wallet address
const walletAddress = "0x123...abc";
return (
<div style={{ maxWidth: '400px', margin: '0 auto' }}>
{/* Basic usage */}
<ProfileCard
address={walletAddress}
/>
{/* Full featured usage */}
<ProfileCard
address={walletAddress}
showHeader={true}
showLinks={true}
showDescription={true}
showDisplayName={true}
showEdit={true}
/>
</div>
);
};
export default MyComponent;
/*
Note: The component will automatically:
- Resolve VET domains for the address
- Fetch and display avatar
- Load text records for social links
- Handle dark/light mode
- Manage connected account state
*/
Smart Accounts v1 to v3
Upgrading toSmart Account v3 unlocks multi-clause support, enhanced security, and other essential features for transactions on VeChain. This feature is available in VeChain Kit from v1.5.0.
When integrating social login in your app, users might have a version 1 smart account. This version doesn’t support multiclause transactions, potentially causing issues within your app.
To address this scenario, consider wrapping your onClick handler or using another suitable method to prompt users to upgrade their smart accounts to version 3.
The kit makes available both the hooks to know if the upgrade is required and the component for upgrading:
useUpgradeRequired(smartAccountAddress, ownerAddress, targetVersion: 3) is the hook that will let you know if the user is on v1 and needs to upgrade to v3
useUpgradeSmartAccountModal() is the hook that will allow you to open the upgrade modal, that the user will use to upgrade.
You can also handle this with your own UI by using the useUpgradeSmartAccount(smartAccountAddress, targetVersion: 3) hook.
VeChain Kit components are wrapped in their own Chakra Provider (v2), ensuring consistent styling throughout the modals. This can cause conflicts if your app also uses Chakra UI.
Problem
VeChain Kit components not rendering correctly
Theme conflicts when your app uses Chakra UI
Missing styles or unexpected appearance
Solution
Install Chakra UI
Even if you don't use Chakra in your app, it's required as a peer dependency:
You can keep using whatever frontend framework you prefer. The important part is defining the ChakraProvider wrapper for VeChain Kit components to function properly.
Common Issue
One common issue is missing the <ColorModeScript /> component, which can cause styling inconsistencies. Always include it within your ChakraProvider.
Ipfs
IPFS Hooks
The hooks provide tools for interacting with IPFS (InterPlanetary File System):
Image Hooks
useIpfsImage: Fetches NFT media from IPFS, supporting various image formats (JPEG, PNG, GIF, etc.)
useIpfsImageList: Fetches multiple IPFS images in parallel
useSingleImageUpload: Handles single image upload with optional compression
useUploadImages: Manages multiple image uploads with compression support
Metadata Hooks
useIpfsMetadata: Fetches and optionally parses JSON metadata from IPFS
useIpfsMetadatas: Fetches multiple IPFS metadata files in parallel
Usage Example
Login
Login Hooks
The hooks provide authentication methods for VeChain applications:
Authentication Hooks
useLoginWithPasskey: Hook for authenticating using passkeys (biometric/device-based authentication)
useLoginWithOAuth: Hook for authenticating using OAuth providers (Google, Twitter, Apple, Discord)
useLoginWithVeChain: Hook for authenticating using VeChain wallet
Types
Usage example
Transaction Toast
Use our pre built TransactionModal or TransactionToast components to show your users the progress and outcome of the transaction, or build your own UX and UI.
Usage example
vetDomains
VetDomains Hooks
The hooks provide tools for interacting with VET domains and their functionality:
Domain Resolution Hooks
useVechainDomain: Resolves VET domains to addresses and vice versa, returning domain info and validation status
useIsDomainProtected: Checks if a domain is protected from claiming
useGetDomainsOfAddress: Gets all domains owned by an address, with optional parent domain filtering
Domain Record Management Hooks
useGetTextRecords: Gets all text records for a domain
useGetAvatar: Gets the avatar URL for a domain. This hook will return directly the URL of the image, removing the need for developers to convert the URI to URL manually. The response can be null if the domain name does not exist or if there is no avatar attached to this domain.
useGetAvatarOfAddress : This hook will check if the address has any primary domain name set, if yes it will fetch and return the avatar URL (again, no need to manually convert URI to URL, the hook does it). If there is no domain name attached to it or if there is no avatar attached to the domain, it will return the Picasso image.
useGetResolverAddress: Gets the resolver contract address for a domain
useUpdateTextRecord: Updates text records for a domain with transaction handling
Subdomain Management Hooks
useClaimVeWorldSubdomain: Claims a VeWorld subdomain with transaction handling and success/error callbacks
Usage Example
Privy Popup Blocking
Browser popup blocking can affect users using social login (Privy) when operations delay the signing popup.
Problem
When using Privy for social login (cross-app connection), browsers may block the confirmation popup if there's a delay between user
action and popup trigger.
What Causes This
Fetching data after button click
API calls before signing
Any async operations between click and popup
Solution
Pre-fetch Data Before Transaction
Ensure all required data is loaded before the user clicks the button:
Best Practices
Load Data Early
Show Loading States
Avoid Async in Click Handlers
Testing
To test if your implementation avoids popup blocking:
Use social login (Privy)
Click transaction buttons
Popup should appear immediately
No browser blocking warnings
Common Scenarios
Form submissions: Validate and prepare data before submit button is enabled
Token approvals: Pre-fetch allowance amounts
Multi-step transactions: Load all data for subsequent steps upfront
// Example usage of IPFS hooks
import {
useIpfsImage,
useIpfsMetadata,
useSingleImageUpload,
useUploadImages
} from '@vechain/vechain-kit';
const ExampleComponent = () => {
// Fetch an NFT image from IPFS
const {
data: imageData,
isLoading: isImageLoading,
error: imageError
} = useIpfsImage("ipfs://...");
// Fetch metadata from IPFS
const {
data: metadata,
isLoading: isMetadataLoading,
error: metadataError
} = useIpfsMetadata<{
name: string;
description: string
}>("ipfs://...", true); // parse as JSON
// Handle single image upload
const {
uploadedImage,
onUpload: handleSingleUpload,
onRemove: handleSingleRemove,
isUploading: isSingleUploading
} = useSingleImageUpload({
compressImage: true,
defaultImage: undefined,
maxSizeMB: 0.4,
maxWidthOrHeight: 1920
});
// Handle multiple image uploads
const {
uploadedImages,
onUpload: handleMultipleUpload,
onRemove: handleMultipleRemove,
isUploading: isMultipleUploading
} = useUploadImages({
compressImages: true,
defaultImages: [],
maxSizeMB: 0.4,
maxWidthOrHeight: 1920
});
// Example upload handler
const handleFileSelect = async (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (file) {
await handleSingleUpload(file);
}
};
// Example multiple files upload handler
const handleMultipleFileSelect = async (event: React.ChangeEvent<HTMLInputElement>) => {
const files = Array.from(event.target.files || []);
await handleMultipleUpload(files);
};
console.log(
'IPFS Image:', imageData,
'Loading Image:', isImageLoading,
'Metadata:', metadata,
'Loading Metadata:', isMetadataLoading,
'Uploaded Single Image:', uploadedImage,
'Single Upload in Progress:', isSingleUploading,
'Uploaded Multiple Images:', uploadedImages,
'Multiple Upload in Progress:', isMultipleUploading
);
return (
// Your component JSX here
);
};
export default ExampleComponent;
/*
Note: These hooks require:
- Valid IPFS gateway configuration
- Network type configuration
- For image hooks:
- Supported formats: JPEG, PNG, GIF, BMP, TIFF, WebP, SVG
- Maximum file size: 10MB
- For upload hooks:
- Default compression to 0.4MB
- Max width/height: 1920px
- Web Worker support for compression
*/
Your app requires only crypto wallet authentication
You want to bypass social login options
You need a streamlined wallet-focused experience
Special Considerations
VeWorld Mobile Integration
When your application is accessed through the VeWorld mobile wallet browser, VeWorld is automatically enforced as the primary authentication method. This ensures seamless integration with the mobile wallet experience.
Authentication State Management
All authentication methods automatically sync with the VeChain Kit provider, ensuring consistent state across your application. You can access the current authentication state using:
import { useWallet } from '@vechain/vechain-kit';
function Component() {
const { connection, address, source } = useWallet();
if (connection.isConnected) {
console.log('Connected wallet:', address);
console.log('Connection source:', source);
}
}
Error Handling
Always implement proper error handling for authentication flows:
// Example usage of NFT hooks
import { useNFTImage, useNFTMetadataUri } from '@vechain/vechain-kit';
const ExampleComponent = () => {
const walletAddress = "0x...";
const tokenId = "1";
const contractAddress = "0x...";
// Get complete NFT data including image
const {
imageData,
imageMetadata,
tokenID,
isLoading: isLoadingNFT,
error: nftError
} = useNFTImage({
address: walletAddress,
contractAddress: contractAddress
});
// Get just the metadata URI
const {
data: metadataUri,
isLoading: isLoadingUri,
error: uriError
} = useNFTMetadataUri({
tokenId,
contractAddress
});
// Handle loading states
if (isLoadingNFT || isLoadingUri) {
return <div>Loading NFT data...</div>;
}
// Handle errors
if (nftError || uriError) {
return <div>Error: {nftError?.message || uriError?.message}</div>;
}
console.log(
'NFT Image:', imageData,
'NFT Metadata:', imageMetadata,
'Token ID:', tokenID,
'Metadata URI:', metadataUri
);
// Example of using the NFT data
return (
<div>
{imageData && (
<img
src={imageData}
alt={imageMetadata?.name || 'NFT'}
/>
)}
{imageMetadata && (
<div>
<h2>{imageMetadata.name}</h2>
<p>{imageMetadata.description}</p>
{imageMetadata.attributes?.map((attr, index) => (
<div key={index}>
{attr.trait_type}: {attr.value}
</div>
))}
</div>
)}
</div>
);
};
export default ExampleComponent;
/*
Note: These hooks require:
- Valid thor connection
- Network type configuration
- Valid IPFS gateway for image fetching
- The hooks handle the complete flow:
1. Get token ID from address
2. Get metadata URI from token ID
3. Fetch metadata from IPFS
4. Fetch image from IPFS
Types:
interface NFTMetadata {
name: string;
description: string;
image: string;
attributes: {
trait_type: string;
value: string;
}[];
}
*/
General
Common issues and solutions during migration from 1.x to 2.0
TypeScript Compilation Errors
Type Mismatch Errors
// Error: Type 'string' is not assignable to type '`0x${string}`'
const address: `0x${string}` = userAddress;
// ✅ Solution
const contractAddress = getConfig(networkType).contractAddress as `0x${string}`;
const method = 'convertedB3trOf' as const;
// ✅ Validate addresses
import { humanAddress } from '@vechain/vechain-kit/utils';
const validatedAddress = humanAddress(address);
BigInt Serialization Errors
import { hashFn } from 'wagmi/query';
// Error: Do not know how to serialize a BigInt
// ✅ Solution: set wagmi's hashfn as default queryKeyHashFn
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
queryKeyHashFn: hashFn,
retry: 0,
retryOnMount: false,
staleTime: 30000,
// other options
},
},
})
With every name come a set of records. These records are key value pairs that can be used to store information about the profile. Think of this as a user's digital backpack. Utalized for storage of preferences, public details, and more.
Types of Records
Here are some of the most commonly used records:
Name
Usage
Reference
Example
display
Preferred capitalization
Luc.eth
avatar
Avatar or logo (see )
ipfs://dQw4w9WgXcQ
description
Description of the name
DevRel @ ENS Labs
keywords
List of comma-separated keywords
person, ens
email
Email address
mail
Physical mailing address
V3X HQ
notice
Notice regarding this name
This is a notice
location
Generic location (e.g. "Toronto, Canada")
Breda, NL
phone
Phone number as an E.164 string
+1 234 567 890
url
Website URL
header
Image URL to be used as a header/banner
ipfs://dQw4w9WgXcQ
Other Records
Currently there are a few records that have been standardised. However you are welcome to store any key value pair you desire. We generally recommend to stick to a pattern, or prefix things with your app or protocol (eg. com.discord, or org.reddit), as such to avoid collisions.
Header/Banner Record
One of the newer standardised records is the "header" record. This header record, similar to the avatar record, accepts any IPFS, Arweave, EIP155, or regular URL to an image resource. The image is then displayed as a banner on the profile page and tends to be in a 1:3 aspect ratio.
Setting Records
When records are loaded they are loaded from the resolver responsible for the name. As resolvers are user controlled, we cannot guarantee a write function is available. This makes it a more in-depth process to update a users records.
This is protocol build by ENS domains and supported by veDelegate. Follow ENS documentation for more information.
Keep reading how to integrate with the VeChain Kit
Dynamic Import: Always use dynamic import in Next.js to avoid SSR issues
Environment Variables: Store sensitive configuration in environment variables
Fee Delegation: Consider your fee delegation strategy based on user experience needs
Login Methods: Choose login methods that match your target audience
Metadata: Provide clear app metadata for wallet connection requests
Next Steps
Implement Authentication Methods
Configure Fee Delegation
Customize UI Theme
Handle Wallet Interactions
Send Transactions
The useSendTransaction hook is mandatory if you use social login in your app, since it handles the social login transactions (that needs to be prepared and broadcasted differently from normal transactions). If you are not interested in social login features then you can avoid using useSendTransaction and useSignMessage and use the signer exported by the kit following the SDK guides for creating transactions or signing messages.
This hook will take care of checking your connection type and handle the transaction submission between privy, cross-app and wallet connections.
When implementing VeChain Kit it is mandatory to use this hook to send transaction.
Use our pre built TransactionModal or TransactionToast components to show your users the progress and outcome of the transaction, or build your own UX and UI.
'use client';
import {
useWallet,
useSendTransaction,
useTransactionModal,
TransactionModal,
getConfig
} from '@vechain/vechain-kit';
import { IB3TR__factory } from '@vechain/vechain-kit/contracts';
import { humanAddress } from '@vechain/vechain-kit/utils';
import { useMemo, useCallback } from 'react';
export function TransactionExamples() {
const { account } = useWallet();
const b3trMainnetAddress = getConfig("main").b3trContractAddress;
const clauses = useMemo(() => {
const B3TRInterface = IB3TR__factory.createInterface();
const clausesArray: any[] = [];
clausesArray.push({
to: b3trMainnetAddress,
value: '0x0',
data: B3TRInterface.encodeFunctionData('transfer', [
"0x0, // receiver address
'0', // 0 B3TR (in wei)
]),
comment: `This is a dummy transaction to test the transaction modal. Confirm to transfer ${0} B3TR to ${humanAddress("Ox0")}`,
abi: B3TRInterface.getFunction('transfer'),
});
return clausesArray;
}, [connectedWallet?.address]);
const {
sendTransaction,
status,
txReceipt,
resetStatus,
isTransactionPending,
error,
} = useSendTransaction({
signerAccountAddress: account?.address ?? '',
});
const {
open: openTransactionModal,
close: closeTransactionModal,
isOpen: isTransactionModalOpen,
} = useTransactionModal();
// This is the function triggering the transaction and opening the modal
const handleTransaction = useCallback(async () => {
openTransactionModal();
await sendTransaction(clauses);
}, [sendTransaction, clauses, openTransactionModal]);
const handleTryAgain = useCallback(async () => {
resetStatus();
await sendTransaction(clauses);
}, [sendTransaction, clauses, resetStatus]);
return (
<>
<button
onClick={handleTransactionWithModal}
isLoading={isTransactionPending}
isDisabled={isTransactionPending}
>
Send B3TR
</button>
<TransactionModal
isOpen={isTransactionModalOpen}
onClose={closeTransactionModal}
status={status}
txReceipt={txReceipt}
txError={error}
onTryAgain={handleTryAgain}
uiConfig={{
title: 'Test Transaction',
description: `This is a dummy transaction to test the transaction modal. Confirm to transfer ${0} B3TR to ${
account?.address
}`,
showShareOnSocials: true,
showExplorerButton: true,
isClosable: true,
}}
/>
</>
);
}
You can build clauses with some of our available build functions, with our SDK or with connex.
If you want to interact directly with the user's smart account read the Smart Accounts section.
Important
Ensuring data is pre-fetched before initiating a transaction is crucial to avoid browser pop-up blocking for users using social login, which can adversely affect user experience.
// ✅ Good: Pre-fetch data
const { data } = useQuery(['someData'], fetchSomeData);
const sendTx = () => sendTransaction(data);
// ⛔ Bad: Fetching data during the transaction
const sendTx = async () => {
const data = await fetchSomeData();
return sendTransaction(data);
};
🔧 Custom Gas Configuration (optional)
When sending transactions using VechainKit, you can fine-tune the gas settings by using two optional fields: suggestedMaxGas and gasPadding. These options give you greater control over the gas behavior of your transaction.
suggestedMaxGas
The suggestedMaxGas parameter allows you to explicitly define the maximum amount of gas to be used for the transaction. When this field is set, it will override the internal gas estimation logic and also ignore any gasPadding value.
Expected format: an integer representing gas units (e.g., 40000000 for 40 million gas).
Use this option when you want full control and know in advance the maximum gas your transaction should consume.
Example:
useSendTransaction({
..., //other config
suggestedMaxGas: 40000000, // Sets the gas limit directly
});
gasPadding
The gasPadding option allows you to add a safety buffer on top of the estimated gas. This can be useful to prevent underestimations for complex transactions.
Expected format: a number between 0 and 1, representing a percentage increase (e.g., 0.1 adds 10%).
Only applied if suggestedMaxGas is not set.
Example:
useSendTransaction({
..., //other config
gasPadding: 0.1, // Adds 10% buffer to estimated gas
});
Summary
Option
Type
Applies Gas Estimation
Applies Padding
Overwrites Estimation
suggestedMaxGas
Integer
❌
❌
✅
gasPadding
Float (0–1)
✅
✅
❌
Use suggestedMaxGas when you want to define the gas cap directly, and gasPadding when you prefer to work with auto-estimation but want a bit of headroom.
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.
interface User {
/** The Privy-issued DID for the user. If you need to store additional information
* about a user, you can use this DID to reference them. */
id: string;
/** The datetime of when the user was created. */
createdAt: Date;
/** The user's email address, if they have linked one. It cannot be linked to another user. */
email?: Email;
/** The user's phone number, if they have linked one. It cannot be linked to another user. */
phone?: Phone;
/** The user's most recently linked wallet, if they have linked at least one wallet.
* It cannot be linked to another user.
* This wallet is the wallet that will be used for transactions and signing if it is connected.
**/
wallet?: Wallet;
/**
* The user's smart wallet, if they have set up through the Privy Smart Wallet SDK.
*/
smartWallet?: SmartWallet;
/** The user's Google account, if they have linked one. It cannot be linked to another user. */
google?: Google;
/** The user's Twitter account, if they have linked one. It cannot be linked to another user. */
twitter?: Twitter;
/** The user's Discord account, if they have linked one. It cannot be linked to another user. */
discord?: Discord;
/** The user's Github account, if they have linked one. It cannot be linked to another user. */
github?: Github;
/** The user's Spotify account, if they have linked one. It cannot be linked to another user. */
spotify?: Spotify;
/** The user's Instagram account, if they have linked one. It cannot be linked to another user. */
instagram?: Instagram;
/** The user's Tiktok account, if they have linked one. It cannot be linked to another user. */
tiktok?: Tiktok;
/** The user's LinkedIn account, if they have linked one. It cannot be linked to another user. */
linkedin?: LinkedIn;
/** The user's Apple account, if they have linked one. It cannot be linked to another user. */
apple?: Apple;
/** The user's Farcaster account, if they have linked one. It cannot be linked to another user. */
farcaster?: Farcaster;
/** The user's Telegram account, if they have linked one. It cannot be linked to another user. */
telegram?: Telegram;
/** The list of accounts associated with this user. Each account contains additional metadata
* that may be helpful for advanced use cases. */
linkedAccounts: Array<LinkedAccountWithMetadata>;
/** The list of MFA Methods associated with this user. */
mfaMethods: Array<MfaMethod>;
/**
* Whether or not the user has explicitly accepted the Terms and Conditions
* and/or Privacy Policy
*/
hasAcceptedTerms: boolean;
/** Whether or not the user is a guest */
isGuest: boolean;
/** Custom metadata field for a given user account */
customMetadata?: CustomMetadataType;
}
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:
Social Login (privy): Authentication via social providers with your own APP_ID
Wallet Connection (wallet): Direct wallet connection via DappKit
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.
Open targeted modals
The hooks provide tools for managing various modals in the VeChain application:
Account Related Modals
useAccountModal: Core account modal management
useProfileModal: Show the user only his profile, with customize and logout option
This button acts both as a login button and as an account button (when the user is already logged).
VeChain Kit provides multiple ways to customize the UI components. Here are some examples of different button styles and variants.
Usage example
'use client';
import { VStack, Text, Button, Box, HStack, Grid } from '@chakra-ui/react';
import {
WalletButton,
useAccountModal,
ProfileCard,
useWallet,
} from '@vechain/vechain-kit';
import { MdBrush } from 'react-icons/md';
import { CollapsibleCard } from '../../ui/CollapsibleCard';
export function UIControls() {
const { open } = useAccountModal();
const { account } = useWallet();
return (
<>
<VStack spacing={6} align="stretch" w={'full'}>
<Text textAlign="center">
VeChain Kit provides multiple ways to customize the UI
components. Here are some examples of different button
styles and variants.
</Text>
<HStack w={'full'} justifyContent={'space-between'}>
{/* Mobile Variants */}
<HStack w={'full'} justifyContent={'center'}>
<VStack
w={'fit-content'}
spacing={6}
p={6}
borderRadius="md"
bg="whiteAlpha.50"
>
<Text fontWeight="bold">
Account Button Variants
</Text>
<Text
fontSize="sm"
textAlign="center"
color="gray.400"
>
Note: Some variants might look different based
on connection state and available data. Eg:
"iconDomainAndAssets" will show the assets only
if the user has assets. And same for domain
name.
</Text>
<Grid
templateColumns={{
base: '1fr',
md: 'repeat(2, 1fr)',
}}
gap={8}
w="full"
justifyContent="space-between"
>
{/* First Column Items */}
<VStack alignItems="flex-start" spacing={8}>
<VStack alignItems="flex-start" spacing={2}>
<Box w={'fit-content'}>
<WalletButton
mobileVariant="icon"
desktopVariant="icon"
/>
</Box>
<Text
fontSize="sm"
fontWeight="medium"
color="blue.300"
bg="whiteAlpha.100"
px={3}
py={1}
borderRadius="full"
>
variant: "icon"
</Text>
</VStack>
<VStack alignItems="flex-start" spacing={2}>
<Box w={'fit-content'}>
<WalletButton
mobileVariant="iconAndDomain"
desktopVariant="iconAndDomain"
/>
</Box>
<Text
fontSize="sm"
fontWeight="medium"
color="blue.300"
bg="whiteAlpha.100"
px={3}
py={1}
borderRadius="full"
>
variant: "iconAndDomain"
</Text>
</VStack>
<VStack alignItems="flex-start" spacing={2}>
<Box w={'fit-content'}>
<WalletButton
mobileVariant="iconDomainAndAddress"
desktopVariant="iconDomainAndAddress"
/>
</Box>
<Text
fontSize="sm"
fontWeight="medium"
color="blue.300"
bg="whiteAlpha.100"
px={3}
py={1}
borderRadius="full"
>
variant: "iconDomainAndAddress"
</Text>
</VStack>
</VStack>
{/* Second Column Items */}
<VStack alignItems={'flex-start'} spacing={8}>
<VStack alignItems="flex-start" spacing={2}>
<Box w={'fit-content'}>
<WalletButton
mobileVariant="iconDomainAndAssets"
desktopVariant="iconDomainAndAssets"
/>
</Box>
<Text
fontSize="sm"
fontWeight="medium"
color="blue.300"
bg="whiteAlpha.100"
px={3}
py={1}
borderRadius="full"
>
variant: "iconDomainAndAssets"
</Text>
</VStack>
<VStack alignItems="flex-start" spacing={2}>
<Box w={'fit-content'}>
<WalletButton
mobileVariant="iconDomainAndAssets"
desktopVariant="iconDomainAndAssets"
buttonStyle={{
border: '2px solid #000000',
boxShadow:
'-2px 2px 3px 1px #00000038',
background: '#f08098',
color: 'white',
_hover: {
background: '#db607a',
border: '1px solid #000000',
boxShadow:
'-3px 2px 3px 1px #00000038',
},
transition: 'all 0.2s ease',
}}
/>
</Box>
<Text
fontSize="sm"
fontWeight="medium"
color="blue.300"
bg="whiteAlpha.100"
px={3}
py={1}
borderRadius="full"
>
variant: "iconDomainAndAssets"
(styled)
</Text>
</VStack>
<VStack alignItems="flex-start" spacing={2}>
<Button onClick={open}>
<Text>This is a custom button</Text>
</Button>
<Text
fontSize="sm"
fontWeight="medium"
color="blue.300"
bg="whiteAlpha.100"
px={3}
py={1}
borderRadius="full"
>
no variant, custom button
</Text>
</VStack>
</VStack>
</Grid>
</VStack>
</HStack>
</HStack>
</VStack>
</>
);
}
Smart Accounts
Our are a simplified version of the Account Abstraction pattern, made for the VeChain blockchain, and are required in order to enable social login.
Addresses
Mainnet
Testnet
Every wallet on VeChain owns a smart account. The address of your smart account is deterministic, and it can be deployed at any time, and receive tokens even if it is not deployed yet.
Testnet Factory address changed from v1 to v3 from 0x7EABA81B4F3741Ac381af7e025f3B6e0428F05Fb to 0x713b908Bcf77f3E00EFEf328E50b657a1A23AeaF which will cause all your testnet smart account addresses to change when upgrading to v1.5.0.
Contracts
There are 2 contracts that work together to enable social login and account abstraction:
SimpleAccount: A smart contract wallet owned by the user that can:
Execute transactions directly from the owner or through signed messages
Handle both single and batch transactions
SimpleAccountFactory: Factory contract that creates and manages SimpleAccount contracts:
Creates new accounts with deterministic addresses using CREATE2
Get the account address of a smart account without deploying it
Supports multiple accounts per owner through custom salts
Manages different versions of the SimpleAccount implementation
How it works
Account Creation: When a user wants to create a smart account, they interact with the SimpleAccountFactory, which creates a new SimpleAccount instance with the user as the owner.
Transaction Execution: The SimpleAccount can execute transactions in several ways:
Direct execution by the owner
Batch execution of multiple transactions
Signature-based execution (useful for social login) - Deprecated, should avoid using this
Batch signature-based execution with replay protection (useful for social login + multiclause)
Batch signature-based execution with 16-bit chain ID to allow iOS and Android developers handle VeChain chain ID.
Nonce Management: For batch transactions with authorization (executeBatchWithAuthorization), a nonce is required to protect users against replay attacks:
The nonce should be generated when requesting the signature
Best practice is to use Date.now() as the nonce value
Each nonce can only be used once per account
Without proper nonce management, malicious actors could replay the same signed transaction multiple times
Nonces are only used and required for executeBatchWithAuthorization method
Social Login Integration: This system enables social login by creating deterministic account addresses for each user and allowing transactions to be signed off-chain and executed by anyone. This creates a seamless experience where users can interact with dApps using their social credentials.
Version Management
The system has evolved through multiple versions to improve functionality and security:
SimpleAccount:
V1: Basic account functionality with single transaction execution
V2: Skipped for misconfiguration during upgrade
V3: Introduced batch transactions with nonce-based replay protection, ownership transfer and version tracking
SimpleAccountFactory:
V1: Basic account creation and management
V2: Added support for multiple accounts per owner using custom salts
V3: Support for V3 SimpleAccounts, enhanced version management and backward compatibility with legacy accounts
The factory maintains compatibility with all account versions, ensuring a smooth experience across different dApps and versions.
Testnet Factory address changed from v1 to v3 from 0x7EABA81B4F3741Ac381af7e025f3B6e0428F05Fb to 0x713b908Bcf77f3E00EFEf328E50b657a1A23AeaF which will cause all your testnet smart account addresses to change.
Smart Accounts V3 upgrade
Upgrading the user's smart accounts from V1 to V3 is mandatory, in order to protect against reply attacks and to allow multiclause transactions on VeChain.
To facilitate the mandatory upgrade process, the kit now includes:
Built-in Check: Automatically displays an alert prompting users to upgrade if they possess a V1 smart account.
Hooks & Component: To avoid apps spending VTHO to upgrade accounts of users that won't do any action on the app we allow the developer to check upgradeability on demand by using the useUpgradeRequiredForAccount hook and show the UpgradeSmartAccountModal (importable from the kit).
Hooks
Developers can efficiently manage smart accounts using a provided by the kit.
By importing these hooks, developers can:
Easily check if an upgrade is needed
Determine the current smart account version
Simplify maintaining and upgrading smart accounts
This ensures users seamlessly benefit from the latest features and protections.
Multiclause transactions
Multiclause transactions offer enhanced security and flexibility within the VeChain ecosystem. Here's a breakdown of the key points for developers:
Single Clause Transactions:
You can still use executeWithAuthorization, but keep in mind it retains a replay attack vector. This method is primarily for backward compatibility.
Recommended Adoption:
Switch to executeBatchWithAuthorization for a more secure solution. This method:
Solves replay attack issues.
Executes multiple transactions with a single signature, simulating multiclause capabilities.
Automatic Management:
Using useSendTransaction from the kit automates this process, negating the need for manual adjustments.
Understanding these components is crucial for those working with smart accounts outside of the vechain-kit. This knowledge ensures both security and operational efficiency.
How to use executeBatchWithAuthorization and the nonce :
Currently VeChain Kit does not support the handling of a smart account by a VeWorld wallet.
const executeBatchWithAuthorization = (txClauses: Connex.VM.Clause[]) => {
const toArray: string[] = [];
const valueArray: string[] = [];
const dataArray: string[] = [];
txClauses.forEach((clause) => {
toArray.push(clause.to ?? '');
valueArray.push(String(clause.value));
if (typeof clause.data === 'object' && 'abi' in clause.data) {
dataArray.push(encodeFunctionData(clause.data));
} else {
dataArray.push(clause.data || '0x');
}
});
const dataToSign = {
domain: {
name: 'Wallet',
version: '1',
chainId,
verifyingContract, // the smart account of the user
},
types: {
ExecuteBatchWithAuthorization: [
{ name: 'to', type: 'address[]' },
{ name: 'value', type: 'uint256[]' },
{ name: 'data', type: 'bytes[]' },
{ name: 'validAfter', type: 'uint256' },
{ name: 'validBefore', type: 'uint256' },
{ name: 'nonce', type: 'bytes32' },
],
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' },
],
},
primaryType: 'ExecuteBatchWithAuthorization',
message: {
to: toArray,
value: valueArray,
data: dataArray,
validAfter: 0,
validBefore: Math.floor(Date.now() / 1000) + 60, // e.g. 1 minute from now
nonce: ethers.hexlify(ethers.randomBytes(32)), // nonce needs to be random
},
};
// Sign the typed data with Privy
const signature = (
await signTypedDataPrivy(typedData, {
uiOptions: {
title,
description,
buttonText,
},
})
).signature;
// Rebuild the clauses to call the executeBatchWithAuthorization
const clauses = [];
clauses.push(
Clause.callFunction(
Address.of(smartAccount.address),
ABIContract.ofAbi(SimpleAccountABI).getFunction(
'executeBatchWithAuthorization',
),
[
typedData.message.to,
typedData.message.value?.map((val) => BigInt(val)) ?? 0,
typedData.message.data,
BigInt(typedData.message.validAfter),
BigInt(typedData.message.validBefore),
typedData.message.nonce, // If your contract expects bytes32
signature as `0x${string}`,
],
),
);
//Now you can broadcast the transaction to the blockchain with one of your delegator wallets
// ...
};
This document lists all hooks, modules, and features that have been completely removed in v2. If you use any of these, you'll need to find alternatives or implement custom solutions.
// New events API - check documentation for updated usage
import { useEvents } from '@vechain/vechain-kit';
// The API has changed - refer to blockchain hooks documentation
Query Keys
Generating Query Keys
v2 introduces specific query key functions:
import {
getCallClauseQueryKeyWithArgs,
getCallClauseQueryKey
} from '@vechain/vechain-kit';
// With arguments
const queryKeyWithArgs = getCallClauseQueryKeyWithArgs({
abi: ContractABI,
address: contractAddress,
method: 'balanceOf',
args: [userAddress]
});
// Without arguments (for methods with no parameters)
const queryKey = getCallClauseQueryKey({
abi: ContractABI,
address: contractAddress,
method: 'totalSupply'
});
// Use with React Query for cache invalidation
queryClient.invalidateQueries({ queryKey: queryKeyWithArgs });
Fee delegation allows your dApp to sponsor transaction fees for users, removing the barrier of requiring VTHO tokens. This is mandatory for social login users who don't have VTHO to pay for transactions.
What is Fee Delegation?
Fee delegation is a VeChain feature that enables applications to pay transaction fees on behalf of users. This creates a seamless user experience, especially for:
New users without VTHO tokens
Social login users (email, Google, etc.)
Improving overall user onboarding
Configuration
Add fee delegation to your VeChainKitProvider:
Configuration Options
delegatorUrl: The endpoint URL for your fee delegation service
delegateAllTransactions:
true: Sponsor all transactions (wallet and social users)
false: Sponsor only social login transactions (mandatory)
Setup Options
You have two options for setting up fee delegation:
Option 1: Create Your Own Service
Deploy a custom fee delegation service as a microservice or backend endpoint.
Example Implementation (Cloudflare Worker)
Environment Variables
Security Considerations
Never expose your mnemonic: Store it securely in environment variables
Implement request validation: Check origin, transaction limits, etc.
Add rate limiting: Prevent abuse of your delegation service
Monitor usage: Track delegation requests and VTHO consumption
Option 2: Use VeChain.Energy
VeChain.Energy provides a managed fee delegation service.
Setup Steps
For a detailed walkthrough, see the .
Visit VeChain.Energy
Go to
Create an account and project
Configure Fee Delegation
Navigate to: Your Project → Fee Delegation → Configurations
Your delegation URL will be: https://sponsor-testnet.vechain.energy/by/YOUR_PROJECT_ID
Configure Your Provider
Smart Contract for Custom Rules
For advanced delegation rules, deploy a smart contract:
Monitoring and Alerts
For VeChain.Energy
Enable email notifications for low VTHO balance
Set up alerts in your project dashboard
Monitor usage statistics regularly
For Custom Solutions
Implement monitoring for:
VTHO balance of delegation wallet
Number of delegated transactions
Failed delegation attempts
Unusual activity patterns
Testing Fee Delegation
Test with Social Login
Verify Delegation Headers. Check that your delegation service returns proper headers:
Troubleshooting
Common Issues
"Fee delegation failed" error
Check delegation URL is correct
Verify VTHO balance in delegation wallet
Ensure CORS headers are properly set
Social login users can't transact
Confirm feeDelegation is configured in provider
Check delegation service is running
Verify smart contract address is whitelisted
High VTHO consumption
Implement transaction limits
Add user verification
Monitor for unusual patterns
Best Practices
Security First
Never expose private keys or mnemonics
Implement proper authentication
Add rate limiting
User Experience
Ensure sufficient VTHO balance
Provide clear error messages
Monitor service uptime
Cost Management
Set reasonable limits
Track usage per user
Implement fair use policies
<VeChainKitProvider
feeDelegation={{
delegatorUrl: "YOUR_FEE_DELEGATION_URL",
delegateAllTransactions: true, // or false for social login only
}}
>
{children}
</VeChainKitProvider>
import {
Address,
HDKey,
Transaction,
Secp256k1,
Hex
} from '@vechain/sdk-core';
// Default signer for development (use env variable in production)
const DEFAULT_SIGNER = 'denial kitchen pet squirrel other broom bar gas better priority spoil cross';
export async function onRequestPost({ request, env }): Promise<Response> {
try {
const body = await request.json();
console.log('Incoming fee delegation request:', body);
// Load signer wallet from mnemonic
const mnemonic = (env.SIGNER_MNEMONIC ?? DEFAULT_SIGNER).split(' ');
const signerWallet = HDKey.fromMnemonic(
mnemonic,
HDKey.VET_DERIVATION_PATH
).deriveChild(0);
if (!signerWallet.publicKey || !signerWallet.privateKey) {
throw new Error('Could not load signing wallet');
}
// Get signer address
const signerAddress = Address.ofPublicKey(signerWallet.publicKey);
// Decode and sign the transaction
const transactionToSign = Transaction.decode(
Buffer.from(body.raw.slice(2), 'hex'),
false
);
const transactionHash = transactionToSign.getSignatureHash(
Address.of(body.origin)
);
const signature = Secp256k1.sign(
transactionHash.bytes,
signerWallet.privateKey
);
return new Response(JSON.stringify({
signature: Hex.of(signature).toString(),
address: signerAddress.toString()
}), {
status: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
});
} catch (error) {
console.error('Fee delegation error:', error);
return new Response(JSON.stringify({ error: error.message }), {
status: 500,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
});
}
}
# .env
SIGNER_MNEMONIC="your twelve word mnemonic phrase here"
To authenticate users in your backend (BE) and issue them a JWT (JSON Web Token), you may need to check that the connected user actually holds the private keys of that wallet (assuring he is not pretending to be someone else).
The recommended approach is to use signTypedData to have the user sign a piece of structured data, ensuring the signed payload is unique for each authentication request.
When using Privy the user owns a smart account (which is a smart contract), and he cannot directly sign a message with the smart account but needs to do it with his Embedded Wallet (the wallet created and secured by Privy). This means that when you verify identities of users connected with social login you will need to check that the address that signed the message is actually the owner of the smart account.
Example usage
Create a provider that will handle the signature verification.
import { useSignatureVerification } from "../hooks/useSignatureVerification";
import { Modal, ModalOverlay, ModalContent, VStack, Text, Spinner, Button } from "@chakra-ui/react";
import { useTranslation } from "react-i18next";
import { ReactNode, useEffect } from "react";
import { useWallet } from "@vechain/vechain-kit";
import { clearSignature, usePostUser } from "@/hooks";
type Props = {
children: ReactNode;
};
export const SignatureVerificationWrapper = ({ children }: Props) => {
const { hasVerified, isVerifying, signature, verifySignature, value } = useSignatureVerification();
const { account } = useWallet();
const { t } = useTranslation();
const { mutate: postUser } = usePostUser();
useEffect(() => {
if (account?.address && !signature) {
verifySignature();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [account?.address, signature]);
useEffect(() => {
// If user signed the signature we call our backend endpoint
if (signature && value.user !== "" && value.timestamp !== "" && account?.address) {
// When you want to execute the mutation:
postUser({
address: account.address,
value: value,
signature: signature,
});
}
}, [signature, value, account?.address, postUser]);
// if user disconnects we clear the signature
useEffect(() => {
if (!account) {
clearSignature();
}
}, [account]);
// Only show the modal if we have an account connected AND haven't verified yet AND are not in the process of verifying
const showModal = !!account?.address && (!hasVerified || !signature);
return (
<>
{children}
<Modal isOpen={showModal} onClose={() => {}} isCentered closeOnOverlayClick={false}>
<ModalOverlay />
<ModalContent p={6}>
<VStack spacing={4}>
{isVerifying ? (
<>
<Spinner size="xl" color="primary.500" />
<Text textAlign="center" fontSize="lg">
{t("Please sign the message to verify your wallet ownership")}
</Text>
</>
) : (
<>
<Text textAlign="center" fontSize="lg">
{t("Signature verification is mandatory to proceed. Please try again.")}
</Text>
<Button onClick={verifySignature} colorScheme="secondary">
{t("Try Again")}
</Button>
</>
)}
</VStack>
</ModalContent>
</Modal>
</>
);
};
Wrap the app with our new provider
import React from "react";
import ReactDOM from "react-dom/client";
import { VeChainKitProviderWrapper } from "./components/VeChainKitProviderWrapper.tsx";
import { ChakraProvider, ColorModeScript } from "@chakra-ui/react";
import { lightTheme } from "./theme";
import { RouterProvider } from "react-router-dom";
import { router } from "./router";
import { AppProvider } from "./components/AppProvider.tsx";
import { SignatureVerificationWrapper } from "./components/SignatureVerificationWrapper.tsx";
(async () => {
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<ChakraProvider theme={lightTheme}>
<ColorModeScript initialColorMode="light" />
<VeChainKitProviderWrapper>
<SignatureVerificationWrapper>
<AppProvider>
<RouterProvider router={router} />
</AppProvider>
</SignatureVerificationWrapper>
</VeChainKitProviderWrapper>
</ChakraProvider>
</React.StrictMode>,
);
})();
import { useConnex } from '@vechain/vechain-kit';
export default function Home(): ReactElement {
const connex = useConnex();
const handleSignWithConnex = () => {
connex.vendor.sign(
'cert',
{
purpose: 'identification',
payload: {
type: 'text',
content: 'Please sign this message to connect your wallet.',
},
}
).request();
}
return <button onClick={handleSignWithConnex}> Sign </button>
}
Fee Delegation
Fee Delegation is mostly meant to be implemented to support end-user-experience, removing the need to purchase/collect gas tokens and remove need to pay for the applications activities.
Currently, it is mandatory to sponsor transaction for users that use social login. You can deploy your own custom solution or use vechain.energy.
FEE_DELEGATION_URL
You need to set this parameter in your VeChainKitProvider weapper.
You need one per environmnet.
To obtain one you can deploy your own custom solution or use vechain.energy.
Option 1: create your own
You can deploy this as a microservice (through lambda, cloudflare, etc.) or as an endpoint of your backend.
import { Address, HDKey, Transaction, Secp256k1, Hex } from '@vechain/sdk-core';
// the default signer is a solo node seeded account
const DEFAULT_SIGNER = 'denial kitchen pet squirrel other broom bar gas better priority spoil cross'
export async function onRequestPost({ request, env }): Promise<Response> {
const body = await request.json()
console.log('Incoming request', body);
const signerWallet = HDKey.fromMnemonic((env.SIGNER_MNEMONIC ?? DEFAULT_SIGNER).split(' '), HDKey.VET_DERIVATION_PATH).deriveChild(0);
if (!signerWallet.publicKey || !signerWallet.privateKey) { throw new Error('Could not load signing wallet') }
const signerAddress = Address.ofPublicKey(signerWallet.publicKey)
const transactionToSign = Transaction.decode(
Buffer.from(body.raw.slice(2), 'hex'),
false
);
const transactionHash = transactionToSign.getSignatureHash(Address.of(body.origin))
const signature = Secp256k1.sign(transactionHash.bytes, signerWallet.privateKey)
return new Response(JSON.stringify({
signature: Hex.of(signature).toString(),
address: signerAddress.toString()
}), {
status: 200,
headers: {
'Content-Type': 'application/json',
'access-control-allow-origin': '*'
}
})
}
Add this address 0xD7B96cAC488fEE053daAf8dF74f306bBc237D3f5 (MAINNET) or 0x7C5114ef27a721Df187b32e4eD983BaB813B81Cb (TESTNET) in {YourProjectName/FeeDelegation/Configurations/Smart Contract to sponsor all transactions.
// Smart contract to allow delegate all requests
/
pragma solidity ^0.8.20;
contract FeeDelegation {
/**
* @dev Check if a transaction can be sponsored for a user
*/
function canSponsorTransactionFor(
address _origin,
address _to,
bytes calldata _data
) public view returns (bool) {
return true;
}
}
Enable email notifications to let you know of low VTHO balance.
What is Fee Delegation?
Fee Delegation is a simple process that creates a magical user experience using blockchains without losing decentralized benefits.
The user submitting a transaction requests a second signature from a gas payer.
When the transaction is processed, the gas costs are taken from the gas payers balance instead of the user submitting the transaction.
It creates a feeless and trustless solution for instant blockchain access.
It stops users from instantly using an application. Users that need to pay for transactions are required to obtain a token from somewhere. Regular users do not know where to go and researching a place to buy and accessing a (de)centralized exchange is too much to ask for a user that wants to use your application.
What does it allow?
Users can open an application and interact with it instantly. An Application can submit transactions in the background and can no longer be be distinguished from regular(web2) alternatives. Fee delegation solves the biggest hurdle of user on - boarding to blockchain - applications without invalidating the web3 - principles.
Fee Delegation is mostly meant to be implemented to support end-user-experience, removing the need to purchase/collect gas tokens and remove need to pay for the applications activities.
Other use-cases are instant interactions with blockchains from different backends or processes without introducing account management for gas tokens.