Skip to content

useAccounts

Provides access to the connected user's accounts and connection state.

Import

ts
import { useAccounts } from "@midl/react";

Params

NameTypeDescription
configConfig(optional) Config object to use instead of the one from context.

Example

tsx
function Page() {
  const {
    accounts,
    ordinalsAccount,
    paymentAccount,
    connector,
    isConnecting,
    isConnected,
    status,
    network,
    ...rest
  } = useAccounts();

  return (
    <div>
      {isConnected && (
        <div>
          <h2>Accounts</h2>
          <ul>
            {accounts?.map(account => (
              <li key={account.address}>{account.address}</li>
            ))}
          </ul>
        </div>
      )}
    </div>
  );
}

Returns

NameTypeDescription
accountsAccount[] | nullThe list of user accounts
ordinalsAccountAccount | undefinedThe ordinals account (p2tr)
paymentAccountAccount | undefinedThe payment account (p2wpkh)
connectorConnector | undefinedThe current connection
isConnectingbooleanIndicates if a connection is in progress
isConnectedbooleanIndicates if the connection has been established
status"success" | "pending" | "disconnected"The current connection status
networkBitcoinNetwork | undefinedThe connected network
...restAdditional query state provided by useQuery