Skip to content

eanzhao/aelf-sdk.cs

 
 

Repository files navigation

AElf-Client

Introduction

This is a C# client library, used to communicate with the AElf API.

Getting Started

You should build the "AElf.Client" project first to get files defined in protos, which will be generated in the directory named "Protobuf/Generated".

Basic usage

private const string BaseUrl = "Http://127.0.0.1:8100";

// get client instance
AElfClient aelfClient = new AElfClient(BaseUrl);
var height = await aelfClient.GetBlockHeightAsync();

Interface

Interface methods can be easily available by the instance "aelfClient" shown in basic usage. The following is a list of input parameters and output for each method. Check out the Web api reference for detailed Interface description.

IBlockAppService

 Task<long> GetBlockHeightAsync();

 Task<BlockDto> GetBlockByHashAsync(string blockHash, bool includeTransactions = false);

 Task<BlockDto> GetBlockByHeightAsync(long blockHeight, bool includeTransactions = false);

IChainAppService

 Task<ChainStatusDto> GetChainStatusAsync();

 Task<byte[]> GetContractFileDescriptorSetAsync(string address);

 Task<RoundDto> GetCurrentRoundInformationAsync();

 Task<List<TaskQueueInfoDto>> GetTaskQueueStatusAsync();

 Task<int> GetChainIdAsync();

INetAppService

 Task<bool> AddPeerAsync(string address);

 Task<bool> RemovePeerAsync(string address);

 Task<List<PeerDto>> GetPeersAsync(bool withMetrics);

 Task<NetworkInfoOutput> GetNetworkInfoAsync();

ITransactionAppService

Task<TransactionPoolStatusOutput> GetTransactionPoolStatusAsync();

Task<string> ExecuteTransactionAsync(ExecuteTransactionDto input);

Task<string> ExecuteRawTransactionAsync(ExecuteRawTransactionDto input);

Task<CreateRawTransactionOutput> CreateRawTransactionAsync(CreateRawTransactionInput input);

Task<SendRawTransactionOutput> SendRawTransactionAsync(SendRawTransactionInput input);

Task<SendTransactionOutput> SendTransactionAsync(SendTransactionInput input);

Task<string[]> SendTransactionsAsync(SendTransactionsInput input);

Task<TransactionResultDto> GetTransactionResultAsync(string transactionId);

Task<List<TransactionResultDto>> GetTransactionResultsAsync(string blockHash, int offset = 0,int limit = 10);

Task<MerklePathDto> GetMerklePathByTransactionIdAsync(string transactionId);

IClientService

 Task<bool> IsConnected();

 Task<string> GetFormattedAddress(Address address);

 Task<string> GetAddressFromPubKey(string pubKey);

 Task<string> GetGenesisContractAddressAsync();

 Task<Address> GetContractAddressByName(Hash contractNameHash);

Test

This module contains tests for all services provided by AElfClient. You can see how to properly use services provided by AElfClient here.

You need to firstly set necessary parameters to make sure tests can run successfully.

  1. Set baseUrl to your target url.

    private const string BaseUrl = "Http://127.0.0.1:8001";
  2. Give a valid privateKey of a node.

    private const string PrivateKey = "09da44778f8db2e602fb484334f37df19e221c84c4582ce5b7770ccfbc3ddbef";

Note

You need to run a local or remote AElf node to run the unit test successfully. If you're not familiar with how to run a node or multiple nodes, please see Running a node / Running multiple nodes for more information.

About

AElf dotnet SDK

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 96.1%
  • PowerShell 2.4%
  • Shell 1.5%