Transaction Context
// https://api.bitbadges.io/api/v0/user?address=bb1...
const res = await BitBadgesApi.getAccount({ address: '...' });
const account = res.account;
const { accountNumber, sequence, publicKey } = account;
if (Number(accountNumber) <= 0) {
// The account hasn't interacted with the chain yet β it has no
// account ID, so the chain can't validate a signed tx from it.
// Register the account by sending it any non-zero amount of any
// denom (BADGE works); the next block assigns an account number.
//
// Production apps typically route the user to:
// β’ The faucet (testnet only β see ai-agents/testnet-faucet.md), or
// β’ An MsgSend signed by an already-registered key (mainnet),
//
// β¦then re-fetch the account via `BitBadgesApi.getAccount` to pick
// up the now-valid accountNumber. The snippet below stops the flow
// cleanly so the calling app can decide which registration path
// to use:
throw new Error(
`Account ${account.address} is unregistered. ` +
`Send it any non-zero balance (e.g. via MsgSend or the testnet faucet) ` +
`and re-fetch before building a tx context.`
);
}Last updated