Cardanoex.Wallet (cardanoex v0.6.3)

The wallet module lets you work with Cardano wallets.

Wallets are identified by unique ID which is deterministically derived from the seed (mnemonic phrase), so each time you delete and create a wallet again, it receives the same ID.

Link to this section Summary

Functions

Create and restore a wallet from a mnemonic sentence.

Delete wallet by wallet id

Fetch a wallet by wallet id

Return the UTxOs distribution across the whole wallet, in the form of a histogram.

Return a list of known wallets, ordered from oldest to newest.

Update the name of a wallet

Link to this section Types

@type assets() :: %{available: list(), total: list()}
@type balance() :: %{
  available: %{quantity: non_neg_integer(), unit: String.t()},
  reward: %{quantity: non_neg_integer(), unit: String.t()},
  total: %{quantity: non_neg_integer(), unit: String.t()}
}
Link to this type

delegation()

@type delegation() :: %{active: %{status: String.t()}, next: list()}
Link to this type

passphrase()

@type passphrase() :: %{last_updated_at: String.t()}
@type state() :: %{
  progress: %{quantity: non_neg_integer(), unit: String.t()},
  status: String.t()
}
@type tip() :: %{
  absolute_slot_number: non_neg_integer(),
  epoch_number: non_neg_integer(),
  height: %{quantity: non_neg_integer(), unit: String.t()},
  slot_number: non_neg_integer(),
  time: String.t()
}
Link to this type

utxo_stats()

@type utxo_stats() :: %{
  distribution: %{
    "10": non_neg_integer(),
    "100": non_neg_integer(),
    "1000": non_neg_integer(),
    "10000": non_neg_integer(),
    "100000": non_neg_integer(),
    "1000000": non_neg_integer(),
    "10000000": non_neg_integer(),
    "100000000": non_neg_integer(),
    "1000000000": non_neg_integer(),
    "10000000000": non_neg_integer(),
    "100000000000": non_neg_integer(),
    "1000000000000": non_neg_integer(),
    "10000000000000": non_neg_integer(),
    "100000000000000": non_neg_integer(),
    "1000000000000000": non_neg_integer(),
    "10000000000000000": non_neg_integer(),
    "45000000000000000": non_neg_integer()
  },
  scale: String.t(),
  total: %{quantity: non_neg_integer(), unit: String.t()}
}
@type wallet() :: %{
  address_pool_gap: non_neg_integer(),
  assets: assets(),
  balance: balance(),
  delegation: delegation(),
  id: String.t(),
  name: String.t(),
  passphrase: passphrase(),
  state: state(),
  tip: tip()
}

Link to this section Functions

Link to this function

create_wallet(options \\ [])

@spec create_wallet(
  name: String.t(),
  mnemonic_sentence: String.t(),
  passphrase: String.t(),
  mnemonic_second_factor: String.t()
) :: {:error, String.t()} | {:ok, wallet()}

Create and restore a wallet from a mnemonic sentence.

options

Options

  • name - A human readable name for the wallet

  • mnemonic_sentence - A list of bip-0039 mnemonic words. 15-24 words.

  • passphrase - A master passphrase to lock and protect the wallet for sensitive operation (e.g. sending funds)

  • mnemonic_second_factor - An optional passphrase used to encrypt the mnemonic sentence. A list of bip-0039 mnemonic words. 9-12 words.

  • address_pool_gap - Number of consecutive unused addresses allowed. Default is 20.

    IMPORTANT DISCLAIMER: Using values other than 20 automatically makes your wallet invalid with regards to BIP-44 address discovery. It means that you will not be able to fully restore your wallet in a different software which is strictly following BIP-44.

    Beside, using large gaps is not recommended as it may induce important performance degradations. Use at your own risks.

Link to this function

delete(wallet_id)

@spec delete(String.t()) :: {:error, String.t()} | :ok

Delete wallet by wallet id

options

Options

  • wallet_id - hex based string. 40 characters
Link to this function

fetch(wallet_id)

@spec fetch(String.t()) :: {:error, String.t()} | {:ok, wallet()}

Fetch a wallet by wallet id

options

Options

  • wallet_id - hex based string. 40 characters
Link to this function

fetch_utxo_stats(wallet_id)

@spec fetch_utxo_stats(String.t()) :: {:error, String.t()} | {:ok, utxo_stats()}

Return the UTxOs distribution across the whole wallet, in the form of a histogram.

options

Options

  • wallet_id - hex based string. 40 characters
@spec list() :: {:error, String.t()} | {:ok, [wallet()]}

Return a list of known wallets, ordered from oldest to newest.

Link to this function

update(wallet_id, new_name)

@spec update(String.t(), String.t()) :: {:error, String.t()} | {:ok, wallet()}

Update the name of a wallet

options

Options

  • wallet_id - hex based string. 40 characters
  • new_name - the new name for the wallet
Link to this function

update_passphrase(wallet_id, old_passphrase, new_passphrase)

@spec update_passphrase(String.t(), String.t(), String.t()) ::
  {:error, String.t()} | :ok

Update passphrase for a wallet

options

Options

  • wallet_id - hex based string. 40 characters
  • old_passphrase - the old passphrase
  • new_passphrase - the new passphrase