Code Monkey home page Code Monkey logo

ontology-csharp-sdk's Introduction

Ontology C# SDK

Version 0.0.1

Overview

This C# SDK aims to help .NET developers when writing applications for the Ontology Blockhain. The initial implementation supports RPC.

Note: This software should be considered pre-alpha and only be used on testnet or privatenet



Setup / Usage

Requires .NET v4.7

  1. Download repository
https://github.com/OntologyCommunityDevelopers/ontology-csharp-sdk.git
  1. Modify Network/RPCrequest.cs to point to the appropriate RPC node
HttpWebRequest ontRPCRequest = (HttpWebRequest)WebRequest.Create("http://ont-privnet:20336"); <--- modify as needed
  1. Build and add ontology-csharp-sdk.dll to your project

  2. Create instance, e.g.

OntologySDK ontSDK = new OntologySDK();
  1. Call methods, e.g.
int BlockHeight = ontSDK.getBlockHeight();



Methods

Method Parameters Description Note
getBlockGenerationTime gets the current block generation time
getBlockHeight gets the current block height
getAddressBalance string gets the ont/ong balance of address
getNodeCount gets the number of network nodes
getBlockHeightByTxHash string gets the block height of specified transaction hash
getBlockHex int gets the block (hex) of specified block by block height
getBlockHex string gets the block (hex) of specified block by block hash
getBlockJson int gets the block (json) of specified block by block height
getBlockJson string gets the block (json) of specified block by block hash
getRawTransactionHex string gets the hex representation of a transaction based on transaction hash
getRawTransactionJson string gets the json representation of a transaction based on transaction hash



Account

createPrivateKey: create a private key using SecureRandom

getPublicKey: get a public key from a private key

  • privatekey (string)

createONTID create a ONTID from a private key

  • privatekey (string)

registerONTID register a ONTID on Blockchain

  • ontid (string)
  • privatekey (string)

transferFund: Transfer token from address to another address

  • name (string) - name of the fund, for example: ONT
  • fromaddress (string) from address
  • toaddress (string) to address
  • value (decimal) value of the fund
  • privatekey (string) private key of the from address



Example

  1. Create and Register ONTID
var privatekey = "YOUR PRIVATE KEY";  // your private key
var ontid = sdk.createONTID(privatekey); // create ONTID
var result = sdk.registerONTID(ontid, privatekey); // register ONTID on blockchain
Console.WriteLine("result:{0}", result.content.ToString()); // use result value to query on explore.ont.io
  1. Transfer Fund
var privatekey = "YOUR PRIVATE KEY";  // your private key
var publickey = sdk.getPublicKey(privatekey);  // get your public key
var fromaddress = sdk.createAddressFromPublickKey(publickey); // get your address
var toaddress = "TO ADDRESS";
var result = sdk.transferFund("ONT", fromaddress, toaddress, 5, privatekey); // transfer 5 ONT from your address to destination toaddress
Console.WriteLine("result:{0}", result.content); // use result value to query on explore.ont.io

======= | createPrivateKey | | create a private key using SecureRandom | | | getPublicKey | string | get a public key from a private key | |



License

This project is licensed under the GNU GENERAL PUBLIC LICENSE v3.0

ontology-csharp-sdk's People

Contributors

panther142 avatar

Watchers

 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.