Address Conversions
Convert between 0x Ethereum addresses and bb1 BitBadges addresses, and validate addresses, with the bitbadges SDK.
Every account has one bb1 (bech32) address and one 0x (hex) address that encode the same bytes. The SDK converts between them and validates either form.
Example
bb account convert 0x0bc63cfe31d5218eb414b142c799e20964a54a1a
bb account validate bb1p0rrel3365scadq5k9pv0x0zp9j22js6dnw70d{ "ok": true, "data": { "result": "bb1p0rrel3365scadq5k9pv0x0zp9j22js6dnw70d", "source": "0x0bc63cfe31d5218eb414b142c799e20964a54a1a", "target": "bb1" }, "warnings": [], "error": null }import { convertToBitBadgesAddress, convertToEthAddress, isAddressValid } from 'bitbadges';
const bb = convertToBitBadgesAddress('0x0bc63cfe31d5218eb414b142c799e20964a54a1a');
// "bb1p0rrel3365scadq5k9pv0x0zp9j22js6dnw70d"
const eth = convertToEthAddress('bb1p0rrel3365scadq5k9pv0x0zp9j22js6dnw70d');
// "0x0bC63Cfe31D5218eB414b142c799e20964a54A1A"
// Validation: convertToBitBadgesAddress returns '' for invalid input
const userInput = 'bb1p0rrel3365scadq5k9pv0x0zp9j22js6dnw70x'; // bad checksum
if (convertToBitBadgesAddress(userInput)) {
console.log('valid');
} else {
console.log('invalid'); // this branch
}
// Or ask directly
console.log(isAddressValid('bb1p0rrel3365scadq5k9pv0x0zp9j22js6dnw70d')); // trueBehavior
convertToBitBadgesAddressaccepts abb1or0xaddress and returns thebb1form. It returns an empty string when the input does not parse.convertToEthAddressaccepts either form and returns the checksummed0xform.isAddressValid(address, chain?)returns a boolean. Pass aSupportedChainto require one format.- The chain, the API, and the SDK message classes expect
bb1addresses increator,from, andtoAddressesfields. Convert before you build a message. - Which address a wallet controls depends on the key derivation path, not on the format. See Signing Client for the Cosmos vs EVM adapter difference.