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
@type result() :: %{ precheck_code: integer(), ok?: boolean(), transaction_id: Hedera.TransactionId.t() }
@type t() :: %Hedera.Client{ nodes: [Hedera.Network.node_info()], operator_id: Hedera.AccountId.t(), operator_key: Hedera.PrivateKey.t() }
Functions
@spec append_file(t(), Hedera.FileId.t(), binary(), keyword()) :: {:ok, result()} | {:error, term()}
Append contents to file (needs the file's key).
@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.
@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.
@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.
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).
@spec delete_file(t(), Hedera.FileId.t(), keyword()) :: {:ok, result()} | {:error, term()}
Delete file (needs the file's key).
@spec freeze_token(t(), Hedera.TokenId.t(), Hedera.AccountId.t(), keyword()) :: {:ok, result()} | {:error, term()}
Freeze token for account (needs the freeze key).
@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).
@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.
@spec pause_token(t(), Hedera.TokenId.t(), keyword()) :: {:ok, result()} | {:error, term()}
Pause token (needs the pause key).
@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).
@spec sign_schedule(t(), Hedera.ScheduleId.t(), keyword()) :: {:ok, result()} | {:error, term()}
Add the operator's (and any :signers') signature to a pending schedule.
@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).
@spec testnet(Hedera.AccountId.t(), Hedera.PrivateKey.t()) :: t()
Build a testnet client (with the full testnet node address book).
@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).
@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}])
@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.
@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).
@spec unfreeze_token(t(), Hedera.TokenId.t(), Hedera.AccountId.t(), keyword()) :: {:ok, result()} | {:error, term()}
Unfreeze token for account (needs the freeze key).
@spec unpause_token(t(), Hedera.TokenId.t(), keyword()) :: {:ok, result()} | {:error, term()}
Unpause token (needs the pause key).
@spec update_file(t(), Hedera.FileId.t(), keyword()) :: {:ok, result()} | {:error, term()}
Update file (opts: :contents, :keys, :expiration_seconds). Needs the file's key.
@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.