Show / Hide Table of Contents

Class TransferExtensions

Extension methods for transferring crypto, tokens, and NFTs.

Inheritance
object
TransferExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Hiero
Assembly: Hiero.dll
Syntax
public static class TransferExtensions

Methods

| Edit this page View Source

TransferAsync(ConsensusClient, EntityId, EntityId, long, Action<IConsensusContext>?)

Transfer tinybars from one account to another.

Declaration
public static Task<TransactionReceipt> TransferAsync(this ConsensusClient client, EntityId fromAddress, EntityId toAddress, long amount, Action<IConsensusContext>? configure = null)
Parameters
Type Name Description
ConsensusClient client

The Consensus Node Client orchestrating the transfer.

EntityId fromAddress

The address to transfer the tinybars from. Ensure that a signatory either in the context or passed with this call can fulfill the signing requirements to transfer crypto out of the account identified by this address.

EntityId toAddress

The address receiving the tinybars.

long amount

The amount of tinybars to transfer.

Action<IConsensusContext> configure

Optional callback method providing an opportunity to modify the execution configuration for just this method call. It is executed prior to submitting the request to the network.

Returns
Type Description
Task<TransactionReceipt>

A transfer receipt indicating success of the operation.

Examples
// Transfer 1 HBAR (100,000,000 tinybars) from `sender` to `receiver`.
// The client's Signatory must satisfy the sender's signing requirement.
var receipt = await client.TransferAsync(sender, receiver, 100_000_000);
Console.WriteLine($"Transfer status: {receipt.Status}");
Exceptions
Type Condition
ArgumentOutOfRangeException

If required arguments are missing.

InvalidOperationException

If required context configuration is missing.

PrecheckException

If the gateway node rejected the request upon submission.

ConsensusException

If the network was unable to come to consensus before the duration of the transaction expired.

TransactionException

If the network rejected the transfer request as invalid or had missing data.

| Edit this page View Source

TransferAsync(ConsensusClient, TransferParams, Action<IConsensusContext>?)

Transfer cryptocurrency and tokens in the same transaction atomically among multiple Hedera accounts and contracts.

Declaration
public static Task<TransactionReceipt> TransferAsync(this ConsensusClient client, TransferParams transfers, Action<IConsensusContext>? configure = null)
Parameters
Type Name Description
ConsensusClient client

The Consensus Node Client orchestrating the transfer.

TransferParams transfers

A transfers parameter object holding lists of crypto and token transfers to perform.

Action<IConsensusContext> configure

Optional callback method providing an opportunity to modify the execution configuration for just this method call. It is executed prior to submitting the request to the network.

Returns
Type Description
Task<TransactionReceipt>

A transfer receipt indicating success of the consensus operation.

Examples
// Atomic multi-party transfer: two senders each contribute 0.5 HBAR,
// one receiver takes the full 1 HBAR. Every negative amount must be
// authorized by the sending account's signatory, and the sum across
// the transfer list must be zero.
var receipt = await client.TransferAsync(new TransferParams
{
    CryptoTransfers = new[]
    {
        new CryptoTransfer(sender1, -50_000_000),
        new CryptoTransfer(sender2, -50_000_000),
        new CryptoTransfer(receiver, 100_000_000),
    }
});
Console.WriteLine($"Transfer status: {receipt.Status}");
Exceptions
Type Condition
ArgumentOutOfRangeException

If required arguments are missing.

InvalidOperationException

If required context configuration is missing.

PrecheckException

If the gateway node rejected the request upon submission.

ConsensusException

If the network was unable to come to consensus before the duration of the transaction expired.

TransactionException

If the network rejected the transfer request as invalid or had missing data.

| Edit this page View Source

TransferNftAsync(ConsensusClient, Nft, EntityId, EntityId, Action<IConsensusContext>?)

Transfer assets (NFTs) from one account to another.

Declaration
public static Task<TransactionReceipt> TransferNftAsync(this ConsensusClient client, Nft nft, EntityId fromAddress, EntityId toAddress, Action<IConsensusContext>? configure = null)
Parameters
Type Name Description
ConsensusClient client

The Consensus Node Client orchestrating the transfer.

Nft nft

The identifier of the nft to transfer (shard, realm, num, serial).

EntityId fromAddress

The account to transfer the assets from. Ensure that a signatory either in the context or passed with this call can fulfill the signing requirements to transfer assets out of the account identified by this account.

EntityId toAddress

The account receiving the assets.

Action<IConsensusContext> configure

Optional callback method providing an opportunity to modify the execution configuration for just this method call. It is executed prior to submitting the request to the network.

Returns
Type Description
Task<TransactionReceipt>

A transfer receipt indicating success of the operation.

Remarks

This convenience method does not support allowances, to perform transfers with allowances, use the overload of this method, TransferAsync(ConsensusClient, TransferParams, Action<IConsensusContext>?), instead.

Examples
// Transfer a single NFT by (token, serial). Use the atomic multi-asset
// TransferAsync(TransferParams) overload if you need approvals or want
// to move several NFTs in one transaction.
var receipt = await client.TransferNftAsync(nft, sender, receiver);
Console.WriteLine($"NFT transfer status: {receipt.Status}");
Exceptions
Type Condition
ArgumentOutOfRangeException

If required arguments are missing.

InvalidOperationException

If required context configuration is missing.

PrecheckException

If the gateway node rejected the request upon submission.

ConsensusException

If the network was unable to come to consensus before the duration of the transaction expired.

TransactionException

If the network rejected the transfer request as invalid or had missing data.

| Edit this page View Source

TransferTokensAsync(ConsensusClient, EntityId, EntityId, EntityId, long, Action<IConsensusContext>?)

Transfer Fungible tokens from one account to another.

Declaration
public static Task<TransactionReceipt> TransferTokensAsync(this ConsensusClient client, EntityId token, EntityId fromAddress, EntityId toAddress, long amount, Action<IConsensusContext>? configure = null)
Parameters
Type Name Description
ConsensusClient client

The Consensus Node Client orchestrating the transfer.

EntityId token

The identifier of the token type being transferred.

EntityId fromAddress

The address to transfer the tokens from. Ensure that a signatory either in the context or passed with this call can fulfill the signing requirements to transfer tokens out of the account identified by this address.

EntityId toAddress

The address receiving the tokens.

long amount

The amount of tokens to transfer.

Action<IConsensusContext> configure

Optional callback method providing an opportunity to modify the execution configuration for just this method call. It is executed prior to submitting the request to the network.

Returns
Type Description
Task<TransactionReceipt>

A transfer receipt indicating success of the operation.

Remarks

Does not support allowances, to use the allowance flag in the transfer list use the TransferParams to construct the transfer.

Examples
// Transfer fungible token units between two accounts. The receiver
// must already be associated with the token (AssociateTokenAsync) or
// have automatic-association slots available.
var receipt = await client.TransferTokensAsync(token, sender, receiver, units);
Console.WriteLine($"Token transfer status: {receipt.Status}");
Exceptions
Type Condition
ArgumentOutOfRangeException

If required arguments are missing.

InvalidOperationException

If required context configuration is missing.

PrecheckException

If the gateway node rejected the request upon submission.

ConsensusException

If the network was unable to come to consensus before the duration of the transaction expired.

TransactionException

If the network rejected the transfer request as invalid or had missing data.

  • Edit this page
  • View Source
In this article
Back to top .NET Client Library for Hiero Network and Hedera Hashgraph