BSV.Contract.P2PKH (BSV v2.1.0) View Source

Pay to Public Key Hash contract.

P2PKH scripts are used to lock Bitcoin to an address. The Bitcoin can later be unlocked using the private key corresponding to the address.

Lock parameters

Unlock parameters

Examples

iex> contract = P2PKH.lock(1000, %{address: Address.from_pubkey(@keypair.pubkey)})
iex> Contract.to_script(contract)
%Script{chunks: [
  :OP_DUP,
  :OP_HASH160,
  <<83, 143, 209, 121, 200, 190, 15, 40, 156, 115, 14, 51, 181, 246, 163, 84, 27, 233, 102, 143>>,
  :OP_EQUALVERIFY,
  :OP_CHECKSIG
]}

iex> contract = P2PKH.unlock(%UTXO{}, %{keypair: @keypair})
iex> Contract.to_script(contract)
%Script{chunks: [
  <<0::568>>, # signatures are zero'd out until the transaction context is attached
  <<3, 248, 31, 140, 139, 144, 245, 236, 6, 238, 66, 69, 234, 177, 102, 232, 175, 144, 63, 199, 58, 109, 215, 54, 54, 104, 126, 240, 39, 135, 10, 190, 57>>
]}

Link to this section Summary

Functions

Returns a locking script contract with the given parameters.

Returns an unlocking script contract with the given parameters.

Link to this section Functions

Link to this function

lock(satoshis, params, opts \\ [])

View Source

Specs

Returns a locking script contract with the given parameters.

Link to this function

unlock(utxo, params, opts \\ [])

View Source

Specs

unlock(BSV.UTXO.t(), map(), keyword()) :: BSV.Contract.t()

Returns an unlocking script contract with the given parameters.