BSV.Address (BSV v2.1.0) View Source

A Bitcoin address is a 26-35 character string beginning with the number 1, that represents the hash of a pulic key.

An address is derived by calculating the RIPEMD hash of a SHA-256 hash of the public key, and then Base58check encoding it.

Addresses are used in P2PKH outputs, a common script template used to send Bitcoin payments.

Link to this section Summary

Types

Bitcoin address string

t()

Bitcoin address

Link to this section Types

Specs

address_str() :: String.t()

Bitcoin address string

Base58Check encoded public key hash.

Specs

t() :: %BSV.Address{pubkey_hash: <<_::160>>}

Bitcoin address

An Elixir struct containing the public key hash.

Link to this section Functions

Specs

from_pubkey(BSV.PubKey.t() | binary()) :: t()

Converts the given BSV.PubKey.t/0 into an BSV.Address.t/0.

Examples

iex> Address.from_pubkey(@pubkey)
%Address{
  pubkey_hash: <<83, 143, 209, 121, 200, 190, 15, 40, 156, 115, 14, 51, 181, 246, 163, 84, 27, 233, 102, 143>>
}

Specs

from_string(address_str()) :: {:ok, t()} | {:error, term()}

Decodes the given BSV.Address.address_str/0 into an BSV.Address.t/0.

Returns the result in an :ok / :error tuple pair.

Examples

iex> Address.from_string("18cqNbEBxkAttxcZLuH9LWhZJPd1BNu1A5")
{:ok, %Address{
  pubkey_hash: <<83, 143, 209, 121, 200, 190, 15, 40, 156, 115, 14, 51, 181, 246, 163, 84, 27, 233, 102, 143>>
}}

Specs

from_string!(address_str()) :: t()

Decodes the given BSV.Address.address_str/0 into an BSV.Address.t/0.

As from_string/1 but returns the result or raises an exception.

Specs

to_string(t()) :: address_str()

Encodes the given BSV.Address.t/0 as a Base58Check encoded BSV.Address.address_str/0.

Example

iex> Address.to_string(@address)
"18cqNbEBxkAttxcZLuH9LWhZJPd1BNu1A5"