Function.useKeybanAccount
function useKeybanAccount(): ApiResult<KeybanAccount>
Retrieves the current KeybanAccount
associated with the Keyban client.
This React hook allows you to access the user's Keyban account within a functional component.
It returns an ApiResult
tuple containing the account data or an error if one occurred during retrieval.
Returns
An array containing the account data, error, and an undefined value.
Example
import { useKeybanAccount } from "@keyban/sdk-react";
const MyComponent: React.FC = () => {
const [account, accountError] = useKeybanAccount();
if (accountError) throw accountError;
return (
<div>
<p>Your wallet address: {account.address}</p>
</div>
);
};
Remarks
- Ensure that your component is wrapped within a
KeybanProvider
to have access to the Keyban client context. - The hook internally uses React Suspense and may throw a promise if the data is not yet available.
- Handle errors appropriately to ensure a good user experience.