Hedera.Transaction (Hedera v0.2.0)

Copy Markdown View Source

Builds and signs Hedera transactions for the Consensus, Crypto, Token, File and Schedule services.

The flow follows the Hedera HAPI: build a TransactionBody, encode it, sign the exact bodyBytes with the operator key (and any additional :signers), wrap them in a SignedTransaction (bodyBytes + signature map) and finally a Transaction (signedTransactionBytes). The signature is computed over the precise bodyBytes that are transmitted.

The wire encoding is handled by the protoc-generated Hedera.Pb.* modules (see priv/protos/hedera_min.proto); this module maps the SDK's structs onto those messages. Field numbers therefore live in the .proto, validated end-to-end against a live node by the gRPC layer.

Summary

Functions

Build + sign a contractCall. Required: :contract (a ContractId). Opts: :gas (default 50 000), :amount (tinybars to send), :function_parameters (ABI-encoded call data). The return value is in the record, not the receipt.

Build + sign a contractCreateInstance. Provide the bytecode either inline via :bytecode (EVM init bytecode) or by :file (a FileId holding it). Opts: :gas (default 100 000), :admin_key, :initial_balance, :constructor_parameters, :auto_renew_period, :contract_memo. The new contract id is returned in the receipt.

Build + sign a consensusCreateTopic transaction. Optional: :memo, :max_fee.

Build + sign a cryptoTransfer of HBAR and/or HTS tokens. Opts: :transfers ({%AccountId{}, tinybars} list), :token_transfers ({%TokenId{}, [{%AccountId{}, amount}]} list), :nft_transfers ({%TokenId{}, [{sender, receiver, serial}]} list). Amounts are sint64 (ZigZag); each currency must net to zero. Optional: :memo, :max_fee.

Build + sign a fileAppend. Required: :file, :contents. Needs the file's key(s).

Build + sign a fileCreate. Opts: :contents, :keys (a list of PublicKeys; defaults to the operator's key), :expiration_seconds, :file_memo.

Build + sign a fileDelete. Required: :file. Needs the file's key(s).

Build + sign a fileUpdate. Required: :file. Optional: :contents, :keys, :expiration_seconds.

Build + sign a scheduleCreate wrapping an HBAR/token transfer (:transfers, :token_transfers, :nft_transfers describe the scheduled transaction). Optional: :admin_key, :schedule_memo.

Build + sign a scheduleSign. Required: :schedule_id.

Build + sign a consensusSubmitMessage transaction. Required opts: :operator_id, :operator_key, :node_account_id, :topic_id, :message. Optional: :max_fee, :memo.

Build + sign a tokenAssociate. Required: :account, :tokens (list of TokenId).

Build + sign a tokenBurn. Required: :token, :amount.

Build + sign a tokenCreation. Required: :treasury. Common opts: :name, :symbol, :decimals, :initial_supply, :token_type (:fungible | :nft), :supply_type (:infinite | :finite), :max_supply, :token_memo, :auto_renew_account, :auto_renew_period, and key opts :admin_key, :supply_key, :kyc_key, :freeze_key, :wipe_key, :pause_key.

Build + sign a tokenFreezeAccount. Required: :token, :account. Needs the freeze key.

Build + sign a tokenGrantKyc. Required: :token, :account. Needs the KYC key.

Build + sign a tokenMint. Required: :token. Opts: :amount (fungible) or :metadata (NFT).

Build + sign a tokenPause. Required: :token. Needs the pause key.

Build + sign a tokenRevokeKyc. Required: :token, :account. Needs the KYC key.

Build + sign a tokenUnfreezeAccount. Required: :token, :account. Needs the freeze key.

Build + sign a tokenUnpause. Required: :token. Needs the pause key.

Build + sign a tokenWipeAccount. Required: :token, :account. For fungible tokens pass :amount; for NFTs pass :serials. Needs the wipe key.

Types

build_result()

@type build_result() :: %{
  transaction: binary(),
  transaction_id: Hedera.TransactionId.t()
}

Functions

contract_call(opts)

@spec contract_call(keyword()) :: build_result()

Build + sign a contractCall. Required: :contract (a ContractId). Opts: :gas (default 50 000), :amount (tinybars to send), :function_parameters (ABI-encoded call data). The return value is in the record, not the receipt.

contract_create(opts)

@spec contract_create(keyword()) :: build_result()

Build + sign a contractCreateInstance. Provide the bytecode either inline via :bytecode (EVM init bytecode) or by :file (a FileId holding it). Opts: :gas (default 100 000), :admin_key, :initial_balance, :constructor_parameters, :auto_renew_period, :contract_memo. The new contract id is returned in the receipt.

create_topic(opts)

@spec create_topic(keyword()) :: build_result()

Build + sign a consensusCreateTopic transaction. Optional: :memo, :max_fee.

crypto_transfer(opts)

@spec crypto_transfer(keyword()) :: build_result()

Build + sign a cryptoTransfer of HBAR and/or HTS tokens. Opts: :transfers ({%AccountId{}, tinybars} list), :token_transfers ({%TokenId{}, [{%AccountId{}, amount}]} list), :nft_transfers ({%TokenId{}, [{sender, receiver, serial}]} list). Amounts are sint64 (ZigZag); each currency must net to zero. Optional: :memo, :max_fee.

file_append(opts)

@spec file_append(keyword()) :: build_result()

Build + sign a fileAppend. Required: :file, :contents. Needs the file's key(s).

file_create(opts)

@spec file_create(keyword()) :: build_result()

Build + sign a fileCreate. Opts: :contents, :keys (a list of PublicKeys; defaults to the operator's key), :expiration_seconds, :file_memo.

file_delete(opts)

@spec file_delete(keyword()) :: build_result()

Build + sign a fileDelete. Required: :file. Needs the file's key(s).

file_update(opts)

@spec file_update(keyword()) :: build_result()

Build + sign a fileUpdate. Required: :file. Optional: :contents, :keys, :expiration_seconds.

schedule_create(opts)

@spec schedule_create(keyword()) :: build_result()

Build + sign a scheduleCreate wrapping an HBAR/token transfer (:transfers, :token_transfers, :nft_transfers describe the scheduled transaction). Optional: :admin_key, :schedule_memo.

schedule_sign(opts)

@spec schedule_sign(keyword()) :: build_result()

Build + sign a scheduleSign. Required: :schedule_id.

submit_message(opts)

@spec submit_message(keyword()) :: build_result()

Build + sign a consensusSubmitMessage transaction. Required opts: :operator_id, :operator_key, :node_account_id, :topic_id, :message. Optional: :max_fee, :memo.

token_associate(opts)

@spec token_associate(keyword()) :: build_result()

Build + sign a tokenAssociate. Required: :account, :tokens (list of TokenId).

token_burn(opts)

@spec token_burn(keyword()) :: build_result()

Build + sign a tokenBurn. Required: :token, :amount.

token_create(opts)

@spec token_create(keyword()) :: build_result()

Build + sign a tokenCreation. Required: :treasury. Common opts: :name, :symbol, :decimals, :initial_supply, :token_type (:fungible | :nft), :supply_type (:infinite | :finite), :max_supply, :token_memo, :auto_renew_account, :auto_renew_period, and key opts :admin_key, :supply_key, :kyc_key, :freeze_key, :wipe_key, :pause_key.

token_freeze(opts)

@spec token_freeze(keyword()) :: build_result()

Build + sign a tokenFreezeAccount. Required: :token, :account. Needs the freeze key.

token_grant_kyc(opts)

@spec token_grant_kyc(keyword()) :: build_result()

Build + sign a tokenGrantKyc. Required: :token, :account. Needs the KYC key.

token_mint(opts)

@spec token_mint(keyword()) :: build_result()

Build + sign a tokenMint. Required: :token. Opts: :amount (fungible) or :metadata (NFT).

token_pause(opts)

@spec token_pause(keyword()) :: build_result()

Build + sign a tokenPause. Required: :token. Needs the pause key.

token_revoke_kyc(opts)

@spec token_revoke_kyc(keyword()) :: build_result()

Build + sign a tokenRevokeKyc. Required: :token, :account. Needs the KYC key.

token_unfreeze(opts)

@spec token_unfreeze(keyword()) :: build_result()

Build + sign a tokenUnfreezeAccount. Required: :token, :account. Needs the freeze key.

token_unpause(opts)

@spec token_unpause(keyword()) :: build_result()

Build + sign a tokenUnpause. Required: :token. Needs the pause key.

token_wipe(opts)

@spec token_wipe(keyword()) :: build_result()

Build + sign a tokenWipeAccount. Required: :token, :account. For fungible tokens pass :amount; for NFTs pass :serials. Needs the wipe key.