SDK for Elixir

Warthog provides an SDK for the Elixir/Erlang ecosystem called warthog_ex intended for interaction with the Warthog ecosystem.

Installation

The package is not yet published to Hex.pm. Install it directly from the GitHub repository:

# mix.exs
def deps do
  [
    {:warthog_ex, github: "warthog-network/warthog_ex"}
  ]
end

Then:

mix deps.get
mix deps.compile

A working C toolchain may be required (the ex_secp256k1 dependency ships prebuilt NIFs for common platforms; otherwise it builds from source)

Features

  • Generate wallets and HD accounts, sign transactions
  • Built-in HTTP client for node communication
  • All 7 signed DeFi transaction types: wartTransfer, tokenTransfer, assetCreation, cancelation, liquidityDeposit, liquidityWithdrawal, limitSwap
  • Idiomatic Elixir API: {:ok, value} | :error returns, name!/1 bang variants that raise on invalid input
  • Battle-tested crypto via ex_secp256k1 (Rust NIF backed by libsecp256k1) and BIP-39/BIP-32 via cryptopunk

Quick Start

alias WarthogEx.{
  Account,
  Address,
  DeFiApi,
  DeFiTransactionContext,
  Funds,
  Liquidity,
  NonceId,
  Price,
  RoundedFee,
  TokenDecimals,
  TransactionContext,
  Wart
}

# 1. Load or generate your account
account = Account.from_private_key_hex!("your-private-key-hex")

# 2. Prepare the recipient
{:ok, recipient} = Address.from_hex("0000000000000000000000000000000000000000de47c9b2")

# 3. Connect to a core/defi node. This client reads the V2 /chain/head format.
api = DeFiApi.new("http://127.0.0.1:3100")

# 4. Fetch the chain head and build a transaction context
{:ok, ctx} = DeFiApi.create_transaction_context(api, RoundedFee.min(), NonceId.random())

# 5. Build and sign a WART transfer
tx = TransactionContext.transfer_wart(ctx, account, recipient, Wart.from_e8!(100_000_000))

# 6. Submit
{:ok, %{txHash: hash}} = DeFiApi.submit_transaction(api, tx)

The nonce

The nonce is a replay tag, not a counter. A transaction is identified by its (account, pin height, nonce) triple, and the only check a node makes is that it has not seen that triple before: a repeat is rejected with ENONCE, unless the new transaction pays a higher fee, in which case it replaces the old one.

The nonce does not have to increase, and no node reports an account's next nonce, so there is nothing to fetch and nothing to keep track of. Use the random one:

nonce = NonceId.random()