useSelectedAccount
The currently selected account, or null
useSelectedAccount returns the account the user is currently acting as, a
SignerAccount with address, h160Address, publicKey, name and
source, or null while no wallet is connected. It reads the same shared
store as useAccounts, so select(address)
or disconnect() called anywhere updates every consumer at once.
It is the natural input for read hooks: pass account?.address straight into
useBalance or a chain query without guarding;
those hooks stay disabled while the address is undefined.
Usage
import { useSelectedAccount, truncateAddress } from "@use-truapi/react";
function AccountBadge() {
const account = useSelectedAccount();
if (!account) return <p>No account selected.</p>;
return (
<p>
{account.name ?? "Unnamed"}: <code>{truncateAddress(account.address)}</code>
</p>
);
}<script setup lang="ts">
import { useSelectedAccount, truncateAddress } from "@use-truapi/vue";
const account = useSelectedAccount();
</script>
<template>
<p v-if="!account">No account selected.</p>
<p v-else>
{{ account.name ?? "Unnamed" }}: <code>{{ truncateAddress(account.address) }}</code>
</p>
</template>The hook returns a ComputedRef: use account.value in script, it unwraps
automatically in templates.
See also
useAccountsexposes the full account list plusselectto change the selection.useSignerreturns thePolkadotSignerbehind the selected account.useBalancetakes the selected address for a live balance.
API reference
React
function useSelectedAccount(): SignerAccount | null;The currently selected account, or null.
Returns
SignerAccount | null
Vue
function useSelectedAccount(): ComputedRef<SignerAccount | null>;The currently selected account, or null.
Returns
ComputedRef<SignerAccount | null>