Usage
Initialization
1. Optional: Wallet Connect Options
import type { WalletConnectOptions } from '@vechain/dapp-kit';
const walletConnectOptions: WalletConnectOptions = {
// Create your project here: https://cloud.walletconnect.com/sign-up
projectId: '<PROJECT_ID>',
metadata: {
name: 'My dApp',
description: 'My dApp description',
// Your app URL
url: window.location.origin,
// Your app Icon
icons: [`${window.location.origin}/images/my-dapp-icon.png`],
},
};2. Initialise theDAppKitProvider
import { DAppKitProvider } from '@vechain/dapp-kit-react';
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<DAppKitProvider
// REQUIRED: The URL of the node you want to connect to
nodeUrl={'https://testnet.vechain.org/'}
// OPTIONAL: Required if you're not connecting to the main net
genesis={'test'}
// OPTIONAL: Whether or not to persist state in local storage (account, wallet source)
usePersistence={true}
// OPTIONAL: Options to enable wallet connect
walletConnectOptions={walletConnectOptions}
// OPTIONAL: A log level for console logs
logLevel="DEBUG"
>
<App />
</DAppKitProvider>
</React.StrictMode>,
);Hooks
useWallet
useWalletuseConnex
useConnexThis hook exposes the
thorandvendorinstances of@vechain/connex. To interact with a wallet, you mustuseWalletand callsetSourcefirst.
useModal
useModalThis hook can be used to open and close the wallet modal.
The modal will display the available wallets and allow the user to connect to one of them.
Once the user has connected, the modal will close itself
UI Components
ConnectWalletButton
ConnectWalletButtonThis component mounts a button that will open a modal with the available wallets when clicked.
The user can then select a wallet of their choice and connect to it.
Once connected,
accountandsourcewill be available via theuseWallethook.
Last updated
Was this helpful?