FT4Client 0.1.1

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

// Install FT4Client as a Cake Tool
#tool nuget:?package=FT4Client&version=0.1.1

FT4 Client C#

FT4 Client implements the FT4 protocol features for account, asset and transaction history management when interacting with a decentralized application (dapp) built using the Postchain blockchain framework, also known as Chromia.

FT4 depends on an established connection to a Chromia blockchain using the PostchainClient.

Usage

Native

The FT4 client can be installed from nuget or referenced through DLLs from the releases.

Unity

The NET Standard 2.1 DLL is compatible and can be imported into Unity. Unpack the contents from the releases section and add them to the Unity project.

Initializing the FT4 connection

A ChromiaClient has to be initialized first following the steps described in the PostchainClient package. The ChromiaClient is then passed into the Ft4Connection.Create() method together with a valid SignatureProvider.

// Initialize the ChromiaClient
var blockchainRID = Buffer.From("7d565d92fd15bd1cdac2dc276cbcbc5581349d05a9e94ba919e1155ef4daf8f9");
var chromiaClient = await ChromiaClient.Create("http://localhost:7740", blockchainRID);

// Initialize the Ft4Connection
var userSignature = SignatureProvider.Create(Buffer.Repeat("0", 32)); // Replace with actual user private key here
var ft4Connection = await Ft4Connection.Create(Client, userSignature);

FT4 session

The main way to interact with and use the FT4 features is through a Ft4Session. A session will automatically be initialized with the first fetched account when you initialize a Ft4Connection. It can be accessed through the public property ft4Connection.CurrentSession. The list of all existing accounts related to the given signature can be accessed with ft4Connection.Accounts. In case a specific session needs to be started the ft4Connection.StartSession(Buffer accountId) method should be used.

var ft4Session = ft4Connection.CurrentSession; // Use the session for the first fetched account.

// Or... start a new session with another account.
ft4Session = await ft4Connection.StartSession(ft4Connection.Accounts[1].Id);

⚠ <b>Currently the FT4 Client does not support mixing operations that require FT4 auth and ones that don't require it. Use the method suitable for your needs.</b> ⚠

To call operations that need to be authenticated for FT4:
var receipt = await ft4Session.Call([
    new Operation("auth_operation_1", "someParam"),
    new Operation("auth_operation_2", "anotherParam")
]);
To call operations that don't need FT4 authentication:
var receipt = await ft4Session.CallWithoutAuth([
    new Operation("no_auth_operation_1", "someParam"),
    new Operation("no_auth_operation_2", "anotherParam")
]);

An optional parameter withNop = true applies for both methods. If omitted then a no-operation is added to the call to mark it as unique.

Account

Registration

Accounts in FT4 can be registered by using account creation strategies.

Currently the Open strategy has been implemented. It is intended to be used only in development environments, in order to simplify account creation.

var mainAuthDescriptor = new AuthDescriptor<SingleSignatureArgs>(
    new SingleSignatureArgs()
    {
        Flags = [AuthFlag.Account, AuthFlag.Transfer],
        Signer = pubKey
    }
);

// Register a new account using the Open account creation strategy.
await Account.Register(Client, userSignature, mainAuthDescriptor, RegistrationStrategies.Open);

Admin

You can also register an account with the Account.AdminRegister static method.

// Register a new account using an admin signature.
await Account.AdminRegister(chromiaClient, adminSignature, userAuthDescriptor);

Account Operations

The Account property can be accessed through the Ft4Session to call account specific operations. Currently AddAuthDescriptor and DeleteAuthDescriptor exist.

// Add an auth descriptor.
var authDescriptorToAdd = new AuthDescriptor<SingleSignatureArgs>(
    new SingleSignatureArgs()
    {
        Flags = [AuthFlag.Account, AuthFlag.Transfer],
        Signer = pubKey
    }
);

await ft4Session.Account.AddAuthDescriptor(authDescriptorToAdd);

// Delete an auth descriptor.
await ft4Session.Account.DeleteAuthDescriptor(ft4Session.Account.AuthDescriptors.Last().Id);

Queries

Queries do not have a specific FT4 implementation. You can use either the provided ChromiaClient directly or you can use the same client through the Ft4Connection.Client property and use the Query method provided there. Refer to the PostchainClient readme.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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

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
0.1.1 72 4/26/2024
0.1.0 79 4/15/2024