Class ConsensusClient
Hiero Network Consensus (Gossip) Node Client
Implements
Inherited Members
Namespace: Hiero
Assembly: Hiero.dll
Syntax
public sealed class ConsensusClient : IAsyncDisposable
Remarks
This component facilitates interaction with the Hiero Network.
It manages the communication channels with the network and
serialization of requests and responses. This library generally
shields the client code from directly interacting with the
underlying protobuf communication layer but does provide hooks
allowing advanced low-level manipulation of messages if necessary.
Constructors
| Edit this page View SourceConsensusClient(Action<IConsensusContext>?)
Creates a new instance of a Hiero Network ConsensusClient.
Declaration
public ConsensusClient(Action<IConsensusContext>? configure = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<IConsensusContext> | configure | Optional configuration method that can set the location of the network node accessing the network and how transaction fees shall be paid for. |
Remarks
Creating a new instance of a
ConsensusClient
initializes a new instance of a client. It will have a separate cache of GRPC channels to the network and will maintain a separate configuration from other clients. The constructor takes an optional callback method that configures the details on how the client should connect to the network and what accounts generally pay transaction fees and other details. See the IConsensusContext documentation for configuration details.
ConsensusClient(Func<ConsensusNodeEndpoint, GrpcChannel>, Action<IConsensusContext>?)
Creates a new instance of a Hiero Network ConsensusClient with a custom gRPC channel factory.
Declaration
public ConsensusClient(Func<ConsensusNodeEndpoint, GrpcChannel> channelFactory, Action<IConsensusContext>? configure = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<ConsensusNodeEndpoint, GrpcChannel> | channelFactory | A custom callback method returning a new channel given the target ConsensusNodeEndpoint. Note, this method is only called once for each unique ConsensusNodeEndpoint requested by the ConsensusClient (which is a function of the current context's ConsensusNodeEndpoint parameter) |
| Action<IConsensusContext> | configure | Optional configuration method that can set the location of the network node accessing the network and how transaction fees shall be paid for. |
Remarks
Creating a new instance of a
ConsensusClient
initializes a new instance of a client. It will have a separate cache of GRPC channels to the network and will maintain a separate configuration from other clients. The constructor takes an optional callback method that configures the details on how the client should connect to the network and what accounts generally pay transaction fees and other details. See the IConsensusContext documentation for configuration details.
Methods
| Edit this page View SourceClone(Action<IConsensusContext>?)
Creates a new instance of the client having a shared base configuration with its parent. Changes to the parent’s configuration will reflect in this instance’s configuration while changes in this instance’s configuration will not be reflected in the parent configuration.
Declaration
public ConsensusClient Clone(Action<IConsensusContext>? configure = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<IConsensusContext> | configure | The callback method receiving the IConsensusContext object providing the configuration details of this client instance. Values can be retrieved and set within the context of the method invocation. |
Returns
| Type | Description |
|---|---|
| ConsensusClient | A new instance of a client object. |
Configure(Action<IConsensusContext>)
Updates the configuration of this instance of a client through implementation of the supplied IConsensusContext callback method.
Declaration
public void Configure(Action<IConsensusContext> configure)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<IConsensusContext> | configure | The callback method receiving the IConsensusContext object providing the configuration details of this client instance. Values can be retrieved and set within the context of the method invocation. |
DisposeAsync()
.NET Asynchronous dispose method.
Declaration
public ValueTask DisposeAsync()
Returns
| Type | Description |
|---|---|
| ValueTask | An Async Task. |
Remarks
Closes any GRPC channels solely owned by this
ConsensusClient
instance.
ExecuteAsync<T>(TransactionParams<T>, Action<IConsensusContext>?)
Creates, signs, submits a transaction and waits for a response from the target consensus node, returning a receipt.
Declaration
public Task<T> ExecuteAsync<T>(TransactionParams<T> transactionParams, Action<IConsensusContext>? configure = null) where T : TransactionReceipt
Parameters
| Type | Name | Description |
|---|---|---|
| TransactionParams<T> | transactionParams | The details of the transaction to create, sign and submit. |
| Action<IConsensusContext> | configure | Optional callback to configure the calling context immediately before assembling the transaction for submission. |
Returns
| Type | Description |
|---|---|
| Task<T> | A receipt object. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of receipt to return. |
Exceptions
| Type | Condition |
|---|---|
| PrecheckException | If there was a problem submitting the request, including the consensus node considering the request invalid. |
| TransactionException | If the consensus node returned a failure code and throw on failure is set to
in the client context configuration. |
| ConsensusException | Under heavy load, the network may not process the transaction before it expires. |
SubmitAsync<T>(TransactionParams<T>, Action<IConsensusContext>?)
Creates, signs, submits a transaction and waits for a response from the target consensus node. Returning the precheck response code. A PrecheckException may be thrown under certain invalid input scenarios.
Declaration
public Task<ResponseCode> SubmitAsync<T>(TransactionParams<T> transactionParams, Action<IConsensusContext>? configure = null) where T : TransactionReceipt
Parameters
| Type | Name | Description |
|---|---|---|
| TransactionParams<T> | transactionParams | Transaction input parameters. |
| Action<IConsensusContext> | configure | Optional callback to configure the calling context immediately before assembling the transaction for submission. |
Returns
| Type | Description |
|---|---|
| Task<ResponseCode> | The precheck ResponseCode returned from the request after waiting for submission retries if applicable. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of TransactionReceipt returned by the request. |
Remarks
This method will wait for the target consensus node to respond with a code other than Busy or InvalidTransactionStart if applicable, until such time as the retry count is exhausted, in which case it is possible to receive a Busy response.
ToString()
Returns a human-readable debug string describing this client instance.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |