Hooks
Hooks
useDecane()
Reactive state hook. Re-renders on any wallet or session change.
tsx
const {
// Detected wallets
wallets, // all wallets
evmWallets, // EVM wallets
solanaWallets, // Solana wallets
tronWallets, // Tron wallets
bitcoinWallets, // Bitcoin wallets
multiChainWallets, // wallets supporting 2+ chains
// Connection state
isConnected,
connectedWallet, // UnifiedWalletAccount | null
activeSession, // ActiveSession | null
activeChain, // CAIP-2 string | null
// Theme
theme, // "light" | "dark" | "auto"
setTheme, // (t: Theme) => void
// Actions
connect, // (wallet, preference?) => Promise<void>
disconnect, // () => Promise<void>
addChain, // (chain: ChainDescriptor) => void
removeChain, // (chainId: string) => void
} = useDecane();useWalletSelector()
Controls the wallet modal.
tsx
const { isOpen, open, close } = useWalletSelector();useSignMessage()
Works on EVM, Solana, Tron, Bitcoin, and social wallets.
tsx
const { signMessage, signature, loading, error, reset } = useSignMessage();
// Uses active chain and account automatically
await signMessage("Hello world");
// Override chain explicitly
await signMessage("Hello world", { chainId: CHAINS.POLYGON });useSendTransaction()
Works on EVM, Solana, Tron, and Bitcoin.
tsx
const { sendTransaction, txHash, loading, error, reset } = useSendTransaction();
// EVM — value in wei
await sendTransaction({
to: "0xRecipient",
value: "1000000000000000",
gas: "21000",
});
// Bitcoin — value in satoshis
await sendTransaction({ to: "bc1q…", value: "10000" }, { chainId: CHAINS.BITCOIN });useSignTypedData()
EVM only. Throws DecaneErrorCode.EVM_ONLY_METHOD if called on a non-EVM chain.
tsx
const { signTypedData, signature, loading, error, reset } = useSignTypedData();
await signTypedData({
domain: { name: "MyApp", version: "1", chainId: 1 },
types: { Permit: [{ name: "owner", type: "address" }, …] },
message: { owner: "0xAbc…", spender: "0xDef…", value: "1000" },
});useChainSwitch()
Switch the active chain within the current session.
tsx
const { switchChain, activeChain, grantedChains, loading, error } = useChainSwitch();
await switchChain(CHAINS.POLYGON);