Coder Social home page Coder Social logo

znn_sdk_csharp's Introduction

Zenon Sdk for .NET

nuget build codecov

Reference implementation for the Zenon SDK for .NET. Compatible with the Zenon Alphanet - Network of Momentum Phase 1. 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;
using Zenon.Client;

// Create client instance with default options (mainnet)
using var client = new WsClient("wss://my.hc1node.com:35998");

// Connect to node
await client.ConnectAsync();

Generate wallet

using Zenon;
using Zenon.Wallet;

var walletName = "name";
var passphrase = "secret";

// Use key store manager
var walletManager = new KeyStoreManager();

// Create wallet
var walletDefinition = walletManager
    .CreateNew(passphrase, walletName);

Generate wallet from mnemonic

using Zenon;
using Zenon.Wallet;

var walletName = "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";

// Use key store manager
var walletManager = new KeyStoreManager();

// Create wallet
var walletDefinition = walletManager
    .CreateFromMnemonic(mnemonic, passphrase, walletName);

Sending a transaction

using Zenon;
using Zenon.Client;
using Zenon.Wallet;

// Use key store manager
var walletManager = new KeyStoreManager();

// Use first wallet available
var walletDefinition =
    (await walletManager.GetWalletDefinitionsAsync()).First();

// Options for retrieving the wallet
var options = new KeyStoreOptions()
{
    DecryptionPassword = "secret"
};

// Retrieve the wallet
var wallet =
    await walletManager.GetWalletAsync(walletDefinition, options);

// Create client instance with default options (mainnet)
using var client = new WsClient("wss://my.hc1node.com:35998");

// Connect to node
await client.ConnectAsync();

// Create zdk instance and attach primary wallet account
var zdk = new Zdk(client)
{
    DefaultWalletAccount =
        await wallet.GetAccountAsync(accountIndex: 0)
};

// Send tx
await zdk.SendAsync(zdk.Embedded.Pillar.CollectReward());

Receive a transaction

using Zenon;
using Zenon.Client;
using Zenon.Wallet;
using Zenon.Model.NoM;

// Use key store manager
var walletManager = new KeyStoreManager();

// Use first wallet available
var walletDefinition =
    (await walletManager.GetWalletDefinitionsAsync()).First();

// Options for retrieving the wallet
var options = new KeyStoreOptions()
{
    DecryptionPassword = "secret"
};

// Retrieve the wallet
var wallet =
    await walletManager.GetWalletAsync(walletDefinition, options);

// Create client instance with default options (mainnet)
using var client = new WsClient("wss://my.hc1node.com:35998");

// Connect to node
await client.ConnectAsync();

// Create zdk instance and attach primary wallet account
var zdk = new Zdk(client)
{
    DefaultWalletAccount =
        await wallet.GetAccountAsync(accountIndex: 0)
};

// Get account address
var address = await zdk.DefaultWalletAccount.GetAddressAsync();

// Get all unreceived tx's
var result = await zdk.Ledger
    .GetUnreceivedBlocksByAddress(address);

if (result.Count != 0)
{
    foreach (var item in result.List)
    {
        // Send tx
        await zdk.SendAsync(AccountBlockTemplate
            .Receive(client.ProtocolVersion, client.ChainIdentifier, item.Hash));
    }
}

Contributing

Please check CONTRIBUTING for more details.

License

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

znn_sdk_csharp's People

Contributors

kinggorrin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.