Cardanoex.Transaction (cardanoex v0.6.0)

The Transaction module lets you work with transactions for a wallet.

Link to this section Summary

Functions

Create and send transaction from the wallet.

Estimate fee for the transaction. The estimate is made by assembling multiple transactions and analyzing the distribution of their fees. The estimated_max is the highest fee observed, and the estimated_min is the fee which is lower than at least 90% of the fees observed.

Get transaction by id.

Lists all incoming and outgoing wallet's transactions.

Link to this section Types

Specs

amount() :: %{quantity: non_neg_integer(), unit: String.t()}

Specs

asset() :: %{
  policy_id: String.t(),
  asset_name: String.t(),
  quantity: non_neg_integer()
}
Link to this type

collateral()

Specs

collateral() :: %{
  address: String.t(),
  amount: amount(),
  id: String.t(),
  index: non_neg_integer()
}
Link to this type

create_transaction()

Specs

create_transaction() :: %{
  passphrase: String.t(),
  payments: [payment()],
  withdrawal: String.t() | nil,
  metadata: map()
}
Link to this type

fee_estimation()

Specs

fee_estimation() :: %{
  deposit: amount(),
  estimated_max: amount(),
  estimated_min: amount(),
  minimum_coins: [amount()]
}

Specs

input() :: %{
  address: String.t(),
  amount: amount(),
  assets: [asset()],
  id: String.t(),
  index: non_neg_integer()
}

Specs

output() :: %{address: String.t(), amount: amount(), assets: [asset()]}

Specs

payment() :: %{
  address: String.t(),
  amount: non_neg_integer(),
  assets: [asset()] | nil
}
Link to this type

transaction()

Specs

transaction() :: %{
  amount: amount(),
  collateral: [collateral()],
  deposit: amount(),
  depth: %{quantity: non_neg_integer(), unit: String.t()},
  direction: String.t(),
  expires_at: %{
    absolute_slot_number: non_neg_integer(),
    epoch_number: non_neg_integer(),
    slot_number: non_neg_integer(),
    time: String.t()
  },
  fee: amount(),
  id: String.t(),
  inputs: [input()],
  inserted_at: %{
    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()
  },
  metadata: map() | nil,
  mint: list(),
  outputs: [output()],
  pending_since: %{
    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()
  },
  status: String.t(),
  withdrawals: [withdrawal()],
  script_validity: String.t() | nil
}
Link to this type

withdrawal()

Specs

withdrawal() :: %{stake_address: String.t(), amount: amount()}

Link to this section Functions

Link to this function

create(wallet_id, transaction)

Specs

create(String.t(), create_transaction()) ::
  {:error, String.t()} | {:ok, transaction()}

Create and send transaction from the wallet.

Options

  • wallet_id - hex based string. 40 characters
  • transaction - A map with the following structure:
  %{
    payments: [
          %{
            address: "addr_test1qruzy7l5...nq04es9elzy7",
            amount: %{quantity: 42_000_000, unit: "lovelace"}
          }
        ]
  }

  # With asset:
  %{
    payments: [
      %{
        address:"addr_test1qruzy7l5...nq04es9elzy7",
            amount: %{quantity: 1_407_406, unit: "lovelace"},
            assets: [
              %{
                policy_id: "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7",
                asset_name: "",
                quantity: 0
              }
            ]
          }
        ]
  }

  # With metadata:
  %{
    payments: [
      %{
        address: "addr_test1qruzy7l5...nq04es9elzy7",
            amount: %{quantity: 1_407_406, unit: "lovelace"}
      }
    ],
    metadata: %{"0" => %{"string" => "cardano"}, "1" => %{"int" => 14}}
  }
Link to this function

estimate_fee(wallet_id, transaction)

Specs

estimate_fee(String.t(), create_transaction()) ::
  {:error, String.t()} | {:ok, fee_estimation()}

Estimate fee for the transaction. The estimate is made by assembling multiple transactions and analyzing the distribution of their fees. The estimated_max is the highest fee observed, and the estimated_min is the fee which is lower than at least 90% of the fees observed.

Options

  • wallet_id - hex based string. 40 characters
  • transaction - A map with the following structure:
  %{
    payments: [
          %{
            address: "addr_test1qruzy7l5...nq04es9elzy7",
            amount: %{quantity: 42_000_000, unit: "lovelace"}
          }
        ]
  }

  # With asset:
  %{
    payments: [
      %{
        address:"addr_test1qruzy7l5...nq04es9elzy7",
            amount: %{quantity: 1_407_406, unit: "lovelace"},
            assets: [
              %{
                policy_id: "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7",
                asset_name: "",
                quantity: 0
              }
            ]
          }
        ]
  }

  # With metadata:
  %{
    payments: [
      %{
        address: "addr_test1qruzy7l5...nq04es9elzy7",
            amount: %{quantity: 1_407_406, unit: "lovelace"}
      }
    ],
    metadata: %{"0" => %{"string" => "cardano"}, "1" => %{"int" => 14}}
  }
Link to this function

get(wallet_id, transaction_id)

Specs

get(String.t(), String.t()) :: {:error, String.t()} | {:ok, transaction()}

Get transaction by id.

Options

  • transaction_id - Transaction ID
Link to this function

list(wallet_id, options \\ [])

Specs

list(String.t(),
  start: String.t(),
  stop: String.t(),
  order: atom(),
  min_withdrawal: non_neg_integer()
) :: {:error, String.t()} | {:ok, [transaction()]}

Lists all incoming and outgoing wallet's transactions.

Options

  • start - An optional start time in ISO 8601 date-and-time format. Basic and extended formats are both accepted. Times can be local (with a timezone offset) or UTC. If both a start time and an end time are specified, then the start time must not be later than the end time. Example: 2008-08-08T08:08:08Z
  • stop - An optional end time in ISO 8601 date-and-time format. Basic and extended formats are both accepted. Times can be local (with a timezone offset) or UTC. If both a start time and an end time are specified, then the start time must not be later than the end time.
  • order - Can be set to :descending or :ascending. Defaults to :descending
  • min_withdrawal - Returns only transactions that have at least one withdrawal above the given amount. This is particularly useful when set to 1 in order to list the withdrawal history of a wallet.