import { isAddress } from '@solana/addresses';
if (isAddress(ownerAddress)) {
// At this point, `ownerAddress` has been refined to a
// `Address` that can be used with the RPC.
const { value: lamports } = await rpc.getBalance(ownerAddress).send();
setBalanceLamports(lamports);
} else {
setError(`${ownerAddress} is not an address`);
}
A type guard that returns
trueif the input string conforms to the Address type, and refines its type for use in your program.