Git Product home page Git Product logo

nano.net's Introduction

Nano.Net

A .NET library for Nano. Still in development. Please feel free to submit any changes, bugfixes or new features with pull requests.

Features/Roadmap

  • Seed generation and derivation
  • Keypair and address generation
  • Local block signing
  • Unit conversion
  • RPC client for interacting with the network
  • Improve documentation

Usage

Using the RPC client

var rpcClient = new RpcClient("NODE_ADDRESS");

AccountInfoResponse accountInfo = await rpcClient.AccountInfoAsync("nano_3r9rdhbipf9xsnpxdhf7h7kebo8iyfefc9s3bcx4racody5wubz1y1kzaon9");
Console.WriteLine($"Balance (raw): {accountInfo.Balance}");
Console.WriteLine($"Representative: {accountInfo.Representative}");

Account creation and seed derivation

// Generate a random seed and create an Account using it and an index.
string randomSeed = Utils.GenerateSeed();
Account account1 = Account.FromSeed(randomSeed, 5);

// Create an Account from a private key
Account account2 = Account.FromPrivateKey("A066701E0641E524662E3B7F67F98A248C300017BAA8AA0D91A95A2BCAF8D4D8");

Key and address conversion

// Private key from a seed and index
byte[] privateKey = Utils.DerivePrivateKey("949DD42FB17350D7FDDEDFFBD44CB1D4DF977026E715E0C91C5A62FB6CA72716", index: 5);
            
// Public key from private key
byte[] publicKey = Utils.PublicKeyFromPrivateKey(privateKey);
            
// Convert from address to public key or in reverse
string address = Utils.AddressFromPublicKey(publicKey);
publicKey = Utils.PublicKeyFromAddress(address);

Sending and receiving a transaction

var rpcClient = new RpcClient("NODE_ADDRESS");
Account account = Account.FromPrivateKey("A066701E0641E524662E3B7F67F98A248C300017BAA8AA0D91A95A2BCAF8D4D8");
            
// Sets the balance, representative and frontier for this account from a node. Can also be set manually.
await rpcClient.UpdateAccountAsync(account);
            
// Creates a block and automatically sign it. The PoW nonce has to be obtained externally. Unit conversion isn't implemented yet.
var sendBlock = Block.CreateSendBlock(account,
    "nano_3tjhazni9juaoa8q9rw33nf3f6i45gswhpzrgrbrawxhh7a777ror9okstch",
    Amount.FromRaw("1"), 
    "POW_NONCE");
            
// Publish the block to the network.
await rpcClient.ProcessAsync(sendBlock);

// Receive a transaction
var receiveBlock = Block.CreateReceiveBlock(account, "PENDING_BLOCK_HASH", Amount.FromRaw("1"), "POW_NONCE"); // You can also get pending blocks for an account using the rpc client and use a PendingBlock object as an argument.

await rpcClient.ProcessAsync(receiveBlock);

Acknowledgements

  • NanoDotNet for bits of code, including the Nano base32 implementation
  • Chaos.NaCl for the original C# implementation of ED25519 signing and keypair generation
  • BLAKE2 for the C# implementation of Blake2B
  • BigDecimal for an arbitrary precision decimal for .NET

Donations

This library is 100% free, but donations are accepted at the address below. Any amount is appreciated. nano_168owitqjg7nhg1jqcqf9q4uqgtmcp5h9xtydh6ybz7zqa9mp197draz4azs

nano.net's People

Contributors

miguel1117 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.