Address Best Practices
Recommendations
Address Best Practices
Use Hex-Encoded Public Keys
Never pass bech32 addresses to fromString(). Always use hex-encoded public keys. If only a bech32 address is available, resolve it to public keys through a provider first.
Secure Memory Cleanup
Use [Symbol.dispose] or call dispose() manually to zero sensitive key material when addresses are no longer needed.
Prefer P2OP for OP_NET Identifiers
Use p2op() for OP_NET-specific identifiers since it only requires the ML-DSA hash and avoids triggering expensive classical key processing.
Leverage Internal Caching
Results from toBigInt() and toUint64Array() are internally cached. Repeated calls are free, so external caching is unnecessary.
Use equals() for Comparison
For address comparison, use equals() rather than comparing hex strings for better performance.
Address Validation Best Practices
Always Validate Addresses
Always validate addresses before using them in transactions. Sending funds to an invalid address results in permanent loss.
Use detectAddressType() for Routing
Use detectAddressType() for routing logic instead of string-prefix heuristics, which can fail across networks.
Provide Witness Script for P2WDA
Provide the witness script when validating P2WDA to get definitive confirmation rather than just potential P2WDA status.
Validate Public Keys First
Validate public keys with isValidPublicKey() before passing them to Address.fromString() or multi-sig construction.
Check Network Parameter
Check the network parameter carefully. An address valid on mainnet may not be valid on testnet and vice versa.