Hedera.Client (Hedera v0.2.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

Append contents to file (needs the file's key).

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.

Call a contract method. Opts: :gas, :amount, :function_parameters (ABI-encoded). The return value is in the record, not the receipt.

Deploy a smart contract. See Hedera.Transaction.contract_create/1 for opts (:bytecode or :file, plus :gas etc.). New contract id is in the receipt.

Create a file. See Hedera.Transaction.file_create/1 for opts. New file id is in the receipt.

Create a scheduled transfer. See Hedera.Transaction.schedule_create/1. Schedule id is in the receipt.

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).

Delete file (needs the file's key).

Freeze token for account (needs the freeze key).

Grant KYC of token to account (needs the KYC key).

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

Pause token (needs the pause key).

Revoke KYC of token from account (needs the KYC key).

Add the operator's (and any :signers') signature to a pending schedule.

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 NFTs of token. moves is a list of {sender, receiver, serial} tuples (AccountIds + integer serial). Needs sender authorization.

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

Unfreeze token for account (needs the freeze key).

Unpause token (needs the pause key).

Update file (opts: :contents, :keys, :expiration_seconds). Needs the file's key.

Wipe a token balance from account (needs the wipe key). Pass amount: for a fungible token or serials: (a list) for NFTs in opts.

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

append_file(client, file, contents, opts \\ [])

@spec append_file(t(), Hedera.FileId.t(), binary(), keyword()) ::
  {:ok, result()} | {:error, term()}

Append contents to file (needs the file's key).

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.

call_contract(client, contract, opts \\ [])

@spec call_contract(t(), Hedera.ContractId.t(), keyword()) ::
  {:ok, result()} | {:error, term()}

Call a contract method. Opts: :gas, :amount, :function_parameters (ABI-encoded). The return value is in the record, not the receipt.

create_contract(client, opts \\ [])

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

Deploy a smart contract. See Hedera.Transaction.contract_create/1 for opts (:bytecode or :file, plus :gas etc.). New contract id is in the receipt.

create_file(client, opts \\ [])

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

Create a file. See Hedera.Transaction.file_create/1 for opts. New file id is in the receipt.

create_schedule(client, opts \\ [])

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

Create a scheduled transfer. See Hedera.Transaction.schedule_create/1. Schedule id is in the receipt.

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).

delete_file(client, file, opts \\ [])

@spec delete_file(t(), Hedera.FileId.t(), keyword()) ::
  {:ok, result()} | {:error, term()}

Delete file (needs the file's key).

freeze_token(client, token, account, opts \\ [])

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

Freeze token for account (needs the freeze key).

grant_kyc(client, token, account, opts \\ [])

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

Grant KYC of token to account (needs the KYC key).

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.

pause_token(client, token, opts \\ [])

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

Pause token (needs the pause key).

revoke_kyc(client, token, account, opts \\ [])

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

Revoke KYC of token from account (needs the KYC key).

sign_schedule(client, schedule_id, opts \\ [])

@spec sign_schedule(t(), Hedera.ScheduleId.t(), keyword()) ::
  {:ok, result()} | {:error, term()}

Add the operator's (and any :signers') signature to a pending schedule.

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_nft(client, token, moves, opts \\ [])

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

Transfer NFTs of token. moves is a list of {sender, receiver, serial} tuples (AccountIds + integer serial). Needs sender authorization.

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).

unfreeze_token(client, token, account, opts \\ [])

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

Unfreeze token for account (needs the freeze key).

unpause_token(client, token, opts \\ [])

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

Unpause token (needs the pause key).

update_file(client, file, opts \\ [])

@spec update_file(t(), Hedera.FileId.t(), keyword()) ::
  {:ok, result()} | {:error, term()}

Update file (opts: :contents, :keys, :expiration_seconds). Needs the file's key.

wipe_token(client, token, account, opts \\ [])

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

Wipe a token balance from account (needs the wipe key). Pass amount: for a fungible token or serials: (a list) for NFTs in opts.