Class CallContractExtensions
Extension methods for calling smart contracts.
Inherited Members
Namespace: Hiero
Assembly: Hiero.dll
Syntax
public static class CallContractExtensions
Methods
| Edit this page View SourceCallContractAsync(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, fetch the contract result from a mirror node by
transaction id
(GetContractResultByTransactionIdAsync(MirrorRestClient, TransactionId, CancellationToken, params IMirrorProjection[])),
or, within about three minutes of consensus, retrieve the record from
a consensus node with
GetTransactionRecordAsync(ConsensusClient, TransactionId, CancellationToken, Action<IConsensusContext>?)
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 |
|---|---|
| ArgumentException | If required arguments are missing or invalid. |
| InvalidOperationException | If required context configuration is missing. |
| PrecheckException | If the gateway node refused the transaction. Only a code about the transaction itself proves it did not execute; any other code leaves the outcome unknown, so settle it by its transaction id on a mirror node rather than resubmitting it (see PrecheckException). |
| ConsensusException | If the outcome could not be confirmed: the transaction may have executed, so settle it by its transaction id on a mirror node rather than resubmitting it. |
| TransactionException | If the contract call reached consensus and failed, for example with ContractRevertExecuted or InsufficientGas. |