Show / Hide Table of Contents

Class CallContractExtensions

Extension methods for calling smart contracts.

Inheritance
object
CallContractExtensions
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 CallContractExtensions

Methods

| Edit this page View Source

CallContractAsync(ConsensusClient, CallContractParams, Action<IConsensusContext>?)

Calls a smart contract returning a receipt indicating success.
This call does not return the data emitted from the contract, to obtain that data, use a mirror node to fetch the results by transaction id or retrieve the transaction record from the mirror node and cast the result to a CallContractRecord.

Declaration
public static Task<TransactionReceipt> CallContractAsync(this ConsensusClient client, CallContractParams callParameters, Action<IConsensusContext>? configure = null)
Parameters
Type Name Description
ConsensusClient client

The Consensus Node Client executing the contract call.

CallContractParams callParameters

An object identifying the function to call, any input parameters and the amount of gas that may be used to execute the request.

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 contract transaction receipt indicating success, it does not include any output parameters returned from the contract.

Examples

Call a payable method — PayableAmount in tinybars is debited from the Payer and credited to the contract's crypto account:

// Payable calls include a tinybar amount debited from the Payer and
// credited to the contract's crypto account. The contract method must
// be marked payable or the call reverts.
var receipt = await client.CallContractAsync(new CallContractParams
{
    Contract = contract,
    Gas = 100_000,
    PayableAmount = 50_000_000, // 0.5 HBAR
    MethodName = "deposit",
    MethodArgs = Array.Empty<object>()
});
Console.WriteLine($"Payable call 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 create 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