This API enables connection and interaction between a .NET application and a Cosmos blockchain node built with Cosmos SDK.
Built by UseTech.com
- Getting Started
- Gas Estimates
- Connecting to a Node
- Gaia API
- Tendermint API
- Transactions API
- Custom Transactions
- Bank API
- Authentication API
- Staking API
- Government API
- Slashing API
- Distribution API
- Minting API
The purpose of this section is to get you started working on .NET API for Cosmos SDK and we assume that you already have a Cosmos node up and running locally or at some URL. If you have not done this yet, please refer to Cosmos SDK Tutorials.
First, install .NET Code 3.1. Microsoft provides support for several operating systems, here is the link to .NET Core page.
Now let's check out the API code if you have not done so yet:
git checkout https://github.com/usetech-llc/cosmos_api_dotnet cosmos_api_dotnet
The next step is to build the API and unit tests:
$ cd cosmos_api_dotnet/src
$ dotnet build
If the code builds with no errors, you have the development environment setup! Create a new .NET application, add a project reference to API project like this (or using UI in your IDE):
<ItemGroup>
<ProjectReference Include="..\CosmosApi\CosmosApi.csproj" />
</ItemGroup>
...and proceed to the Connecting to a Node section.
In order to format a transaction, Post... methods are used, which return formatted transaction in JSON format ready to be signed and sent to the node.
Each Post... method has "...Simulation" version, which accepts the same parameters and returns gas estimate for the transaction.
We will start simple then provide details for all possible configuration.
This is a simple example how one can connect to a local node and read an address balance:
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.CreateClient();
var balance =
await client.Bank.GetBankBalancesByAddressAsync("cosmos1h9ymfm2fxrqgd257dlw5nku3jgqjgpl59sm5ns");
To perform a bit more complex operations, such as transferring balance in Bank module, we need to register JSON converters that will help API endoce standard transactions and decode messages received from node. Standard converters can be registered with RegisterCosmosSdkTypeConverters method:
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
The interface ICosmosApiBuilder
is created to help create the api client. Above is the example how it can be used to build an api object. Below you will find details for each method.
ICosmosApiClient CreateClient();
Creates a new instance of Cosmos Api Client
None
An API object that is ready to be used with a node. See ICosmosApiClient for details.
ICosmosApiBuilder Configure(Action<CosmosApiClientSettings> configurator);
Sets settings of created clients using Action.
configurator Action . See CosmosApiClientSettings for details.
ICosmosApiBuilder for method chaining.
ICosmosApiBuilder UseAuthorization(string username, string password);
Sets username and password authorization for created clients
username string - User name
password string - Password
ICosmosApiBuilder for method chaining.
ICosmosApiBuilder UseBaseUrl(string url);
Sets the base url used by created clients.
url string - Node URL
ICosmosApiBuilder for method chaining.
ICosmosApiBuilder RegisterCosmosSdkTypeConverters();
Registers json converters for types declared in standard cosmos sdk with no cutom modules.
None
ICosmosApiBuilder for method chaining.
ICosmosApiBuilder RegisterTxType<T>(string jsonName) where T : ITx;
Adds a possible subtype of the ITx Interface so it can be serialized and deserialized properly.
This method should be used to add custom module transactions if the module has its own implementations of Account, Tx or Msg interfaces that serialize to JSON in the same way as they do in Cosmos SDK modules, i.e.
{ "type": "<type discriminator>", "value": { <json value of implementation> }
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterTxType<StdTx>("cosmos-sdk/StdTx")
.CreateClient();
T Type Parameter - Type which might be used where ITx Interface is used. In the example StdTx represents the standard transaction structure that is already implemented in the API in CosmosApi.Models
namespace. Custom module transactions need to be implemented as similar structures that inherit from ITx Interface.
jsonName string - Value of the type discriminator. I.e. JSON value field name, as it comes in the response from the node.
ICosmosApiBuilder for method chaining.
ICosmosApiBuilder RegisterMsgType<T>(string jsonName) where T : IMsg;
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterMsgType<MsgSend>("cosmos-sdk/MsgSend")
.CreateClient();
Adds a possible subtype of the IMsg Interface so it can be serialized and deserialized properly.
This method should be used to add custom module transactions if the module has its own implementations of Account, Tx or Msg interfaces that serialize to JSON in the same way as they do in Cosmos SDK modules, i.e.
{ "type": "<type discriminator>", "value": { <json value of implementation> }
T Type Parameter - Type which might be used where IMsg Interface is used. In the example MsgSend represents the standard message structure that is already implemented in the API in CosmosApi.Models
namespace. Custom module messages need to be implemented as similar structures that inherit from IMsg Interface.
jsonName string - Value of the type discriminator. I.e. JSON value field name, as it comes in the response from the node.
ICosmosApiBuilder for method chaining.
ICosmosApiBuilder RegisterAccountType<T>(string jsonName) where T : IAccount
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterAccountType<BaseAccount>("cosmos-sdk/Account")
.CreateClient();
Adds a possible subtype of the IAccount Interface, so it can be serialized and deserialized properly
This method should be used to add custom module transactions if the module has its own implementations of Account, Tx or Msg interfaces that serialize to JSON in the same way as they do in Cosmos SDK modules, i.e.
{ "type": "<type discriminator>", "value": { <json value of implementation> }
T Type Parameter - Type which might be used where BaseAccount class is used. In the example BaseAccount represents the standard message structure that is already implemented in the API in CosmosApi.Models
namespace. Custom module messages need to be implemented as similar structures that inherit from BaseAccount class.
jsonName string - Value of the type discriminator. I.e. JSON value field name, as it comes in the response from the node.
ICosmosApiBuilder for method chaining.
ICosmosApiBuilder AddJsonConverter(IConverterFactory factory);
Adds a converter factory to use for serialization and deserialization.
This method should be used when custom module transactions do not serialize to JSON in a standard Cosmos SDK way (i.e. key-value type of JSON object)
factory IConverterFactory - Converter Factory
ICosmosApiBuilder for method chaining.
The ICosmosApiClient contains nested interfaces that implement interaction with built-in modules of Cosmos SDK such as TendermintRPC, Transactions, Bank, etc. These interfaces are each documented in high level sections of this document.
IGaiaREST GaiaRest { get; }
ITendermintRPC TendermintRpc { get; }
ITransactions Transactions { get; }
IAuth Auth { get; }
IBank Bank { get; }
...
Task<BroadcastTxResult> SendAsync(string chainId, string fromAddress, string toAddress, IList<Coin> coins, BroadcastTxMode mode, StdFee fee, string privateKey, string passphrase, string memo = "", CancellationToken cancellationToken = default);
Creates signed transaction and broadcasts it.
chainId string - Chain ID
fromAddress string - Address that signs transaction
toAddress string - Address that receives transaction
coins IList - List of token entries (Denomination and Amount) to send in this transaction
mode BroadcastTxMode - Defines when this call will complete (Block: Return after tx commit, Sync: Return afer CheckTx, Async: Return right away).
fee StdFee - includes the amount of coins paid in fees and the maximum gas to be used by the transaction. The ratio yields an effective "gasprice", which must be above some miminum to be accepted into the mempool.
privateKey string - Sender address private key
passphrase string - Sender passphrase to decode private key
memo string - Memo to include in transaction data
cancellationToken - CancellationToken
BroadcastTxResult structure
All fields in this structure are nullable.
BaseUrl - string - Base url of cosmos api rest server.
Username - string - Specifies the username to use for the authorization.
Password - string - Specifies the password to use for the authorization.
ConnectionLeaseTimeout - TimeSpan - Specifies the time to keep the underlying HTTP/TCP conneciton open. When expired, a Connection: close header is sent with the next request, which should force a new connection and DSN lookup to occur on the next call. Default is null, effectively disabling the behavior.
HttpClientFactory - Func<HttpMessageHandler, HttpClient> - Defines how HttpClient should be instantiated and configured by default. Default is null, creating default HttpClient.
CreateMessageHandlerFactory - Func - Defines how HttpMessageHandler should be instantiated and configured by default. Default is null, creating default HttpMessageHandler.
Timeout - TimeSpan - The HTTP request timeout.
OnBeforeCall - Action - Callback that is called immediately before every HTTP request is sent.
OnBeforeCallAsync - Func<BeforeCall, Task> - Callback that is asynchronously called immediately before every HTTP request is sent.
OnAfterCall - Action - Callback that is called immediately after every HTTP response is received.
OnAfterCallAsync - Func<AfterCall, Task> - Callback that is asynchronously called immediately after every HTTP response is received.
OnError - Action - Callback that is called when an error occurs during any HTTP call, including when any non-success HTTP status code is returned in the response.
OnErrorAsync - Func<Error, Task> - Callback that is asynchronously called when an error occurs during any HTTP call, including when any non-success HTTP status code is returned in the response.
Gaia API is implemented in IGaiaREST
sub-interface of ICosmosApiClient
.
NodeStatus GetNodeInfo();
Task<NodeStatus> GetNodeInfoAsync(CancellationToken cancellationToken = default(CancellationToken));
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var nodeInfo = client.GaiaRest.GetNodeInfo();
Returns properties of the connected node
None
NodeStatus structure:
ApplicationVersion - Application version
NodeInfo - Node Information (Id, Moniker, ProtocolVersion, Network, Channels, ListenAddr, Version, Other)
Tendermint API is implemented in ITendermintRPC
sub-interface of ICosmosApiClient
.
Task<NodeSyncingStatus> GetSyncingAsync(CancellationToken cancellationToken = default(CancellationToken));
NodeSyncingStatus GetSyncing();
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var syncData = await client.TendermintRpc.GetSyncingAsync();
Get if the node is currently syning with other nodes
None
NodeSyncingStatus structure (one boolean field Syncing).
Task<BlockQuery> GetLatestBlockAsync(CancellationToken cancellationToken = default(CancellationToken));
BlockQuery GetLatestBlock();
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var block = await client.TendermintRpc.GetLatestBlockAsync();
Get the latest block
None
BlockMeta
|- BlockHeader
|- string ChainId
|- long? Height
|- DateTimeOffset Time
|- long? NumTxs
|- BlockID LastBlockId
|- byte[] Hash
|- BlockIDParts Parts
|- int Total
|- byte[] Hash
|- long TotalTxs
|- byte[] LastCommitHash
|- byte[] DataHash
|- byte[] ValidatorsHash
|- byte[] NextValidatorsHash
|- byte[] ConsensusHash
|- byte[] AppHash
|- byte[] LastResultsHash
|- byte[] EvidenceHash
|- byte[] ProposerAddress
|- BlockHeaderVersion Version
|- ulong Block
|- ulong App
|-BlockId
|- byte[] Hash
|- BlockIDParts Parts
|- int Total
|- byte[] Hash
Block
|- BlockHeader Header
|- BlockData Data
|- IList<string> Transactions
|- EvidenceData Evidence
|- object Evidence
|- BlockLastCommit LastCommit
|- BlockID BlockId
|- IList<CommitSig> Precommits
|- byte[] ValidatorAddress
|- int ValidatorIndex
|- long Height
|- int Round
|- DateTimeOffset Timestamp
|- SignedMsgType? Type
|- enum: PrevoteType, PrecommitType, or ProposalType
|- BlockID BlockId
|- byte[] Signature
Task<BlockQuery> GetBlockByHeightAsync(long height, CancellationToken cancellationToken = default(CancellationToken));
BlockQuery GetBlockByHeight(long height);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var block = await client.TendermintRpc.GetBlockByHeightAsync(3);
Get a block at a certain height
height - long - Block height
Task<ResponseWithHeight<ValidatorSet>> GetLatestValidatorSetAsync(CancellationToken cancellationToken = default(CancellationToken));
ResponseWithHeight<ValidatorSet> GetLatestValidatorSet();
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var validatorSet = await client.TendermintRpc.GetLatestValidatorSetAsync();
Get the latest validator set
None
ResponseWithHeight<ValidatorSet> structure
ResponseWithHeight
|- long Height
|- TResult Result
ValidatorSet
|- long BlockHeight
|- IList<TendermintValidator>
|- byte[] Address
|- string PubKey
|- long VotingPower
|- long ProposerPriority
Task<ResponseWithHeight<ValidatorSet>> GetValidatorSetByHeightAsync(long height, CancellationToken cancellationToken = default(CancellationToken));
ResponseWithHeight<ValidatorSet> GetValidatorSetByHeight(long height);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var validatorSet = await client.TendermintRpc.GetValidatorSetByHeightAsync(1);
Get a validator set a certain height
height - long - Block height
ResponseWithHeight<ValidatorSet> structure
Retrieve a transaction using its hash.
hash - byte[] - Array of bytes containing transaction hash
Task<TxResponse> GetByHashAsync(byte[] hash, CancellationToken cancellationToken = default);
TxResponse GetByHash(byte[] hash);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var tx = await client.Transactions.GetByHashAsync(
ByteArrayExtensions.ParseHexString("7DCB49D5B4FAE87A5532741816E68EE4222C1DBD66326FBADA55268FA7E760E6"));
Retrieve a transaction using its hash.
hash - byte[] - Array of bytes containing transaction hash
TxResponse
|- long Height
|- string TxHash
|- uint Code
|- string Data
|- string RawLog
|- IList<ABCIMessageLog> Logs
|- ushort MsgIndex
|- bool Success
|- string Log
|- string Info
|- long GasWanted
|- long GasUsed
|- string Codespace
|- IList<ITx> Tx
|- DateTimeOffset Timestamp
Task<PaginatedTxs> GetSearchAsync(string? messageAction, string? messageSender, int? page = default, int? limit = default, int? minHeight = default, int? maxHeight = default, CancellationToken cancellationToken = default);
PaginatedTxs GetSearch(string? messageAction, string? messageSender, int? page = default, int? limit = default, int? minHeight = default, int? maxHeight = default);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var searchResult = await client.Transactions.GetSearchAsync("send", null, limit: 2);
Paginated method for searching transactions.
messageAction - string - Transaction events such as ‘send’. Note that each module documents its own events. look for xx_events.md in the corresponding cosmos-sdk/docs/spec directory.
messageSender - string - Transaction tags with sender.
page - int - Page number.
limit - int - Maximum number of items per page
minHeight - int - Transactions on blocks with height greater or equal this value
maxHeight - int - transactions on blocks with height less than or equal this value
PaginatedTxs structure
PaginatedTxs
|- int TotalCount
|- int Count
|- int PageNumber
|- int PageTotal
|- int Limit
|- IList<[TxResponse](#txresponse)> Txs
This structure is the base structure for every transaction request.
public class BaseReq
{
// Sender address
public string From;
// Memo
public string? Memo;
// Chain ID string
public string ChainId;
// Account number
public ulong AccountNumber { get; set; }
// Sequence number
public ulong Sequence { get; set; }
// fees
public IList<Coin>? Fees { get; set; }
// gas price in each coin gas charged in
public IList<DecCoin>? GasPrices { get; set; }
// gas
public string? Gas { get; set; }
// gas adjustment
public string? GasAdjustment { get; set; }
}
The API support sending custom transactions, but there are certain requirements to the module: It must support POST method that creates transaction object.
There is a NameService demo that comes with this API. It is located in NameserviceApi directory. The method PostBuyNameAsync
in file Nameservice.cs
utilizes POST method in NameService SDK example to compose the transaction:
public async Task<StdTx> PostBuyNameAsync(BuyNameReq request, CancellationToken cancellationToken = default)
{
var baseReq = new BaseReqWithSimulate(request.BaseReq, false);
request = new BuyNameReq(baseReq, request.Name, request.Amount, request.Buyer);
var content = _cosmosApiClient.Serializer.SerializeJsonHttpContent(request);
var response = (await _cosmosApiClient.HttpClient.PostAsync("nameservice/names", content, cancellationToken))
.EnsureSuccessStatusCode();
return await _cosmosApiClient.Serializer.DeserializeJson<StdTx>(response.Content);
}
In ordert to get access to this method in the application that uses API, we need to implement an API extension. This is done in file CosmosApiClientExtensions.cs
:
public static class CosmosApiClientExtensions
{
public static INameservice CreateNameservice(this ICosmosApiClient cosmosApiClient)
{
return new Nameservice(cosmosApiClient);
}
}
...so the calling code will look like this:
using var client = ConfigureBuilder(Configuration.LocalNameserviceBaseUrl)
.RegisterAccountType<Account>("cosmos-sdk/Account")
.RegisterMsgType<MsgBuyName>("nameservice/BuyName")
.CreateClient();
var namespaceApi = client.CreateNameservice();
Now in order to format a transaction that registers a name we need this:
var baseReq = await client.CreateBaseReq(Configuration.LocalNameserviceOwner1, "memo", null, null, null, null);
var name = Guid.NewGuid().ToString("N");
var req = new BuyNameReq(baseReq, name, "1nametoken", Configuration.LocalNameserviceOwner1);
var stdTx = await namespaceApi.PostBuyNameAsync(req);
Signing and posting the transaction can be done using method SignAndBroadcastStdTxAsync
:
var signers = new []{ new SignerWithAddress(Configuration.LocalNameserviceOwner1, Configuration.LocalNameserviceOwner1PrivateKey, Configuration.LocalNameserviceOwner1Passphrase) };
var broadcastResponse = await client.SignAndBroadcastStdTxAsync(stdTx, signers, BroadcastTxMode.Block);
Alternatively, an already signed transaction can be sent with method client.Transactions.PostBroadcastAsync
.
The complete example of signing and sending transaction is located in file src/CosmosApi.Test/Nameservice/NameserviceTests.cs
.
Task<ResponseWithHeight<IList<Coin>>> GetBankBalancesByAddressAsync(string address, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<Coin>> GetBankBalancesByAddress(string address);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var balance =
await client.Bank.GetBankBalancesByAddressAsync("cosmos1h9ymfm2fxrqgd257dlw5nku3jgqjgpl59sm5ns");
Get the account balances.
address - string - Account address
ResponseWithHeight<IList>> structure, where Coin is a list of token entries (Denomination and Amount).
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var account1 = ((await client.Auth.GetAuthAccountByAddressAsync(Address1)).Result as BaseAccount)!;
var denom = account1.Coins[0].Denom;
var amount = 10;
var coinsToSend = new List<Coin>()
{
new Coin(denom, amount)
};
var memo = Guid.NewGuid().ToString("D");
var fee = new StdFee()
{
Amount = new List<Coin>(),
Gas = 300000,
};
var result = await client.SendAsync(LocalChainId, Address1, Address2, coinsToSend, BroadcastTxMode.Block, fee, Address1PrivateKey, Address1Passphrase, memo);
Task<ResponseWithHeight<IAccount>> GetAuthAccountByAddressAsync(string address, CancellationToken cancellationToken = default);
ResponseWithHeight<IAccount> GetAuthAccountByAddress(string address);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var account =
await client.Auth.GetAuthAccountByAddressAsync("cosmos16xyempempp92x9hyzz9wrgf94r6j9h5f06pxxv");
Get the account information on blockchain.
address - string - Address
ResponseWithHeight<IAccount Interface>
public interface IAccount
{
public PublicKey GetPublicKey();
public ulong GetSequence();
public ulong GetAccountNumber();
}
Task<ResponseWithHeight<IList<Delegation>>> GetDelegationsAsync(string delegatorAddr, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<Delegation>> GetDelegations(string delegatorAddr);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var delegations = client
.Staking
.GetDelegations(Configuration.LocalDelegator1Address);
Get all delegations from a delegator.
delegatorAddr - Bech32 AccAddress of Delegator.
List of Delegation structs
public class Delegation
{
string DelegatorAddress;
string ValidatorAddress;
BigDecimal Shares;
BigInteger Balance;
}
Task<StdTx> PostDelegationsAsync(DelegateRequest request, CancellationToken cancellationToken = default);
StdTx PostDelegations(DelegateRequest request);
Task<GasEstimateResponse> PostDelegationsSimulationAsync(DelegateRequest request, CancellationToken cancellationToken = default);
GasEstimateResponse PostDelegationsSimulation(DelegateRequest request);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var baseRequest = await client.CreateBaseReq(Configuration.LocalDelegator1Address, null, null, null, null, null);
var delegateRequest = new DelegateRequest(baseRequest, Configuration.LocalDelegator1Address, Configuration.LocalValidatorAddress, new Coin("stake", 10));
var postResult = await client
.Staking
.PostDelegationsAsync(delegateRequest);
Format Delegation transaction. Sign and send it with SignAndBroadcastStdTxAsync method. The simulation version returns gas estimate.
request - DelegateRequest
public class DelegateRequest
{
public BaseReq BaseReq;
public string DelegatorAddress;
public string ValidatorAddress;
public Coin Amount;
}
Transaction in JSON format.
The simulation version returns GasEstimateResponse struct.
Represents the estimated transaction fees.
public class GasEstimateResponse
{
public ulong GasEstimate;
}
Task<ResponseWithHeight<Delegation>> GetDelegationByValidatorAsync(string delegatorAddr, string validatorAddr, CancellationToken cancellationToken = default);
ResponseWithHeight<Delegation> GetDelegationByValidator(string delegatorAddr, string validatorAddr);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var delegation = await client
.Staking
.GetDelegationByValidatorAsync(Configuration.LocalDelegator1Address,
Configuration.LocalValidatorAddress);
Query the current delegation between a delegator and a validator.
delegatorAddr - Bech32 AccAddress of Delegator validatorAddr - Bech32 OperatorAddress of validator
Delegation struct
Task<ResponseWithHeight<IList<UnbondingDelegation>>> GetUnbondingDelegationsAsync(string delegatorAddr, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<UnbondingDelegation>> GetUnbondingDelegations(string delegatorAddr);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var delegations = await client
.Staking
.GetUnbondingDelegationsAsync(Configuration.LocalDelegator1Address);
Get all unbonding delegations from a delegator.
delegatorAddr - Bech32 AccAddress of Delegator
List of UnbondingDelegation struct
public class UnbondingDelegation
{
public string DelegatorAddress;
public string ValidatorAddress;
public IList<UnbondingDelegationEntry> Entries;
}
public class UnbondingDelegationEntry
{
/// Height which the unbonding took place.
public long CreationHeight { get; set; }
/// Time at which the unbonding delegation will complete.
public DateTimeOffset CompletionTime { get; set; }
/// Atoms initially scheduled to receive at completion.
public BigInteger InitialBalance { get; set; }
/// Atoms to receive at completion.
public BigInteger Balance { get; set; }
}
Task<StdTx> PostUnbondingDelegationAsync(UndelegateRequest request, CancellationToken cancellationToken = default);
StdTx PostUnbondingDelegation(UndelegateRequest request);
Task<GasEstimateResponse> PostUnbondingDelegationSimulationAsync(UndelegateRequest request, CancellationToken cancellationToken = default);
GasEstimateResponse PostUnbondingDelegationSimulation(UndelegateRequest request);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var baseRequest = await client.CreateBaseReq(Configuration.LocalDelegator1Address, null, null, null, null, null);
var undelegateRequest = new UndelegateRequest(baseRequest, Configuration.LocalDelegator1Address, Configuration.LocalValidatorAddress, new Coin("stake", 10));
var tx = (await client
.Staking
.PostUnbondingDelegationAsync(undelegateRequest));
Format transaction for unbonding delegation. Sign and send it with SignAndBroadcastStdTxAsync method.
request - UndelegateRequest
public class UndelegateRequest
{
public BaseReq BaseReq;
public string DelegatorAddress;
public string ValidatorAddress;
public Coin Amount;
}
Transaction in JSON format. The simulation version returns GasEstimateResponse struct.
Task<ResponseWithHeight<UnbondingDelegation>> GetUnbondingDelegationsByValidatorAsync(string delegatorAddr, string validatorAddr, CancellationToken cancellationToken = default);
ResponseWithHeight<UnbondingDelegation> GetUnbondingDelegationsByValidator(string delegatorAddr, string validatorAddr);
Task<ResponseWithHeight<IList<UnbondingDelegation>>> GetUnbondingDelegationsByValidatorAsync(string validatorAddr, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<UnbondingDelegation>> GetUnbondingDelegationsByValidator(string validatorAddr);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var result = await client
.Staking
.GetUnbondingDelegationsByValidatorAsync(Configuration.LocalDelegator1Address, Configuration.LocalValidatorAddress);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var unbondingDelegations = await client
.Staking
.GetUnbondingDelegationsByValidatorAsync(Configuration.GlobalValidator1Address);
- Query all unbonding delegations between a delegator and a validator.
- Get all unbonding delegations for a validator.
delegatorAddr - Bech32 AccAddress of Delegator validatorAddr - Bech32 OperatorAddress of validator
List of UnbondingDelegation struct
Task<ResponseWithHeight<IList<Redelegation>>> GetRedelegationsAsync(string? delegator = default, string? validatorFrom = default, string? validatorTo = default, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<Redelegation>> GetRedelegations(string? delegator = default, string? validatorFrom = default, string? validatorTo = default);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var result = await client
.Staking
.GetRedelegationsAsync(Configuration.GlobalDelegator1Address, Configuration.GlobalValidator1Address, Configuration.GlobalValidator2Address);
Get all redelegations.
delegator - Bech32 AccAddress of Delegator. validatorFrom - Bech32 ValAddress of SrcValidator. validatorTo - Bech32 ValAddress of DstValidator.
List of Redelegation struct
Redelegation contains the list of a particular delegator's redelegating bonds from a particular source validator to a particular destination validator
public class Redelegation
{
/// Delegator.
public string DelegatorAddress;
/// Validator redelegation source operator addr.
public string ValidatorSrcAddress;
/// Validator redelegation destination operator addr.
public string ValidatorDstAddress;
/// Redelegation entries.
public IList<Redelegation> Entries;
}
Task<StdTx> PostRedelegationAsync(RedelegateRequest request, CancellationToken cancellationToken = default);
StdTx PostRedelegation(RedelegateRequest request);
Task<GasEstimateResponse> PostRedelegationSimulationAsync(RedelegateRequest request, CancellationToken cancellationToken = default);
GasEstimateResponse PostRedelegationSimulation(RedelegateRequest request);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var baseRequest = await client.CreateBaseReq(Configuration.GlobalDelegator1Address, null, null, null, null, null);
var redelegationRequest = new RedelegateRequest(baseRequest, Configuration.GlobalDelegator1Address, Configuration.GlobalValidator1Address, Configuration.GlobalValidator2Address, new Coin("uatom", 10));
var tx = await client
.Staking
.PostRedelegationAsync(redelegationRequest);
Format a redelegation request transaction. Sign and send it with SignAndBroadcastStdTxAsync method.
request - RedelegateRequest
public class RedelegateRequest
{
public BaseReq BaseReq;
public string DelegatorAddress;
public string ValidatorSrcAddress;
public string ValidatorDstAddress;
public Coin Amount;
}
Transaction in JSON format. The simulation version returns GasEstimateResponse struct.
Task<ResponseWithHeight<IList<Validator>>> GetValidatorsAsync(BondStatus? status = default, int? page = default, int? limit = default, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<Validator>> GetValidators(BondStatus? status = default, int? page = default, int? limit = default);
ResponseWithHeight<IList<Validator>> GetValidators(string delegatorAddr);
Task<ResponseWithHeight<Validator>> GetValidatorAsync(string delegatorAddr, string validatorAddr, CancellationToken cancellationToken = default);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var validators = await client
.Staking
.GetValidatorsAsync();
Get all validator candidates. By default it returns only the bonded validators.
status - The validator bond status. page - The page number. limit - The maximum number of items per page. delegatorAddr - Bech32 AccAddress of Delegator.
List of Validator struct
Validator defines the total amount of bond shares and their exchange rate to coins. Slashing results in a decrease in the exchange rate, allowing correct calculation of future undelegations without iterating over delegators. When coins are delegated to this validator, the validator is credited with a delegation whose number of bond shares is based on the amount of coins delegated divided by the current exchange rate. Voting power can be calculated as total bonded shares multiplied by exchange rate.
public class Validator
{
/// Address of the validator's operator; bech encoded in JSON.
public string OperatorAddress { get; set; } = null!;
/// The consensus public key of the validator; bech encoded in JSON.
public string ConsPubKey { get; set; } = null!;
/// Has the validator been jailed from bonded status.
public bool Jailed { get; set; }
/// Validator status (bonded/unbonding/unbonded).
public BondStatus Status { get; set; }
/// delegated tokens (incl. self-delegation).
public BigInteger Tokens { get; set; }
/// Total shares issued to a validator's delegators.
public BigDecimal DelegatorShares { get; set; }
/// Description terms for the validator.
public ValidatorDescription Description { get; set; } = null!;
/// If unbonding, height at which this validator has begun unbonding.
public long UnbondingHeight { get; set; }
/// If unbonding, min time for the validator to complete unbonding.
public DateTimeOffset UnbondingCompletionTime { get; set; }
/// Commission parameters.
public ValidatorCommission Commission { get; set; } = null!;
/// Validator's self declared minimum self delegation.
public BigInteger MinSelfDelegation { get; set; }
}
public enum BondStatus
{
Unbonded = 0,
Unbonding = 1,
Bonded = 2,
}
public class ValidatorDescription
{
/// Name.
public string Moniker { get; set; } = null!;
/// Optional identity signature (ex. UPort or Keybase).
public string Identity { get; set; } = null!;
/// Optional website link.
public string Website { get; set; } = null!;
/// Optional details.
public string Details { get; set; } = null!;
}
public class ValidatorCommission
{
public CommissionRates CommissionRates { get; set; } = null!;
/// The last time the commission rate was changed.
public DateTimeOffset UpdateTime { get; set; }
}
Task<ResponseWithHeight<Validator>> GetValidatorAsync(string delegatorAddr, string validatorAddr, CancellationToken cancellationToken = default);
ResponseWithHeight<Validator> GetValidator(string delegatorAddr, string validatorAddr);
cancellationToken = default);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var validators = await client
.Staking
.GetValidatorsAsync(BondStatus.Bonded, limit: 3);
Query a validator that a delegator is bonded to.
delegatorAddr - Bech32 AccAddress of Delegator. validatorAddr - Bech32 ValAddress of Delegator.
Validator struct
Task<IList<PaginatedTxs>> GetTransactionsAsync(string delegatorAddr, IList<DelegatingTxType>? txTypes = default, CancellationToken
IList<PaginatedTxs> GetTransactions(string delegatorAddr, IList<DelegatingTxType>? txTypes = default);
This example shows how to get Bond transactions.
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var txTypes = new List<DelegatingTxType>()
{
DelegatingTxType.Bond
};
var txs = await client
.Staking
.GetTransactionsAsync(Configuration.GlobalDelegator1Address, txTypes);
Get the list of delegation transactions by delegator address and transaction type
delegatorAddr - Delegator address txTypes - Transaction types
List of PaginatedTxs
Task<ResponseWithHeight<IList<Delegation>>> GetDelegationsByValidatorAsync(string validatorAddr, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<Delegation>> GetDelegationsByValidator(string validatorAddr);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var validatorResponse = await client
.Staking
.GetValidatorAsync(Configuration.GlobalValidator1Address);
Get all delegations for a validator.
validatorAddr - Bech32 OperatorAddress of validator
List of Delegation struct
Task<ResponseWithHeight<StakingPool>> GetStakingPoolAsync(CancellationToken cancellationToken = default);
ResponseWithHeight<StakingPool> GetStakingPool();
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var pool = await client
.Staking
.GetStakingPoolAsync();
Get the current state of the staking pool.
None
StakingPool struct
public class StakingPool
{
public BigInteger NotBondedTokens;
public BigInteger BondedTokens;
}
Task<ResponseWithHeight<StakingParams>> GetStakingParamsAsync(CancellationToken cancellationToken = default);
ResponseWithHeight<StakingParams> GetStakingParams();
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var @params = await client
.Staking
.GetStakingParamsAsync();
Get the current staking parameter values
None
StakingParams struct
public class StakingParams
{
/// Nanoseconds count.
public long UnbondingTime;
public ushort MaxValidators;
public ushort MaxEntries;
public string BondDenom;
}
Task<ResponseWithHeight<IList<Proposal>>> GetProposalsAsync(string? voter = default, string? depositor = default, ProposalStatus? status = default, ulong? limit = default, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<Proposal>> GetProposals(string? voter = default, string? depositor = default, ProposalStatus? status = default, ulong? limit = default);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var proposals = await client
.Governance
.GetProposalsAsync(limit: 5);
Query proposals.
voter - Voter address. depositor - Depositor address. status - Proposal status. limit - Maximum number of items.
List of Proposal struct
public class Proposal
{
public IProposalContent Content;
public ulong ProposalId;
public ProposalStatus Status;
public TallyResult FinalTallyResult;
public DateTimeOffset SubmitTime;
public DateTimeOffset DepositEndTime;
public IList<Coin> TotalDeposit;
public DateTimeOffset VotingStartTime;
public DateTimeOffset VotingEndTime;
}
Task<GasEstimateResponse> PostProposalSimulationAsync(PostProposalReq request, CancellationToken cancellationToken = default);
Task<GasEstimateResponse> PostProposalSimulationAsync(BaseReq baseReq, string title, string description, string proposer, IList<Coin> initialDeposit, Type proposalContentType, CancellationToken cancellationToken = default);
Task<GasEstimateResponse> PostProposalSimulationAsync<TContentType>(BaseReq baseReq, string title, string description, string proposer, IList<Coin> initialDeposit, CancellationToken cancellationToken = default) where TContentType : IProposalContent;
GasEstimateResponse PostProposalSimulation(PostProposalReq request);
GasEstimateResponse PostProposalSimulation(BaseReq baseReq, string title, string description, string proposer, IList<Coin> initialDeposit, Type proposalContentType);
GasEstimateResponse PostProposalSimulation<TContentType>(BaseReq baseReq, string title, string description, string proposer, IList<Coin> initialDeposit) where TContentType : IProposalContent;
Task<StdTx> PostProposalAsync(PostProposalReq request, CancellationToken cancellationToken = default);
Task<StdTx> PostProposalAsync(BaseReq baseReq, string title, string description, string proposer, IList<Coin> initialDeposit, Type proposalContentType, CancellationToken cancellationToken = default);
Task<StdTx> PostProposalAsync<TContentType>(BaseReq baseReq, string title, string description, string proposer, IList<Coin> initialDeposit, CancellationToken cancellationToken = default) where TContentType : IProposalContent;
StdTx PostProposal(PostProposalReq request);
StdTx PostProposal(BaseReq baseReq, string title, string description, string proposer, IList<Coin> initialDeposit, Type proposalContentType);
StdTx PostProposal<TContentType>(BaseReq baseReq, string title, string description, string proposer, IList<Coin> initialDeposit) where TContentType : IProposalContent;
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var baseReq = await client.CreateBaseReq(Configuration.GlobalDelegator1Address, "", null, null, null, null);
var initialDeposit = new List<Coin>()
{
new Coin()
{
Amount = 10,
Denom = "uatom"
}
};
var stdTx = await client
.Governance
.PostProposalAsync<TextProposal>(baseReq, "title", "description", Configuration.GlobalDelegator1Address, initialDeposit);
Format a proposal transaction. Sign and send it with SignAndBroadcastStdTxAsync method.
request - PostProposalReq struct baseReq - base request title - Proposal title description - Proposal description proposer - Proposer address initialDeposit - Initial proposal deposit proposalContentType - Proposal type
Transaction in JSON format. The simulation version returns GasEstimateResponse struct.
Task<ResponseWithHeight<Proposal>> GetProposalAsync(ulong id, CancellationToken cancellationToken = default);
ResponseWithHeight<Proposal> GetProposal(ulong id);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var proposal = await client
.Governance
.GetProposalAsync(1);
Query a proposal.
id - Proposal ID
Proposal struct
Task<ResponseWithHeight<Proposer>> GetProposerByProposalIdAsync(ulong proposalId, CancellationToken cancellationToken = default);
ResponseWithHeight<Proposer> GetProposerByProposalId(ulong proposalId);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var proposer = await client
.Governance
.GetProposerByProposalIdAsync(ProposalId);
Query proposer.
proposalId - Proposal ID to query proposer for
Proposer struct
public class Proposer
{
public ulong ProposalId { get; set; }
public string ProposerAddress { get; set; } = null!;
}
Task<ResponseWithHeight<IList<Deposit>>> GetDepositsAsync(ulong proposalId, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<Deposit>> GetDeposits(ulong proposalId);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var deposits = await client
.Governance
.GetDepositsAsync(ProposalId);
Query deposits.
proposalId - Proposal ID
List of Deposit struct
public class Deposit
{
public IList<Coin> Amount;
public ulong ProposalId;
public string Depositor;
}
Task<GasEstimateResponse> PostDepositSimulationAsync(ulong proposalId, DepositReq request, CancellationToken cancellationToken = default);
GasEstimateResponse PostDepositSimulation(ulong proposalId, DepositReq request);
Task<StdTx> PostDepositAsync(ulong proposalId, DepositReq request, CancellationToken cancellationToken = default);
StdTx PostDeposit(ulong proposalId, DepositReq request);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var baseReq = await client.CreateBaseReq(Configuration.GlobalDelegator1Address, "memo", null, null, null, null);
var amount = new List<Coin>()
{
new Coin()
{
Amount = 10,
Denom = "uatom"
}
};
var depositReq = new DepositReq(baseReq, Configuration.GlobalDelegator1Address, amount);
var tx = await client
.Governance
.PostDepositAsync(ProposalId, depositReq);
Format a transaction to deposit tokens to a proposal. Sign and send it with SignAndBroadcastStdTxAsync method.
proposalId - Proposal ID request - Deposit request, DepositReq struct
public class DepositReq
{
public BaseReq BaseReq;
/// Address of the depositor.
public string Depositor;
/// Coins to add to the proposal's deposit.
public IList<Coin> Amount;
}
Transaction in JSON format. The simulation version returns GasEstimateResponse struct.
Task<ResponseWithHeight<Deposit>> GetDepositAsync(ulong proposalId, string depositor, CancellationToken cancellationToken = default);
ResponseWithHeight<Deposit> GetDeposit(ulong proposalId, string depositor);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var deposits = await client
.Governance
.GetDepositsAsync(ProposalId);
var expectedDeposit = deposits.Result.First();
var deposit = await client
.Governance
.GetDepositAsync(ProposalId, expectedDeposit.Depositor);
Query deposits by proposal ID and depositor.
proposalId - Proposal ID depositor - Depositor account
Deposit struct
Task<ResponseWithHeight<IList<Vote>>> GetVotesAsync(ulong proposalId, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<Vote>> GetVotes(ulong proposalId);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var votes = await client
.Governance
.GetVotesAsync(ProposalId);
Query voters information by proposalId.
proposalId - Proposal ID
List of Vote struct
public class Vote
{
public string Voter;
public ulong ProposalId;
public VoteOption Option;
}
Task<GasEstimateResponse> PostVoteSimulationAsync(ulong proposalId, VoteReq request, CancellationToken cancellationToken = default);
GasEstimateResponse PostVoteSimulation(ulong proposalId, VoteReq request);
Task<StdTx> PostVoteAsync(ulong proposalId, VoteReq request, CancellationToken cancellationToken = default);
StdTx PostVote(ulong proposalId, VoteReq request);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var baseReq = await client.CreateBaseReq(Configuration.GlobalDelegator1Address, "memo", null, null, null, null);
var voteReq = new VoteReq(baseReq, Configuration.GlobalDelegator1Address, VoteOption.Yes);
var tx = await client
.Governance
.PostVoteAsync(ProposalId, voteReq);
Format a voting transaction. Sign and send it with SignAndBroadcastStdTxAsync method.
proposalId - Proposal ID request - Voting request, VoteReq struct
public class VoteReq
{
public BaseReq BaseReq;
/// Address of the voter.
public string Voter;
public VoteOption Option;
}
public enum VoteOption : byte
{
Empty = 0x00,
Yes = 0x01,
Abstain = 0x02,
No = 0x03,
NoWithVeto = 0x04,
}
Transaction in JSON format. The simulation version returns GasEstimateResponse struct.
Task<ResponseWithHeight<Vote>> GetVoteAsync(ulong proposalId, string voter, CancellationToken cancellationToken = default);
ResponseWithHeight<Vote> GetVote(ulong proposalId, string voter);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var votes = await client
.Governance
.GetVotesAsync(ProposalId);
var expectedVote = votes.Result.Last();
var vote = await client
.Governance
.GetVoteAsync(ProposalId, expectedVote.Voter);
Query vote information by proposal Id and voter address.
proposalId - Proposal ID voter - Bech32 voter address
Vote struct
Task<ResponseWithHeight<TallyResult>> GetTallyAsync(ulong proposalId, CancellationToken cancellationToken = default);
ResponseWithHeight<TallyResult> GetTally(ulong proposalId);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var tally = await client
.Governance
.GetTallyAsync(ProposalId);
Gets a proposal’s tally result at the current time. If the proposal is pending deposits (i.e status ‘DepositPeriod’) it returns an empty tally result.
proposalId - Proposal ID
TallyResult struct
public class TallyResult
{
public BigDecimal Yes { get; set; }
public BigDecimal Abstain { get; set; }
public BigDecimal No { get; set; }
public BigDecimal NoWithVeto { get; set; }
}
Task<ResponseWithHeight<DepositParams>> GetDepositParamsAsync(CancellationToken cancellationToken = default);
ResponseWithHeight<DepositParams> GetDepositParams();
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var depositParams = await client
.Governance
.GetDepositParamsAsync();
Query governance deposit parameters.
None
DepositParams struct
public class DepositParams
{
/// Minimum deposit for a proposal to enter voting period.
public IList<Coin>? MinDeposit;
/// Maximum period in nanoseconds for Atom holders to deposit on a proposal.
public long? MaxDepositPeriod;
}
Task<ResponseWithHeight<TallyParams>> GetTallyParamsAsync(CancellationToken cancellationToken = default);
ResponseWithHeight<TallyParams> GetTallyParams();
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var tallyParams = await client
.Governance
.GetTallyParamsAsync();
Query governance tally parameters.
None
TallyParams struct
public class TallyParams
{
/// Minimum percentage of total stake needed to vote for a result to be considered valid.
public BigDecimal? Quorum;
/// Minimum proportion of Yes votes for proposal to pass.
public BigDecimal? Threshold;
/// Minimum value of Veto votes to Total votes ratio for proposal to be vetoed.
public BigDecimal? Veto;
}
Task<ResponseWithHeight<VotingParams>> GetVotingParamsAsync(CancellationToken cancellationToken = default);
ResponseWithHeight<VotingParams> GetVotingParams();
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var votingParams = await client
.Governance
.GetVotingParamsAsync();
Query governance voting parameters.
None
VotingParams struct
public class VotingParams
{
/// Length of the voting period in nanoseconds.
public long? VotingPeriod;
}
Task<ResponseWithHeight<ValidatorSigningInfo>> GetSigningInfoAsync(string publicKey, CancellationToken cancellationToken = default);
ResponseWithHeight<ValidatorSigningInfo> GetSigningInfo(string publicKey);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var validators = await client.Staking.GetValidatorsAsync();
var validator = validators.Result.First();
Get sign info of a validator.
publicKey - Validator's public key.
ValidatorSigningInfo struct
public class ValidatorSigningInfo
{
/// Validator consensus address.
public string Address { get; set; } = null!;
/// Height at which validator was first a candidate OR was unjailed.
public long StartHeight { get; set; }
/// Index offset into signed block bit array.
public long IndexOffset { get; set; }
/// Timestamp validator cannot be unjailed until.
public DateTimeOffset JailedUntil { get; set; }
/// Whether or not a validator has been tombstoned (killed out of validator set).
public bool Tombstoned { get; set; }
/// Missed blocks counter (to avoid scanning the array every time).
public long MissedBlocksCounter { get; set; }
}
Task<ResponseWithHeight<IList<ValidatorSigningInfo>>> GetSigningInfosAsync(int? page = default, int? limit = default, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<ValidatorSigningInfo>> GetSigningInfos(int? page = default, int? limit = default);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var signingInfos = await client
.Slashing
.GetSigningInfosAsync();
Get signing info of multiple validators.
page - Page number. limit - Maximum number of items per page.
ValidatorSigningInfo struct
Task<GasEstimateResponse> PostUnjailSimulationAsync(string validatorAddress, UnjailRequest request, CancellationToken cancellationToken = default);
GasEstimateResponse PostUnjailSimulation(string validatorAddress, UnjailRequest request);
Task<StdTx> PostUnjailAsync(string validatorAddress, UnjailRequest request, CancellationToken cancellationToken = default);
StdTx PostUnjail(string validatorAddress, UnjailRequest request);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var baseReq = await client.CreateBaseReq(Configuration.LocalAccount1Address, "memo", null, null, null, null);
var stdTx = await client
.Slashing
.PostUnjailAsync(Configuration.LocalValidator1Address, new UnjailRequest(baseReq));
Format Unjail transaction. Sign and send it with SignAndBroadcastStdTxAsync method.
validatorAddress - Validator address request - UnjailRequest request
public class UnjailRequest
{
public BaseReq BaseReq { get; set; } = null!;
}
Transaction in JSON format. The simulation version returns GasEstimateResponse struct.
Task<ResponseWithHeight<SlashingParams>> GetParametersAsync(CancellationToken cancellationToken = default);
ResponseWithHeight<SlashingParams> GetParameters();
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var slashingParams = await client
.Slashing
.GetParametersAsync();
Get the current slashing parameters.
None
SlashingParams struct
public class SlashingParams
{
/// Duration in nanoseconds.
public long MaxEvidenceAge { get; set; }
public long SignedBlocksWindow { get; set; }
public BigDecimal MinSignedPerWindow { get; set; }
/// Duration in nanoseconds.
public long DowntimeJailDuration { get; set; }
public BigDecimal SlashFractionDoubleSign { get; set; }
public BigDecimal SlashFractionDowntime { get; set; }
}
ResponseWithHeight<DelegatorTotalRewards> GetDelegatorRewards(string delegatorAddress);
Task<ResponseWithHeight<DelegatorTotalRewards>> GetDelegatorRewardsAsync(string delegatorAddress, CancellationToken cancellationToken = default);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var rewards = await client
.Distribution
.GetDelegatorRewardsAsync(Configuration.LocalDelegator1Address);
Get the total rewards balance from all delegations.
delegatorAddress - Delegator address to query
DelegatorTotalRewards struct
public class DelegatorTotalRewards
{
public IList<DelegationDelegatorReward> Rewards;
public IList<DecCoin> Total;
}
Task<GasEstimateResponse> PostWithdrawRewardsSimulationAsync(string delegatorAddress, WithdrawRewardsRequest request, CancellationToken cancellationToken = default);
GasEstimateResponse PostWithdrawRewardsSimulation(string delegatorAddress, WithdrawRewardsRequest request);
Task<StdTx> PostWithdrawRewardsAsync(string delegatorAddress, WithdrawRewardsRequest request, CancellationToken cancellationToken = default);
StdTx PostWithdrawRewards(string delegatorAddress, WithdrawRewardsRequest request);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var baseRequest = await client.CreateBaseReq(Configuration.LocalAccount1Address, "memo", null, null, null, null);
var stdTx = await client
.Distribution
.PostWithdrawRewardsAsync(Configuration.LocalDelegator1Address, new WithdrawRewardsRequest(baseRequest));
Format a withdraw all delegator rewards transaction. Sign and send it with SignAndBroadcastStdTxAsync method.
delegatorAddress - Delegator address request - WithdrawRewardsRequest struct
public class WithdrawRewardsRequest
{
public BaseReq BaseReq { get; set; } = null!;
}
Transaction in JSON format. The simulation version returns GasEstimateResponse struct.
Task<ResponseWithHeight<string>> GetWithdrawAddressAsync(string delegatorAddress, CancellationToken cancellationToken = default);
ResponseWithHeight<string> GetWithdrawAddress(string delegatorAddress);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var rewards = await client
.Distribution
.GetDelegatorRewardsAsync(Configuration.LocalDelegator1Address, Configuration.LocalValidator1Address);
Get the delegations' rewards withdrawal address. This is the address in which the user will receive the reward funds.
delegatorAddress - Delegator address to query
Withdraw address string
Task<GasEstimateResponse> PostWithdrawAddressSimulationAsync(string delegatorAddress, SetWithdrawalAddrRequest request, CancellationToken cancellationToken = default);
GasEstimateResponse PostWithdrawAddressSimulation(string delegatorAddress, SetWithdrawalAddrRequest request);
Task<StdTx> PostWithdrawAddressAsync(string delegatorAddress, SetWithdrawalAddrRequest request, CancellationToken cancellationToken = default);
StdTx PostWithdrawAddress(string delegatorAddress, SetWithdrawalAddrRequest request);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var baseRequest = await client.CreateBaseReq(Configuration.LocalAccount1Address, "memo", null, null, null, null);
var stdTx = await client
.Distribution
.PostWithdrawRewardsAsync(Configuration.LocalDelegator1Address, Configuration.LocalValidator1Address, new WithdrawRewardsRequest(baseRequest));
Format a transaction to replace the delegations' rewards withdrawal address for a new one. Sign and send it with SignAndBroadcastStdTxAsync method.
delegatorAddress - Delegator address request - SetWithdrawalAddrRequest struct
public class SetWithdrawalAddrRequest
{
public BaseReq BaseReq { get; set; } = null!;
public string WithdrawAddress { get; set; } = null!;
}
Transaction in JSON format. The simulation version returns GasEstimateResponse struct.
Task<ResponseWithHeight<ValidatorDistInfo>> GetValidatorDistributionInfoAsync(string validatorAddress, CancellationToken cancellationToken = default);
ResponseWithHeight<ValidatorDistInfo> GetValidatorDistributionInfo(string validatorAddress);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var address = await client
.Distribution
.GetWithdrawAddressAsync(Configuration.LocalDelegator1Address);
Query the distribution information of a single validator.
validatorAddress - Validator address
ValidatorDistInfo struct
public class ValidatorDistInfo
{
public string OperatorAddress;
public IList<DecCoin> SelfBondRewards;
public IList<DecCoin> ValCommission;
}
Task<ResponseWithHeight<IList<DecCoin>>> GetValidatorOutstandingRewardsAsync(string validatorAddress, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<DecCoin>> GetValidatorOutstandingRewards(string validatorAddress);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var rewards = await client
.Distribution
.GetValidatorOutstandingRewardsAsync(Configuration.LocalValidator1Address);
Fee distribution outstanding rewards of a single validator.
validatorAddress - Validator address
List of DecCoin struct
DecCoin defines a coin which can have additional decimal points.
public class DecCoin
{
public string Denom { get; set; } = null!;
public BigDecimal Amount { get; set; }
}
Task<ResponseWithHeight<IList<DecCoin>>> GetValidatorRewardsAsync(string validatorAddress, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<DecCoin>> GetValidatorRewards(string validatorAddress);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var rewards = await client
.Distribution
.GetValidatorRewardsAsync(Configuration.LocalValidator1Address);
Query the commission and self-delegation rewards of validator.
validatorAddress - Validator address
List of DecCoin struct
Task<GasEstimateResponse> PostValidatorWithdrawRewardsSimulationAsync(string validatorAddress, WithdrawRewardsRequest request, CancellationToken cancellationToken = default);
GasEstimateResponse PostValidatorWithdrawRewardsSimulation(string validatorAddress, WithdrawRewardsRequest request);
Task<StdTx> PostValidatorWithdrawRewardsAsync(string validatorAddress, WithdrawRewardsRequest request
StdTx PostValidatorWithdrawRewards(string validatorAddress, WithdrawRewardsRequest request);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var baseRequest = await client.CreateBaseReq(Configuration.LocalDelegator1Address, "memo", null, null, null, null);
var stdTx = await client
.Distribution
.PostValidatorWithdrawRewardsAsync(Configuration.LocalValidator1Address, new WithdrawRewardsRequest(baseRequest));
Format a transaction to withdraw the validator's self-delegation and commissions rewards. Sign and send it with SignAndBroadcastStdTxAsync method.
validatorAddress - Validator address request - WithdrawRewardsRequest struct
Transaction in JSON format. The simulation version returns GasEstimateResponse struct.
Task<ResponseWithHeight<IList<DecCoin>>> GetCommunityPoolAsync(long? height = default, CancellationToken cancellationToken = default);
ResponseWithHeight<IList<DecCoin>> GetCommunityPool(long? height = default);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var communityPool = await client
.Distribution
.GetCommunityPoolAsync();
Fee distribution parameters.
height - Block to query
List of DecCoin struct
Task<ResponseWithHeight<DistributionParams>> GetParamsAsync(long? height = default, CancellationToken cancellationToken = default);
ResponseWithHeight<DistributionParams> GetParams(long? height = default);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var @params = await client
.Distribution
.GetParamsAsync();
Get fee distribution parameters.
height - Block to query
public class DistributionParams
{
public BigDecimal CommunityTax;
public BigDecimal BaseProposerReward;
public BigDecimal BonusProposerReward;
public bool WithdrawAddrEnabled;
}
Task<ResponseWithHeight<MintParams>> GetParamsAsync(long? height = default, CancellationToken cancellationToken = default);
ResponseWithHeight<MintParams> GetParams(long? height = default);
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var @params = await client
.Mint
.GetParamsAsync();
Minting module parameters.
height - Block to query
MintParams struct
public class MintParams
{
/// Type of coin to mint.
public string MintDenom;
/// Maximum annual change in inflation rate.
public BigDecimal InflationRateChange;
/// Maximum inflation rate.
public BigDecimal InflationMax;
/// minimum inflation rate.
public BigDecimal InflationMin;
/// Goal of percent bonded atoms.
public BigDecimal GoalBonded;
/// Expected blocks per year.
public ulong BlocksPerYear;
}
Task<ResponseWithHeight<BigDecimal>> GetInflationAsync(CancellationToken cancellationToken = default);
ResponseWithHeight<BigDecimal> GetInflation();
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var inflation = await client
.Mint
.GetInflationAsync();
Current minting inflation value.
None
BigDecimal inflation rate
Task<ResponseWithHeight<BigDecimal>> GetAnnualProvisionsAsync(CancellationToken cancellationToken = default);
ResponseWithHeight<BigDecimal> GetAnnualProvisions();
using var client = new CosmosApiBuilder()
.UseBaseUrl("localhost:1317")
.RegisterCosmosSdkTypeConverters()
.CreateClient();
var annualProvisions = await client
.Mint
.GetAnnualProvisionsAsync();
Current minting annual provisions value.
None
BigDecimal provisions value