Encode and decode Bitcoin Cash addresses (CashAddr), including the token-aware types from CHIP-2022-02 CashTokens.
An address is a prefix ("bitcoincash", "bchtest" or "bchreg"), a type
and a payload: a 20-byte hash for P2PKH, a 20- or 32-byte hash for P2SH.
iex> {:ok, addr} = BitcoinElixir.CashAddr.decode("bitcoincash:qq8hepxlmyfelgyfy985tw80r8pe805gfv230d2ufw")
iex> {addr.prefix, addr.type}
{"bitcoincash", :p2pkh}
iex> BitcoinElixir.CashAddr.to_token_aware("bitcoincash:qq8hepxlmyfelgyfy985tw80r8pe805gfv230d2ufw")
{:ok, "bitcoincash:zq8hepxlmyfelgyfy985tw80r8pe805gfvdmuny6ka"}
Summary
Functions
Decode an address. Without a prefix in the text, default_prefix is used
("bitcoincash" unless given). Upper case is accepted; mixed case is not.
Encode a prefix, type and hash as an address.
Like encode/3 but raises on bad input.
The prefix for a network.
The same address with its plain type (q… or p…).
The same address with its token-aware type (z… or r…).
True for types that can receive CashTokens.
True if the text is a valid address. With a prefix, it must also match it.
Types
Functions
Decode an address. Without a prefix in the text, default_prefix is used
("bitcoincash" unless given). Upper case is accepted; mixed case is not.
Encode a prefix, type and hash as an address.
Like encode/3 but raises on bad input.
@spec prefix(:mainnet | :testnet | :regtest) :: prefix()
The prefix for a network.
The same address with its plain type (q… or p…).
The same address with its token-aware type (z… or r…).
True for types that can receive CashTokens.
True if the text is a valid address. With a prefix, it must also match it.