PostchainClient 0.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package PostchainClient --version 0.4.0
NuGet\Install-Package PostchainClient -Version 0.4.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="PostchainClient" Version="0.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PostchainClient --version 0.4.0
#r "nuget: PostchainClient, 0.4.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 PostchainClient as a Cake Addin
#addin nuget:?package=PostchainClient&version=0.4.0

// Install PostchainClient as a Cake Tool
#tool nuget:?package=PostchainClient&version=0.4.0

Postchain Client API C#

Compatible with Postchain 3.1.0 / Rell 0.10.2

Installation

With NuGet:

Install-Package PostchainClient -Version 0.4.0

With .NET CLI:

dotnet add package PostchainClient --version 0.4.0

For more information, see https://www.nuget.org/packages/PostchainClient/0.4.0

From Unity Asset Store

https://assetstore.unity.com/packages/slug/165153

Usage

using Chromia.PostchainClient;


var keyPair = PostchainUtil.MakeKeyPair();
var privKey = keyPair["privKey"];
var pubKey = keyPair["pubKey"];

// The lower-level client that can be used for any
// postchain client messages. It only handles binary data.
var rest = new RESTClient("http://localhost:7740/");

// Instead of updateing the BRID each time the Rell code is compiled,
// the blockchain can now be accessed throug its chain_id from the 
// run.xml file (<chain name="MyCahin" iid="0">)
var initResult = await rest.InitializeBRIDFromChainID(0);
if (initResult.Error)
{
    Console.WriteLine("Cannot connect to blockchain!");
    return;
}

// Create an instance of the higher-level gtx client. It will
// use the rest client instance
var gtx = new GTXClient(rest);

// Start a new request. A request instance is created.
// The public keys are the keys that must sign the request
// before sending it to postchain. Can be empty.
var req = gtx.NewTransaction(new byte[][] {pubKey});

req.AddOperation("insert_city", "Hamburg", 22222);
req.AddOperation("create_user", pubKey, "Peter");

// Since transactions with the same operations will result in the same txid,
// transactions can contain "nop" operations. This is needed to satisfy
// the unique txid constraint of the postchain. 
req.AddOperation("nop", new Random().Next());

req.Sign(privKey, pubKey);

var result = await req.PostAndWaitConfirmation();
if (result.Error)
{
    Console.WriteLine("Operation failed: " + result.ErrorMessage);
}

// The expected return type has to be passed to the query function. This
// also works with complex types (i.e. your own struct as well as lists).
// The returned tuple will consist of (content, control). The content is of
// the type you pass the function. The control struct contains an error flag
// as well as the error message.
var queryResult = await gtx.Query<int>("get_city", ("name", "Hamburg"));
if (queryResult.control.Error)
{
    Console.WriteLine(queryResult.control.ErrorMessage);
}
else
{
    int plz = queryResult.content;
    Console.WriteLine("ZIP Query: " + plz);
}

// Same as above with the exception that byte arrays will be returned as strings.
// To convert it to a byte array, use the util function Util.HexStringToBuffer() 
// in the Chromia.Postchain.Client.GTX namespace.
var queryResult2 = await gtx.Query<string>("get_user_pubkey", ("name", "Peter"));
if (queryResult2.control.Error)
{
    Console.WriteLine(queryResult2.control.ErrorMessage);
}
else
{
    string queryPubkeyString = queryResult2.content;
    byte[] queryPubkey = PostchainUtil.HexStringToBuffer(queryPubkeyString);
    Console.WriteLine("User Query: " + PostchainUtil.ByteArrayToString(queryPubkey));
}

Rell file

entity city { key name; zip: integer; }
entity user {pubkey; name;}

operation insert_city (name, zip: integer) {
    create city (name, zip);
}

query get_city(name){
    return city @ {name}.zip;
}

query get_zip(zip: integer){
    return city @ {zip}.name;
}

operation create_user(pubkey, name){
    create user (pubkey,name);
}

query get_user_pubkey(name){
    return user @ {name}.pubkey;
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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 PostchainClient:

Package Downloads
FT4Client

Native FT4 C# API for Chromia Blockchain.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.6.3 358 3/28/2024
0.6.2 157 3/7/2024
0.6.1 562 9/1/2023
0.6.0 148 8/2/2023
0.5.1 2,055 9/21/2022
0.5.0 1,218 9/29/2021
0.4.3 293 8/6/2021
0.4.2 531 6/6/2021
0.4.1 273 6/6/2021
0.4.0 631 4/8/2020
0.3.6 521 2/1/2020
0.3.5 454 1/6/2020
0.3.4 460 10/18/2019
0.3.3 439 10/4/2019
0.3.1 482 9/17/2019
0.3.0 474 9/5/2019
0.2.0 492 9/2/2019
0.1.0 464 8/22/2019