Casper.Network.SDK
Show / Hide Table of Contents

Class NetCasperClient

Client to communicate with a Casper node.

Inheritance
System.Object
NetCasperClient
Implements
ICasperClient
IDisposable
Namespace: Casper.Network.SDK
Assembly: Casper.Network.SDK.dll
Syntax
public class NetCasperClient : object, ICasperClient, IDisposable

Constructors

NetCasperClient(String, RpcLoggingHandler)

Create a new instance of the Casper client for a specific node in the network determined by the node address. Optionally, indicate a logging handler to log the requests and responses exchanged with tne node.

Declaration
public NetCasperClient(string nodeAddress, RpcLoggingHandler loggingHandler = null)
Parameters
Type Name Description
System.String nodeAddress

URL of the node. Example: 'http://127.0.0.1:7777/rpc'.

RpcLoggingHandler loggingHandler

Optional. An instance of a logging handler to log the requests and responses exchanged with the network.

NetCasperClient(String, HttpClient)

Declaration
public NetCasperClient(string nodeAddress, HttpClient httpClient)
Parameters
Type Name Description
System.String nodeAddress
HttpClient httpClient

Methods

Dispose()

Declaration
public void Dispose()

Dispose(Boolean)

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
System.Boolean disposing

GetAccountBalance(AccountHashKey, Int32)

Request the balance information of an account given its account hash key.

Declaration
public async Task<RpcResponse<GetBalanceResult>> GetAccountBalance(AccountHashKey accountHash, int blockHeight)
Parameters
Type Name Description
AccountHashKey accountHash

The account hash of the account to request the balance.

System.Int32 blockHeight

Height of the block.

Returns
Type Description
Task<RpcResponse<GetBalanceResult>>

GetAccountBalance(AccountHashKey, String)

Request the balance information of an account given its account hash key.

Declaration
public async Task<RpcResponse<GetBalanceResult>> GetAccountBalance(AccountHashKey accountHash, string stateRootHash = null)
Parameters
Type Name Description
AccountHashKey accountHash

The account hash of the account to request the balance.

System.String stateRootHash

Hash of the state root. Null to get latest available.

Returns
Type Description
Task<RpcResponse<GetBalanceResult>>

GetAccountBalance(PublicKey, Int32)

Request the balance information of an account given its public key.

Declaration
public async Task<RpcResponse<GetBalanceResult>> GetAccountBalance(PublicKey publicKey, int blockHeight)
Parameters
Type Name Description
PublicKey publicKey

The public key of the account to request the balance.

System.Int32 blockHeight

Height of the block.

Returns
Type Description
Task<RpcResponse<GetBalanceResult>>

GetAccountBalance(PublicKey, String)

Request the balance information of an account given its public key.

Declaration
public async Task<RpcResponse<GetBalanceResult>> GetAccountBalance(PublicKey publicKey, string stateRootHash = null)
Parameters
Type Name Description
PublicKey publicKey

The public key of the account to request the balance.

System.String stateRootHash

Hash of the state root. Null to get latest available.

Returns
Type Description
Task<RpcResponse<GetBalanceResult>>

GetAccountBalance(URef, Int32)

Request a purse's balance from the network.

Declaration
public async Task<RpcResponse<GetBalanceResult>> GetAccountBalance(URef purseURef, int blockHeight)
Parameters
Type Name Description
URef purseURef

Purse URef key.

System.Int32 blockHeight

Height of the block.

Returns
Type Description
Task<RpcResponse<GetBalanceResult>>

GetAccountBalance(URef, String)

Request a purse's balance from the network.

Declaration
public async Task<RpcResponse<GetBalanceResult>> GetAccountBalance(URef purseURef, string stateRootHash = null)
Parameters
Type Name Description
URef purseURef

Purse URef key.

System.String stateRootHash

Hash of the state root. Null to get latest available.

Returns
Type Description
Task<RpcResponse<GetBalanceResult>>

GetAccountBalance(String, String)

Request a purse's balance from the network.

Declaration
public async Task<RpcResponse<GetBalanceResult>> GetAccountBalance(string purseURef, string stateRootHash = null)
Parameters
Type Name Description
System.String purseURef

Purse URef formatted as a string.

System.String stateRootHash

Hash of the state root. Null to get latest available.

Returns
Type Description
Task<RpcResponse<GetBalanceResult>>

GetAccountBalanceWithBlockHash(AccountHashKey, String)

Request the balance information of an account given its account hash key.

Declaration
public async Task<RpcResponse<GetBalanceResult>> GetAccountBalanceWithBlockHash(AccountHashKey accountHash, string blockHash = null)
Parameters
Type Name Description
AccountHashKey accountHash

The account hash of the account to request the balance.

System.String blockHash

Hash of the block. Null to get latest available.

Returns
Type Description
Task<RpcResponse<GetBalanceResult>>

GetAccountBalanceWithBlockHash(PublicKey, String)

Request the balance information of an account given its public key.

Declaration
public async Task<RpcResponse<GetBalanceResult>> GetAccountBalanceWithBlockHash(PublicKey publicKey, string blockHash = null)
Parameters
Type Name Description
PublicKey publicKey

The public key of the account to request the balance.

System.String blockHash

Hash of the block. Null to get latest available.

Returns
Type Description
Task<RpcResponse<GetBalanceResult>>

GetAccountBalanceWithBlockHash(URef, String)

Request a purse's balance from the network.

Declaration
public async Task<RpcResponse<GetBalanceResult>> GetAccountBalanceWithBlockHash(URef purseURef, string blockHash = null)
Parameters
Type Name Description
URef purseURef

Purse URef key.

System.String blockHash

Hash of the block. Null to get latest available.

Returns
Type Description
Task<RpcResponse<GetBalanceResult>>

GetAccountInfo(AccountHashKey, Int32)

Request the information of an Account in the network.

Declaration
public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(AccountHashKey accountHash, int blockHeight)
Parameters
Type Name Description
AccountHashKey accountHash

The account hash of the account.

System.Int32 blockHeight

A block height for which the information of the account is queried.

Returns
Type Description
Task<RpcResponse<GetAccountInfoResult>>

GetAccountInfo(AccountHashKey, String)

Request the information of an Account in the network.

Declaration
public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(AccountHashKey accountHash, string blockHash = null)
Parameters
Type Name Description
AccountHashKey accountHash

The account hash of the account.

System.String blockHash

A block hash for which the information of the account is queried. Null for most recent information.

Returns
Type Description
Task<RpcResponse<GetAccountInfoResult>>

GetAccountInfo(PublicKey, Int32)

Request the information of an Account in the network.

Declaration
public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(PublicKey publicKey, int blockHeight)
Parameters
Type Name Description
PublicKey publicKey

The public key of the account.

System.Int32 blockHeight

A block height for which the information of the account is queried.

Returns
Type Description
Task<RpcResponse<GetAccountInfoResult>>

GetAccountInfo(PublicKey, String)

Request the information of an Account in the network.

Declaration
public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(PublicKey publicKey, string blockHash = null)
Parameters
Type Name Description
PublicKey publicKey

The public key of the account.

System.String blockHash

A block hash for which the information of the account is queried. Null for most recent information.

Returns
Type Description
Task<RpcResponse<GetAccountInfoResult>>

GetAccountInfo(String, Int32)

Request the information of an Account in the network.

Declaration
public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(string publicKey, int blockHeight)
Parameters
Type Name Description
System.String publicKey

The public key of the account formatted as an hex-string.

System.Int32 blockHeight

A block height for which the information of the account is queried.

Returns
Type Description
Task<RpcResponse<GetAccountInfoResult>>

GetAccountInfo(String, String)

Request the information of an Account in the network.

Declaration
public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(string publicKey, string blockHash = null)
Parameters
Type Name Description
System.String publicKey

The public key of the account formatted as a string.

System.String blockHash

A block hash for which the information of the account is queried. Null for most recent information.

Returns
Type Description
Task<RpcResponse<GetAccountInfoResult>>

GetAuctionInfo(Int32)

Request the bids and validators at a given block.

Declaration
public async Task<RpcResponse<GetAuctionInfoResult>> GetAuctionInfo(int blockHeight)
Parameters
Type Name Description
System.Int32 blockHeight

Block height for which the auction info is queried.

Returns
Type Description
Task<RpcResponse<GetAuctionInfoResult>>

GetAuctionInfo(String)

Request the bids and validators at a given block.

Declaration
public async Task<RpcResponse<GetAuctionInfoResult>> GetAuctionInfo(string blockHash = null)
Parameters
Type Name Description
System.String blockHash

Block hash for which the auction info is queried. Null for the most recent auction info.

Returns
Type Description
Task<RpcResponse<GetAuctionInfoResult>>

GetBlock(Int32)

Request a Block from the network by its height number.

Declaration
public async Task<RpcResponse<GetBlockResult>> GetBlock(int blockHeight)
Parameters
Type Name Description
System.Int32 blockHeight

Height of the block to retrieve.

Returns
Type Description
Task<RpcResponse<GetBlockResult>>

GetBlock(String)

Retrieves a Block from the network by its hash.

Declaration
public async Task<RpcResponse<GetBlockResult>> GetBlock(string blockHash = null)
Parameters
Type Name Description
System.String blockHash

Hash of the block to retrieve. Null for the most recent block.

Returns
Type Description
Task<RpcResponse<GetBlockResult>>

GetBlockTransfers(Int32)

Request all transfers for a Block by its height number.

Declaration
public async Task<RpcResponse<GetBlockTransfersResult>> GetBlockTransfers(int blockHeight)
Parameters
Type Name Description
System.Int32 blockHeight

Height of the block to retrieve the transfers from.

Returns
Type Description
Task<RpcResponse<GetBlockTransfersResult>>

GetBlockTransfers(String)

Request all transfers for a Block by its block hash.

Declaration
public async Task<RpcResponse<GetBlockTransfersResult>> GetBlockTransfers(string blockHash = null)
Parameters
Type Name Description
System.String blockHash

Hash of the block to retrieve the transfers from. Null for the most recent block

Returns
Type Description
Task<RpcResponse<GetBlockTransfersResult>>

GetChainspec()

Request the the chainspec.toml, genesis accounts.toml, and global_state.toml files of the node.

Declaration
public async Task<RpcResponse<GetChainspecResult>> GetChainspec()
Returns
Type Description
Task<RpcResponse<GetChainspecResult>>

GetDeploy(String, CancellationToken)

Request a Deploy object from the network by the deploy hash. When a cancellation token is included this method waits until the deploy is executed, i.e. until the deploy contains the execution results information.

Declaration
public async Task<RpcResponse<GetDeployResult>> GetDeploy(string deployHash, CancellationToken cancellationToken = null)
Parameters
Type Name Description
System.String deployHash

Hash of the deploy to retrieve.

CancellationToken cancellationToken

A CancellationToken. Do not include this parameter to return with the first deploy object returned by the network, even it's not executed.

Returns
Type Description
Task<RpcResponse<GetDeployResult>>

GetDeploy(String, Boolean, CancellationToken)

Request a Deploy object from the network by the deploy hash. When a cancellation token is included this method waits until the deploy is executed, i.e. until the deploy contains the execution results information.

Declaration
public async Task<RpcResponse<GetDeployResult>> GetDeploy(string deployHash, bool finalizedApprovals, CancellationToken cancellationToken = null)
Parameters
Type Name Description
System.String deployHash

Hash of the deploy to retrieve.

System.Boolean finalizedApprovals

Whether to return the deploy with the finalized approvals substituted. If false or omitted, returns the deploy with the approvals that were originally received by the node.

CancellationToken cancellationToken

A CancellationToken. Do not include this parameter to return with the first deploy object returned by the network, even it's not executed.

Returns
Type Description
Task<RpcResponse<GetDeployResult>>

GetDictionaryItem(String, String)

Lookup a dictionary item from its dictionary key.

Declaration
public async Task<RpcResponse<GetDictionaryItemResult>> GetDictionaryItem(string dictionaryKey, string stateRootHash = null)
Parameters
Type Name Description
System.String dictionaryKey

The dictionary key to retrieve.

System.String stateRootHash

Hash of the state root.

Returns
Type Description
Task<RpcResponse<GetDictionaryItemResult>>

GetDictionaryItemByAccount(String, String, String, String)

Lookup a dictionary item via an Account's named keys.

Declaration
public async Task<RpcResponse<GetDictionaryItemResult>> GetDictionaryItemByAccount(string accountKey, string dictionaryName, string dictionaryItem, string stateRootHash = null)
Parameters
Type Name Description
System.String accountKey

The account key as a formatted string whose named keys contains dictionaryName.

System.String dictionaryName

The named key under which the dictionary seed URef is stored.

System.String dictionaryItem

The dictionary item key.

System.String stateRootHash

Hash of the state root.

Returns
Type Description
Task<RpcResponse<GetDictionaryItemResult>>

GetDictionaryItemByContract(String, String, String, String)

Lookup a dictionary item via a Contract named keys.

Declaration
public async Task<RpcResponse<GetDictionaryItemResult>> GetDictionaryItemByContract(string contractKey, string dictionaryName, string dictionaryItem, string stateRootHash = null)
Parameters
Type Name Description
System.String contractKey

The contract key as a formatted string whose named keys contains dictionaryName.

System.String dictionaryName

The named key under which the dictionary seed URef is stored.

System.String dictionaryItem

The dictionary item key.

System.String stateRootHash

Hash of the state root.

Returns
Type Description
Task<RpcResponse<GetDictionaryItemResult>>

GetDictionaryItemByURef(String, String, String)

Lookup a dictionary item via its seed URef.

Declaration
public async Task<RpcResponse<GetDictionaryItemResult>> GetDictionaryItemByURef(string seedURef, string dictionaryItem, string stateRootHash = null)
Parameters
Type Name Description
System.String seedURef

The dictionary's seed URef.

System.String dictionaryItem

The dictionary item key.

System.String stateRootHash

Hash of the state root.

Returns
Type Description
Task<RpcResponse<GetDictionaryItemResult>>

GetEraInfoBySwitchBlock(Int32)

Request an EraInfo from the network given a switch block. For a non-switch block this method returns an empty response.

Declaration
public async Task<RpcResponse<GetEraInfoBySwitchBlockResult>> GetEraInfoBySwitchBlock(int blockHeight)
Parameters
Type Name Description
System.Int32 blockHeight

Block height of a switch block.

Returns
Type Description
Task<RpcResponse<GetEraInfoBySwitchBlockResult>>

GetEraInfoBySwitchBlock(String)

Request an EraInfo from the network given a switch block. For a non-switch block this method returns an empty response.

Declaration
public async Task<RpcResponse<GetEraInfoBySwitchBlockResult>> GetEraInfoBySwitchBlock(string blockHash = null)
Parameters
Type Name Description
System.String blockHash

Block hash of a switch block. Null for the latest block.

Returns
Type Description
Task<RpcResponse<GetEraInfoBySwitchBlockResult>>

GetEraSummary(Int32)

Request current Era Info from the network given a block hash

Declaration
public async Task<RpcResponse<GetEraSummaryResult>> GetEraSummary(int blockHeight)
Parameters
Type Name Description
System.Int32 blockHeight

Block height.

Returns
Type Description
Task<RpcResponse<GetEraSummaryResult>>

GetEraSummary(String)

Request current Era Info from the network given a block hash

Declaration
public async Task<RpcResponse<GetEraSummaryResult>> GetEraSummary(string blockHash = null)
Parameters
Type Name Description
System.String blockHash

Block hash. Null for the latest block.

Returns
Type Description
Task<RpcResponse<GetEraSummaryResult>>

GetNodeMetrics(String)

Request the performance metrics of a node in the network.

Declaration
public static async Task<string> GetNodeMetrics(string nodeAddress)
Parameters
Type Name Description
System.String nodeAddress

URL of the performance metrics endpoint. Example: 'http://127.0.0.1:8888/metrics'.

Returns
Type Description
Task<System.String>

GetNodeMetrics(String, Int32)

Request the performance metrics of a node in the network.

Declaration
public static async Task<string> GetNodeMetrics(string host, int port)
Parameters
Type Name Description
System.String host

IP of the network node.

System.Int32 port

Port of the performance metrics endpoint (usually 8888).

Returns
Type Description
Task<System.String>

GetNodePeers()

Request a list of peers connected to the node.

Declaration
public async Task<RpcResponse<GetNodePeersResult>> GetNodePeers()
Returns
Type Description
Task<RpcResponse<GetNodePeersResult>>

GetNodeStatus()

Request the current status of the node.

Declaration
public async Task<RpcResponse<GetNodeStatusResult>> GetNodeStatus()
Returns
Type Description
Task<RpcResponse<GetNodeStatusResult>>

GetRpcSchema()

Request the RPC Json schema to the network node.

Declaration
public async Task<string> GetRpcSchema()
Returns
Type Description
Task<System.String>

GetStateRootHash(Int32)

Request the state root hash at a given Block.

Declaration
public async Task<string> GetStateRootHash(int blockHeight)
Parameters
Type Name Description
System.Int32 blockHeight

Block height for which the state root is queried.

Returns
Type Description
Task<System.String>

GetStateRootHash(String)

Request the state root hash at a given Block.

Declaration
public async Task<string> GetStateRootHash(string blockHash = null)
Parameters
Type Name Description
System.String blockHash

Block hash for which the state root is queried. Null for the most recent.

Returns
Type Description
Task<System.String>

GetValidatorChanges()

Request the status changes of active validators.

Declaration
public async Task<RpcResponse<GetValidatorChangesResult>> GetValidatorChanges()
Returns
Type Description
Task<RpcResponse<GetValidatorChangesResult>>

PutDeploy(Deploy)

Send a Deploy to the network for its execution.

Declaration
public async Task<RpcResponse<PutDeployResult>> PutDeploy(Deploy deploy)
Parameters
Type Name Description
Deploy deploy

The deploy object.

Returns
Type Description
Task<RpcResponse<PutDeployResult>>

QueryGlobalState(GlobalStateKey, String, String)

Request the stored value in a global state key.

Declaration
public async Task<RpcResponse<QueryGlobalStateResult>> QueryGlobalState(GlobalStateKey key, string stateRootHash = null, string path = null)
Parameters
Type Name Description
GlobalStateKey key

The global state key to query the value from the network.

System.String stateRootHash

Hash of the state root. Null for the most recent stored value..

System.String path

The path components starting from the key as base (use '/' as separator).

Returns
Type Description
Task<RpcResponse<QueryGlobalStateResult>>

QueryGlobalState(String, Int32, String)

Request the stored value in a global state key.

Declaration
public async Task<RpcResponse<QueryGlobalStateResult>> QueryGlobalState(string key, int height, string path = null)
Parameters
Type Name Description
System.String key

The global state key formatted as a string to query the value from the network.

System.Int32 height

Height of the block to check the stored value in.

System.String path

The path components starting from the key as base (use '/' as separator).

Returns
Type Description
Task<RpcResponse<QueryGlobalStateResult>>

QueryGlobalState(String, String, String)

Request the stored value in a global state key.

Declaration
public async Task<RpcResponse<QueryGlobalStateResult>> QueryGlobalState(string key, string stateRootHash = null, string path = null)
Parameters
Type Name Description
System.String key

The global state key formatted as a string to query the value from the network.

System.String stateRootHash

Hash of the state root. Null for the most recent stored value..

System.String path

The path components starting from the key as base (use '/' as separator).

Returns
Type Description
Task<RpcResponse<QueryGlobalStateResult>>

QueryGlobalStateWithBlockHash(GlobalStateKey, String, String)

Request the stored value in a global state key.

Declaration
public async Task<RpcResponse<QueryGlobalStateResult>> QueryGlobalStateWithBlockHash(GlobalStateKey key, string blockHash, string path = null)
Parameters
Type Name Description
GlobalStateKey key

The global state key to query the value from the network.

System.String blockHash

The block hash.

System.String path

The path components starting from the key as base (use '/' as separator).

Returns
Type Description
Task<RpcResponse<QueryGlobalStateResult>>

QueryGlobalStateWithBlockHash(String, String, String)

Request the stored value in a global state key.

Declaration
public async Task<RpcResponse<QueryGlobalStateResult>> QueryGlobalStateWithBlockHash(string key, string blockHash, string path = null)
Parameters
Type Name Description
System.String key

The global state key formatted as a string to query the value from the network.

System.String blockHash

The block hash.

System.String path

The path components starting from the key as base (use '/' as separator).

Returns
Type Description
Task<RpcResponse<QueryGlobalStateResult>>

QueryState(String, List<String>, String)

Request a stored value from the network. This RPC is deprecated, use QueryGlobalState instead.

Declaration
public async Task<RpcResponse<GetItemResult>> QueryState(string keyHash, List<string> path = null, string stateRootHash = null)
Parameters
Type Name Description
System.String keyHash

A global state key formatted as a string

List<System.String> path

The path components starting from the key as base (use '/' as separator).

System.String stateRootHash
Returns
Type Description
Task<RpcResponse<GetItemResult>>

SpeceulativeExecution(Deploy, String)

Sends a "deploy dry run" to the network. It will execute the deploy on top of the specified block and return the results of the execution to the caller. The effects of the execution won't be committed to the trie (blockchain database/GlobalState). This method runs in a different port of the network (e.g.: 7778) and can be used for debugging, discovery. For example price estimation.

Declaration
public async Task<RpcResponse<SpeculativeExecutionResult>> SpeceulativeExecution(Deploy deploy, string stateRootHash = null)
Parameters
Type Name Description
Deploy deploy

The deploy to execute.

System.String stateRootHash

Hash of the state root. null if deploy is to be executed on top of the latest block.

Returns
Type Description
Task<RpcResponse<SpeculativeExecutionResult>>

SpeceulativeExecutionWithBlockHash(Deploy, String)

Sends a "deploy dry run" to the network. It will execute the deploy on top of the specified block and return the results of the execution to the caller. The effects of the execution won't be committed to the trie (blockchain database/GlobalState). This method runs in a different port of the network (e.g.: 7778) and can be used for debugging, discovery. For example price estimation.

Declaration
public async Task<RpcResponse<PutDeployResult>> SpeceulativeExecutionWithBlockHash(Deploy deploy, string blockHash = null)
Parameters
Type Name Description
Deploy deploy

The deploy to execute.

System.String blockHash

Hash of the block on top of which the deploy is executed.

Returns
Type Description
Task<RpcResponse<PutDeployResult>>

Implements

ICasperClient
IDisposable
In This Article
Back to top Maintained by MAKE Technology LLC