Hedera.Client (Hedera v0.1.0)

Copy Markdown View Source

High-level entry point: holds the operator identity and the network's node address book, builds and submits Consensus Service transactions, retries across nodes on transient failures, and fetches receipts.

client = Hedera.Client.testnet(operator_id, operator_key)
{:ok, %{precheck_code: 0}} = Hedera.Client.submit_message(client, topic_id, "payload")

Summary

Functions

Associate tokens with account. The account must sign; when it is not the operator, pass its key via signers: [account_key] in opts.

Burn amount of a token from the treasury. Needs the supply key.

Create a new HTS token. See Hedera.Transaction.token_create/1 for opts (:treasury is required). The new token's id is in the receipt's token_id.

Create a new HCS topic (open, unless :memo given).

Mint amount of (or :metadata for) a token. Needs the supply key.

Submit a message to an HCS topic (retries across nodes on transient errors).

Build a testnet client (with the full testnet node address book).

Fetch a transaction's consensus receipt, polling until final (free query).

Transfer HBAR between accounts (retries across nodes on transient errors).

Transfer an HTS token between accounts. moves is a list of {%AccountId{}, amount} pairs that must net to zero (debits negative).

Types

result()

@type result() :: %{
  precheck_code: integer(),
  ok?: boolean(),
  transaction_id: Hedera.TransactionId.t()
}

t()

@type t() :: %Hedera.Client{
  nodes: [Hedera.Network.node_info()],
  operator_id: Hedera.AccountId.t(),
  operator_key: Hedera.PrivateKey.t()
}

Functions

associate_token(client, account, tokens, opts \\ [])

@spec associate_token(t(), Hedera.AccountId.t(), [Hedera.TokenId.t()], keyword()) ::
  {:ok, result()} | {:error, term()}

Associate tokens with account. The account must sign; when it is not the operator, pass its key via signers: [account_key] in opts.

burn_token(client, token, amount, opts \\ [])

@spec burn_token(t(), Hedera.TokenId.t(), non_neg_integer(), keyword()) ::
  {:ok, result()} | {:error, term()}

Burn amount of a token from the treasury. Needs the supply key.

create_token(client, opts \\ [])

@spec create_token(
  t(),
  keyword()
) :: {:ok, result()} | {:error, term()}

Create a new HTS token. See Hedera.Transaction.token_create/1 for opts (:treasury is required). The new token's id is in the receipt's token_id.

create_topic(client, opts \\ [])

@spec create_topic(
  t(),
  keyword()
) :: {:ok, result()} | {:error, term()}

Create a new HCS topic (open, unless :memo given).

mint_token(client, token, amount, opts \\ [])

@spec mint_token(t(), Hedera.TokenId.t(), non_neg_integer(), keyword()) ::
  {:ok, result()} | {:error, term()}

Mint amount of (or :metadata for) a token. Needs the supply key.

submit_message(client, topic_id, message)

@spec submit_message(t(), Hedera.TopicId.t(), binary()) ::
  {:ok, result()} | {:error, term()}

Submit a message to an HCS topic (retries across nodes on transient errors).

testnet(operator_id, operator_key)

@spec testnet(Hedera.AccountId.t(), Hedera.PrivateKey.t()) :: t()

Build a testnet client (with the full testnet node address book).

transaction_receipt(client, tx_id, opts \\ [])

@spec transaction_receipt(t(), Hedera.TransactionId.t(), keyword()) ::
  {:ok, Hedera.Receipt.t()} | {:error, term()}

Fetch a transaction's consensus receipt, polling until final (free query).

transfer_hbar(client, transfers, opts \\ [])

@spec transfer_hbar(t(), [{Hedera.AccountId.t(), integer()}], keyword()) ::
  {:ok, result()} | {:error, term()}

Transfer HBAR between accounts (retries across nodes on transient errors).

transfers is a list of {%AccountId{}, amount_in_tinybars} pairs; debits are negative, credits positive, and they must net to zero.

Hedera.Client.transfer_hbar(client, [{from, -1}, {to, 1}])

transfer_token(client, token, moves, opts \\ [])

@spec transfer_token(
  t(),
  Hedera.TokenId.t(),
  [{Hedera.AccountId.t(), integer()}],
  keyword()
) ::
  {:ok, result()} | {:error, term()}

Transfer an HTS token between accounts. moves is a list of {%AccountId{}, amount} pairs that must net to zero (debits negative).