Show / Hide Table of Contents

Class QueryContractExtensions

Extension methods for querying smart contract functions locally.

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

Methods

| Edit this page View Source

QueryContractAsync(ConsensusClient, QueryContractParams, Action<IConsensusContext>?)

Calls a smart contract function locally on the gateway node.

Declaration
public static Task<ContractCallResult> QueryContractAsync(this ConsensusClient client, QueryContractParams queryContractParams, Action<IConsensusContext>? configure = null)
Parameters
Type Name Description
ConsensusClient client

The Consensus Node Client to query.

QueryContractParams queryContractParams

The parameters identifying the contract and function method to call.

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<ContractCallResult>

The results from the local contract query call.

Remarks

This is performed locally on the gateway node. It cannot change the state of the contract instance (and so, cannot spend anything from the instance's cryptocurrency account). It will not have a consensus timestamp nor a record or a receipt. The response will contain the output returned by the function call.

Examples

Query a view method with ABI arguments and decode a typed return:

// Local view call with ABI arguments. Decode typed outputs via
// result.Result.As<T>() — the ABI is inferred from the return type.
// For heavy querying use the mirror node's EstimateGas/CallEvm
// helpers instead — they are free.
var result = await client.QueryContractAsync(new QueryContractParams
{
    Contract = contract,
    Gas = 50_000,
    MethodName = "balanceOf",
    MethodArgs = new object[] { new EntityId(0, 0, 98) }
});
long balance = result.Result.As<long>();
Console.WriteLine($"Balance: {balance}");
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.

ContractException

If the request was accepted by the network but the contract failed for some reason. Contains additional information returned from the contract virtual machine. Only thrown if the ThrowOnFail is set to

true

, the default, otherwise the method returns a ContractCallResult with the same information.

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