Chia-Client-API 2.2.0.18

dotnet add package Chia-Client-API --version 2.2.0.18                
NuGet\Install-Package Chia-Client-API -Version 2.2.0.18                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Chia-Client-API" Version="2.2.0.18" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Chia-Client-API --version 2.2.0.18                
#r "nuget: Chia-Client-API, 2.2.0.18"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Chia-Client-API as a Cake Addin
#addin nuget:?package=Chia-Client-API&version=2.2.0.18

// Install Chia-Client-API as a Cake Tool
#tool nuget:?package=Chia-Client-API&version=2.2.0.18                

Chia-Client-API

Thank you for considering using the Chia Client API for C#! Here is a brief overview of what you can expect to find in this repository:

Description

This repository contains a C# wrapper for the Chia blockchain API. It allows you to easily interact with the Chia blockchain from your C# applications.

This library is also available on NuGet. You can find it by searching for "ChiaClientAPI" in the NuGet Package Manager or by using the following command in the Package Manager Console:

Install-Package Chia-Client-API

Features

A simple, easy-to-use interface for accessing the Chia API Support for all API endpoints, including those for managing accounts, sending and receiving transactions, and querying the blockchain Detailed documentation for each API endpoint, including descriptions of input and output parameters

  • viewing, creating and managing wallets
  • sending chia, cats, nfts
  • creating offers for chia, cats and nfts
  • exploring the blockchain
  • managing datalayer
  • managing simulator
  • Minting NFTs
  • Creating CATs

Requirements

.NET 6 or higher

Installation

To install this library from the repository, simply clone the repository and open the solution file in Visual Studio. You can then build the solution and reference the compiled library in your own C# projects.

Alternatively, you can install the library from NuGet as described above.

Usage

Note: Per default, chia rpc will only listen to requests from the local machine and also load the certificates of the local machine automatically.
If you have remote machines to manage, eg a full node or farmers, you need to enable public port listening.
For that, edit the chia configuration (default at ~/.chia/mainnet/config/config.yaml).
Look for a line starting with self-hostname like so: self_hostname: &self_hostname "localhost"
change it to: self_hostname: 0.0.0.0 to listen on all interfaces or to the local interface ip to listen on a specific interface.

You will need to create an instance of the ChiaClient class and pass in your API certificates:

// ... available endpoints ...
using Chia_Client_API.FullNodeAPI_NS;
using Chia_Client_API.WalletAPI_NS;
using Chia_Client_API.FarmerAPI_NS;
using Chia_Client_API.HarvesterAPI_NS;
using Chia_Client_API.DatalayerAPI_NS;

// ... initialize local host ...
Wallet_RPC_Client client = new Wallet_RPC_Client();

// ... initialize remote host ...
string certificatePath = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
    ".testnet","ssl");
Fullnode_Client = new FullNode_RPC_Client(targetApiAddress: "192.168.1.117", targetCertificateBaseFolder: certificatePath);

You can then call any of the API endpoints by calling the corresponding method on the client object. For example, to get the balance of an account, you can use the GetWalletBalance_Sync method:

using Chia_Client_API.WalletAPI_NS;
using CHIA_RPC.General_NS;
using CHIA_RPC.Wallet_NS.Wallet_NS;

namespace ChiaTransactionExaminator
{
    internal class Clients
    {
        private static Wallet_RPC_Client Wallet = new Wallet_RPC_Client();
        public decimal GetBalance()
        {
            WalletID_RPC walletID_RPC = new WalletID_RPC(1);
            GetWalletBalance_Response response = Wallet.GetWalletBalance_Sync(walletID_RPC);
            return response.wallet_balance.confirmed_wallet_balance_in_xch;
        }
    }
}

Note that a request usually consists of 3 Steps:

  1. Compile the RPC document (with the included chia rpc library) This defines the data which you want to pull prom the chia node
  2. Making the request (with the chia client library) this actually connects to the node and makes the request
  3. Loading the data into a response

Refer to the documentation for specific usage instructions for each API endpoint.

Sending a transaction

Sending a standard transaction is straight forward, you can use the following procedure:

// login
FingerPrint_RPC myFingerprint = new FingerPrint_RPC(1234567890);
FingerPrint_Response loginResponse = Clients.Wallet_Client.LogIn_Sync(rpc);

// wait for the wallet to fully sync
Clients.Wallet_Client.AwaitWalletSync_Sync(timeoutSeconds: 1000);

// send transaction
SendTransaction_RPC XchTransactionRPC = new SendTransaction_RPC(1, "TargetAdress", amount_mojos: 1000, fee_mojos: 0);
GetTransaction_Response sendTransaction_Result = Clients.Wallet_Client.SendTransaction_Sync(transaction);

// wait to complete transaction (recommended)
Clients.Wallet_Client.AwaitTransactionToConfirm_Sync(sendTransaction_Result, CancellationToken.None, timeoutInMinutes: 60);

Creating a cat offer

this is how you offer Cat vs chia:

CatGetAssetId_Response assetId = Testnet_Wallet.Wallet_Client.CatGetAssetID_Sync(new WalletID_RPC(wallet.id));
CreateOfferForIds_RPC offer_rpc = new CreateOfferForIds_RPC();
offer_rpc.offer.Add("1", -50000); // you want to give 500000 mojos
offer_rpc.offer.Add(assetId.asset_id, 500); // you want to receive 0.5 of asset x
OfferFile offer = Testnet_Wallet.Wallet_Client.CreateOfferForIds_Sync(offer_rpc);
offer.Export("btftestoffer");

note you can also give amounts in decimal chia (note that 1 cat is normally 1000 mojos so mind the conversion there)

offer_rpc.AddOfferPosition("1", -0.005); // you want to give 500000 mojos

Contributing

We welcome contributions to this repository! If you have suggestions for improvements or new features, please open an issue or submit a pull request.

License

This library is licensed under the MIT License. Please see the LICENSE file for more information.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.0.18 107 6/11/2024
2.2.0.17 143 3/13/2024
2.2.0.14 111 3/5/2024
2.2.0 107 3/1/2024
2.1.3 193 12/21/2023
2.1.1.10 150 12/8/2023
2.1.1.9 151 11/26/2023
2.1.1.8 134 11/15/2023
2.1.1.7 113 11/15/2023
2.1.1.6 129 11/9/2023
2.1.1.4 142 10/20/2023
2.1.1 149 10/13/2023
2.0.1 151 10/5/2023
2.0.0.1 157 8/31/2023
2.0.0 153 8/28/2023
1.8.2.13 167 8/22/2023
1.8.2.12 134 8/22/2023
1.8.2.5 178 8/10/2023
1.8.2.4 153 8/9/2023
1.8.2.3 168 8/9/2023
1.8.2.2 153 8/9/2023
1.8.2.1 160 8/9/2023
1.8.2 157 7/26/2023
1.8.1.16 147 6/26/2023
1.8.1.15 157 6/23/2023
1.8.1.14 136 6/22/2023
1.8.1.13 138 6/22/2023
1.8.1.12 140 6/22/2023
1.8.1.11 139 6/22/2023
1.8.1.10 142 6/22/2023
1.8.1.9 157 6/21/2023
1.8.1.8 170 6/14/2023
1.8.1.7 145 6/14/2023
1.8.1.6 178 6/12/2023
1.8.1.5 164 6/9/2023
1.8.1.4 155 6/9/2023
1.8.1.3 159 6/9/2023
1.8.1.2 162 6/7/2023
1.8.1.1 156 6/7/2023
1.8.1 161 6/2/2023
1.8.0 178 5/11/2023
1.7.1 196 4/21/2023
1.6.2.14 296 2/8/2023
1.6.2.13 261 2/8/2023
1.6.2.12 277 2/5/2023
1.6.2.10 295 1/31/2023
1.6.2.9 268 1/31/2023
1.6.2.8 296 1/28/2023
1.6.2.7 301 1/26/2023
1.6.2.6 306 1/25/2023
1.6.2.5 288 1/24/2023
1.6.2.4 291 1/17/2023
1.6.2.3 296 1/16/2023
1.6.2.2 297 1/15/2023
1.6.2.1 301 1/13/2023
1.6.2 312 1/12/2023
1.6.1.6 299 1/11/2023
1.6.1.5 305 1/11/2023
1.6.1.4 306 1/11/2023
1.6.1.3 325 1/10/2023
1.6.1.1 315 12/29/2022
1.6.1 308 12/29/2022

2.2.0.18
implemented fix for certificate loader. It is nof possible to manage multiple hosts and endpoints in parallel

2.2.0.17
- hotfix for GetOfferSummary_Response (please report if there is an issue. Its not documented on chia docs)
- implemented clean expired offers custom function according to https://github.com/Chia-Network/chia-blockchain/issues/17476

2.2.0.14
- Fix Mempool related objects for get_all_mempool_items
- Add Custom Property FeePerCost to Mempool Item
- Update Block RPC
- Add implicit conversions from block record to header hash
- Fix response raw content
- Add fee_xch to Mempool item
- User can now decide if raw response should be included or not
- added raw response option to constructor
- implement get_wallet_adresses
- fix file sorting issue when loading certificates. Noiw properly selects the private key
- fix certificate loader in some occasions on ubuntu

2.2.0
- Implement Datalayer get_proof
- implement Datalayer verify_proof
- implement get_aggsig_additional_data
- add custom DustSmallCoins function which can clean a wallet and combine small coins
- add implicit conversion to GetSpendableCoins_RPC
- removed parameter from nft_nft_get_nfts according to documentation update
- removed Transaction History References which are for another branch
- added GetSortedCoins to GetSpendableCoins_Response
- added GetSortedCoins to GetSpendableCoins_Response
- added Bech32 helperFunctions
- implemented and tested curtom coin merge functionality
- Reverse engineered, fixed and tested send_transaction_multi
- Reverse engineered and implemented custom function of coin_split, same as the cli command
- add support for .net 8

2.1.3
- removed ammount_correct_custom as it was a workaround for a bug in outgoing trades in previous chia versions
- Compatible with chia 2.1.2

2.1.1.10 - Critical BugFix
Critical:
fixed a bug where the client could not load the endpoint. Leaving the API Library unable to establish a connection to the Nodes.

Otner:
- update offer sort key
- fix index out of range exception with SeekBlockTransactionIndex
- update cert loading
- update offer sort key
- add Websocket implementation (only compatible with linux < chia 2.1.2)
  requires tls 1.2 allowance in chia config for windows on chia >= 2.1.2


2.1.1.9
- added workaround for amount in cat
- added AssetIDCache as utility class in chia_client_api.Helpers_NS useful if you need to look up asset ids often
- added information to offer summary if the offer will generate a separate fee transaction for the person accepting the offer
- added information to TradeRecord if this offer generates a separate fee transaction for you
- traderecord status is now the apropriate enum TradeStatus
- added implicit conversion from TransactionDict to WalletID_RPC
- added functionality to check if the file exists on disk due to extension
- added efficient hash comparing function to CHIA_RPC.HelperFunctions_NS.HashCompare
- added utility comparing operations to coin. ==, != and .Equals()
- GetCoinID() is now deprecated. Please use the property CoinName
- added comparison function for two coin arrays
- added transaction comparison
- added implicit conversion from ulong to fingerprint_rpc
- added implicit operator for WalletID_RPC (ulong)
- added implicit operator for GetTransactions_RPC (walletID_RPC & ulong)
- improved client endpoints error handling. They will no longer return a null value. Please check if bool success and string error
- Fixed Paths for Cross Plattform compatibility

2.1.1.8
(!) added a critical workaround for chia <= 2.1.1 reporting incorrect amount in OUTGOING_TRADE transactions
use amount_correct_custom for now
see https://github.com/Chia-Network/chia-blockchain/issues/16842 for more details

2.1.1.7
- Updated GetAllOffers_RPC Documentation
- Updated get_all_offers sort_key type (string)
- Updated TradeRecord documentation with findings from offers
- Trade recod accepted_at_time can now be accessed through DateTime with accepted_at_time_dateTime
- NftCoinIdAndWalletId is noww a serializable object
- Format fix GetCoinRecords_Response documentation
- added offer summary and Asset info to offers (was dynamic object before)

2.1.1.6
- Updated Transactions documentation witn the caviats
- Removed obsolete marker with the now improved documentation for Get_Transaction and Get_Transactions

2.1.1.5
- Improved Documentation for GetTransactions_RPC
- Added jsonignore for offer_in_xch (because its a custom property)
- Updated GetTransactions Documentation
- Updated Transaction Documentation

2.1.1.4 Fix for error report function
- moved to asymetric aes encryption due to max data length of RSA

2.1.1.2
- Fixed an error where AwaitOfferToExecuteOrCancel gets stuck when called with an invalid offer
- Implemented Globalvar - packageVersion
- added opt-in error transmit feature improvement program. Transmitts error responses of the server in rsa4096 encrypted manner if opted in. More details in the parameter documentation
- typo corrections in WalletApi_wallet and WalletApi_WalletNode


2.1.1
- Improved nft documentation
- Added functionality to await until an offer is executed or cancalled/invaild
- Added implicit conversion for takeOffer RPC
- update AddOfferPosition (now supports cat and updated documentation)
- added a function to look up the wallet id of an nft in wallet client
- added functionality to await an nft transfer
- add SimpleTransfer_Async: one endpoint for standard chia, cat and nft transfers
- implemented daemon rpc endpoints
- Implemented Verifiable Credentials endpoints
- add clear_pending_roots endpoint according to documentation
- update unsubscribe documentation
- add dl wallet log in according to documentation
- implemented time-limited offers