Wallet Hooks
React hooks for interacting with connected wallets.
React Hooks allow function components to have access to state and other React features. With Mesh Hooks, you can easily interact and access wallet data.
useAssets Hook
import { useAssets } from "@meshsdk/midnight-react";
export default function Home() {
const {
address,
coinPublicKey,
encryptionPublicKey,
hasConnectedWallet,
isProofServerOnline,
uris,
walletName,
} = useAssets();
return (
<div>
<div>Wallet Name: {walletName}</div>
<div>Address: {address}</div>
<div>Coin Public Key: {coinPublicKey}</div>
<div>Encryption Public Key: {encryptionPublicKey}</div>
<div>Has Connected Wallet: {hasConnectedWallet ? "Yes" : "No"}</div>
<div>Is Proof Server Online: {isProofServerOnline ? "Yes" : "No"}</div>
<div>Indexer: {uris?.indexerUri}</div>
<div>IndexerWS: {uris?.indexerWsUri}</div>
<div>Proof Server: {uris?.proverServerUri}</div>
<div>Node: {uris?.substrateNodeUri}</div>
</div>
);
}ℹ️
Output and function signatures
| Wallet Name | mnLace |
| Address | feff6534cae3d59e03275b299f2cd052e02e2084cfd63c4fff2568971c1343e|0300aa6a2d2ed980354bc5f14d595e6b6d8bd740bb99e9115c167c357e2b52865cb808f54d5ce551b5d79df33bb3878baaba5aa8a1be4d510b88 |
| Coin Public Key | 5feff6534cae3d59e03275b299f2cd052e02e2084cfd63c4fff2568971c1343e |
| Encryption Public Key | 0300aa6a2d2ed980354bc5f14d595e6b6d8bd740bb99e9115c167c357e2b52865cb808f54d5ce551b5d79df33bb3878baaba5aa8a1be4d510b88 |
| Has Connected Wallet | Boolean (true or false) |
| Is Proof Server Online | Boolean (true or false) |
| Indexer | http://localhost:8088/api/v1/graphql |
| IndexerWS | ws://localhost:8088/api/v1/graphql/ws |
| Proof Server | http://localhost:6300 |
| Node | http://localhost:9944 |
useWallet Hook
import { useWallet } from "@meshsdk/midnight-react";
export default function Home() {
const { connectingWallet, disconnect, setOpen, connectWallet } = useWallet();
return (
<div>
<div>Connecting Wallet: {connectingWallet? "Yes" : "No"}</div>
<div onClick={disconnect}>Disconnect Wallet</div>
<div onClick={() => setOpen(true)}>Open Wallet Dialog</div>
<div onClick={() => connectWallet("mnLace")}>Connect to the Lace Wallet</div>
</div>
);
}ℹ️
Output and function signatures
| Connecting Wallet | Boolean (true or false) |
Disconnect Wallet
const disconnect: () => voidOpen Wallet Dialog
const setOpen: (value: boolean) => voidConnect to the Lace Wallet
const connectWallet: (walletName: string, persist?: boolean) => Promise<void>useWalletList Hook
import { useWalletList } from "@meshsdk/midnight-react";
const walletList = useWalletList(); ℹ️
Output and function signatures
walletList
const walletList: DAppConnectorAPI[]useWalletBalanceProve Hook
import { useWalletBalanceProve } from "@meshsdk/midnight-react";
const {result, submitTx, submitting} = useWalletBalanceProve(); ℹ️
Output and function signatures
| submitting | Boolean (true or false) |
submitTx
const submitTx: (tx: Transaction, newCoins: CoinInfo[]) => Promise<void>result
const result: Transaction | undefineduseWalletSubmit Hook
import { useWalletSubmit } from "@meshsdk/midnight-react";
const { result, submitTx, submitting } = useWalletSubmit();ℹ️
Output and function signatures
| submitting | Boolean (true or false) |
submitTx
const submitTx: (signedTx: Transaction) => Promise<void>result
const result: string | undefined