Skip to content

Reference implementation for the Zenon SDK for .NET

License

Notifications You must be signed in to change notification settings

0x3639/znn_sdk_csharp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zenon Sdk for .NET

nuget build codecov

Reference implementation for the Zenon SDK for .NET. Compatible with the Zenon Alphanet - Network of Momentum Phase 0. It provides a simple integration with any .NET based projects.

Installation

Install the Zenon.Sdk package from NuGet

dotnet add package Zenon.Sdk

Usage

Connect node

using Zenon;

var nodeUrl = new Uri("ws://nodes.zenon.place:35998");

await Znn.Instance.Client.Value.StartAsync(nodeUrl);
...
await Znn.Instance.Client.Value.StopAsync();

Generate wallet

using Zenon;

var wallet = "name";
var passphrase = "secret";

Znn.Instance.DefaultKeyStorePath = 
    Znn.Instance.KeyStoreManager.CreateNew(passphrase, wallet);
Znn.Instance.DefaultKeyStore = 
    Znn.Instance.KeyStoreManager.ReadKeyStore(passphrase, Znn.Instance.DefaultKeyStorePath);

Generate wallet from mnemonic

using Zenon;

var wallet = "name";
var passphrase = "secret";
var mnemonic =
      "route become dream access impulse price inform obtain engage ski believe awful absent pig thing vibrant possible exotic flee pepper marble rural fire fancy";

Znn.Instance.DefaultKeyStore = 
    Znn.Instance.KeyStoreManager.CreateFromMnemonic(mnemonic, passphrase, wallet);
Znn.Instance.DefaultKeyStore = 
    Znn.Instance.KeyStoreManager.ReadKeyStore(passphrase, Znn.Instance.DefaultKeyStorePath);

Sending a transaction

using Zenon;

var nodeUrl = new Uri("ws://nodes.zenon.place:35998");
var wallet = "name";
var passphrase = "secret";
var mnemonic =
      "route become dream access impulse price inform obtain engage ski believe awful absent pig thing vibrant possible exotic flee pepper marble rural fire fancy";

Znn.Instance.DefaultKeyStore = 
    Znn.Instance.KeyStoreManager.CreateFromMnemonic(mnemonic, passphrase, wallet);
Znn.Instance.DefaultKeyStore = 
    Znn.Instance.KeyStoreManager.ReadKeyStore(passphrase, Znn.Instance.DefaultKeyStorePath);
Znn.Instance.DefaultKeyPair = 
    Znn.Instance.DefaultKeyStore.GetKeyPair(); // Use primary address

await Znn.Instance.Client.Value.StartAsync(nodeUrl);

var tx = Znn.Instance.Embedded.Pillar.CollectReward();

await Znn.Instance.Send(tx);

await Znn.Instance.Client.Value.StopAsync();

Receive a transaction

using Zenon;
using Zenon.Model.NoM;

var nodeUrl = new Uri("ws://nodes.zenon.place:35998");
var wallet = "name";
var passphrase = "secret";
var mnemonic =
      "route become dream access impulse price inform obtain engage ski believe awful absent pig thing vibrant possible exotic flee pepper marble rural fire fancy";

Znn.Instance.DefaultKeyStore = 
    Znn.Instance.KeyStoreManager.CreateFromMnemonic(mnemonic, passphrase, wallet);
Znn.Instance.DefaultKeyStore = 
    Znn.Instance.KeyStoreManager.ReadKeyStore(passphrase, Znn.Instance.DefaultKeyStorePath);
Znn.Instance.DefaultKeyPair = 
    Znn.Instance.DefaultKeyStore.GetKeyPair(); // Use primary address

await Znn.Instance.Client.Value.StartAsync(nodeUrl);

var result = await Znn.Instance.Ledger
    .GetUnreceivedBlocksByAddress(Znn.Instance.DefaultKeyPair.Address);

if (result.Count != 0)
{
    foreach (var item in result.List)
    {
        var tx = AccountBlockTemplate.Receive(item.Hash);

        await Znn.Instance.Send(tx, true);
    }
}

await Znn.Instance.Client.Value.StopAsync();

Contributing

Please check CONTRIBUTING for more details.

License

The MIT License (MIT). Please check LICENSE for more information.

About

Reference implementation for the Zenon SDK for .NET

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%