chia-dotnet 4.0.0

dotnet add package chia-dotnet --version 4.0.0                
NuGet\Install-Package chia-dotnet -Version 4.0.0                
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-dotnet" Version="4.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add chia-dotnet --version 4.0.0                
#r "nuget: chia-dotnet, 4.0.0"                
#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-dotnet as a Cake Addin
#addin nuget:?package=chia-dotnet&version=4.0.0

// Install chia-dotnet as a Cake Tool
#tool nuget:?package=chia-dotnet&version=4.0.0                

chia-dotnet

A .net client library for chia™ RPC interfaces that runs on linux and windows, including a bech32 implementation.

build CodeQL NuGet

Getting Started

See Also

Features

  • Coverage of all of chia's rpc endpoints
    • Daemon, Full Node, Farmer, Harvester, Wallet, Plotter, Crawler, DataLayer
  • Coverage of all of the methods at each endpoint
    • as of 2.2.0
  • Static types for chia input and outputs
  • Supports connecting via the daemon on wss or directly to each service with https
    • both https and wss use tha same interfaces so switching is seamless

Examples

Test carefully and in one of the testnets!

Example app

Try the example code or take a look at rchia remote chia management CLI.

Connect to the Node and find out about the blockchain
var endpoint = Config.Open().GetEndpoint("daemon");
using var rpcClient = new WebSocketRpcClient(endpoint);
await rpcClient.Connect();

var daemon = new DaemonProxy(rpcClient, "unit_tests");
await daemon.RegisterService();

var fullNode = new FullNodeProxy(rpcClient, "unit_tests");
var state = await fullNode.GetBlockchainState();
Console.WriteLine($"This node is synced: {state.Sync.Synced}");
Send me some chia
var endpoint = Config.Open().GetEndpoint("wallet");
using var rpcClient = new HttpRpcClient(endpoint);

var wallet = new WalletProxy(rpcClient, "unit_tests");
await wallet.WaitForSync();

// walletId of 1 is the main XCH wallet
var standardWallet = new Wallet(1, wallet);

// this is my receive address. feel free to run this code on mainnet as often as you like :-)
var transaction = await standardWallet.SendTransaction("xch1ls2w9l2tksmp8u3a8xewhn86na3fjhxq79gnsccxr0v3rpa5ejcsuugha7", 1, 1);

Listen for events

using chia.dotnet;

var endpoint = Config.Open().GetEndpoint("daemon");
using var rpcClient = new WebSocketRpcClient(endpoint);
await rpcClient.Connect();

var daemon = new DaemonProxy(rpcClient, "eventing_testharness");
// this listens for the messages sent to the ui
await daemon.RegisterService("wallet_ui"); 
daemon.StateChanged += (sender, data) => Console.WriteLine($"daemon state change: {data}");

var farmer = daemon.CreateProxyFrom<FarmerProxy>();
farmer.ConnectionAdded += (sender, data) => Console.WriteLine($"Connection added: {data}");
farmer.NewFarmingInfo += (sender, data) => Console.WriteLine($"Farming info: {data}");
farmer.NewSignagePoint += (sender, data) => Console.WriteLine($"Signage point: {data}");

while (true)
{
    await Task.Delay(100);
}

Build

dotnet build ./src

Install from nuget.org

dotnet add package chia-dotnet

Tests

There are various unit and integration tests in the test project that have example usage. Some tests might be set to skip because they either need input data specific to a wallet or they may be destructive.

Some Notes About Types and Naming

In addition to static vs dynamic typing, C# and Python have very different conventions for naming and formatting. For the most part I've tried to make this library fit into dotnet conventions. Please open an issue if something doesn't feel dotnet-y.

  • Method and property names are ProperCased.
  • Parameter names are camelCased.
  • The chia RPC uses unsigned integers where dotnet might use signed. In cases where chia expects an unsigned number, it is unsigned on the dotnet side.
  • ulong is used for the python 64 bit unsigned int.
  • System.Numerics.BigInteger is used for the python 128 bit unsigned int.
  • Where the RPC return a scalar value, the dotnet code will as well. If it is optional in python it will be Nullable<T> in dotnet
  • Where the RPC returns a list of named scalar values, they are returned as a Tuple with named fields.
  • Lists of things are returned as IEnumberable<T>.
  • Where the python code returns a differently shaped object based on its input or logic, the dotnet code is turned into multiple methods.
  • When the RPC returns a success flag equal to false, the dotnet code throws an exception.

chia and its logo are the registered trademark or trademark of Chia Network, Inc. in the United States and worldwide.

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 (1)

Showing the top 1 NuGet packages that depend on chia-dotnet:

Package Downloads
chia-dotnet-wallet

.NET implementation of chia wallet

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 930 5/4/2024
3.3.5 249 3/23/2024
2.1.12 242 12/12/2023

Chia 2.3.0 changes