tanitall / neo-lux

.NET API to interact with the NEO blockchain and invoke smart contracts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NEO Lux

NEO light wallet / blockchain API for C#.

Contents


Description

NEO Lux was developed to provide an easy way to interact with Smart Contracts in the NEO blockchain using C#.

A full node is not necessary, but you can have one running locally and connect to it using NEO Lux.

Compatibility

Platform Status
.NET framework Working
UWP Working
Mono Working
Xamarin / Mobile Untested
Unity Working

Installation

PM> Install-Package NeoLux

Usage

Import the package:

using NeoLux;

For invoking a Smart Contract, e.g.:

	var privKey = "XXXXXXXXXXXXXXXXprivatekeyhereXXXXXXXXXXX".HexToBytes();	 // can be any valid private key
	var key = new KeyPair(privKey);
	var scriptHash = "de1a53be359e8be9f3d11627bcca40548a2d5bc1"; // the scriptHash of the smart contract you want to use	
	// for now, contracts must be in the format Main(string operation, object[] args)
	var result = NeoAPI.CallContract(NeoAPI.Net.Test, key, scriptHash, "registerMailbox", new object[] { "ABCDE", "demo@phantasma.io" });

For getting the balance of an address:

	var balances = NeoAPI.GetBalance(NeoAPI.Net.Test, "AYpY8MKiJ9q5Fpt4EeQQmoYRHxdNHzwWHk");
	foreach (var entry in balances)
	{
		Console.WriteLine(entry.Key + " => " + entry.Value);
	}

Console Demo

A console program is included to demonstrate common features:

  • Loading private keys
  • Obtaining wallet address from private key
  • Query balance from an address
  • Invoking a NEP5 Smart Contract (query symbol and total supply)

Inputs Screenshot

Unity Support

NEOLux can be used together with Unity to make games that interact with the NEO blockchain. A Unity demo showcasing loading a NEO wallet and querying the balance is included.

Use caution, as most NEOLux methods are blocking calls; in Unity the proper way to call them is using Coroutines.

    IEnumerator SyncBalance()
    {
        var balances = NeoAPI.GetBalance(NeoAPI.Net.Test, this.keys.address);
        this.balance = balances["NEO"];
    }
	
	// Then you call the method like this
	StartCoroutine(SyncBalance());

Inputs Screenshot

TODO

  • Sending assets to address (GAS and NEO)
  • NEP5 token support

Credits and License

Created by SĂ©rgio Flores (http://lunarlabs.pt/).

Credits also go to the other devs of City Of Zion(http://cityofzion.io/), as this project started as a port of code from their NEON wallet from Javascript to C#. Of course, credits also go to the NEO team(http://neo.org), as I also used some code from their NEO source.

This project is released under the MIT license, see LICENSE.md for more details.

About

.NET API to interact with the NEO blockchain and invoke smart contracts

License:MIT License


Languages

Language:C# 100.0%