Skip to content

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

License

Notifications You must be signed in to change notification settings

NEO-Development/neo-lux

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 myKeys = 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, myKeys, scriptHash, "registerMailbox", new object[] { "ABCDE", "demo@phantasma.io" });

For transfering assets (NEO or GAS), e.g.:

	var privKey = "XXXXXXXXXXXXXXXXprivatekeyhereXXXXXXXXXXX".HexToBytes();	 // can be any valid private key
	var myKeys = new KeyPair(privKey);
	// WARNING: For now use test net only, this code is experimental, you could lose real assets if using main net
	var result = NeoAPI.SendAsset(NeoAPI.Net.Test, "AanTL6pTTEdnphXpyPMgb7PSE8ifSWpcXU" /*destination address*/, "GAS", 3 /*amount to send */ , myKeys);

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());

Using with Unity

Don't drop the source code of NEOLux inside Unity, it won't work. Instead of the provided .UnityPackage file to install it (or use the included Demo project as a template for your project).

If you have weird compilation errors inside Unity, try the project "Api Compatibility Level" to .NET 4.6.

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%