Coder Social home page Coder Social logo

netezos's Introduction

Netezos

Made With License: MIT

.Net Standard 2.0 libraries pack for working with Tezos.

Package Nuget Description
Netezos.Rpc NuGet Tezos RPC wrapper
Netezos.Forge NuGet Forge operations locally or via RPC
Netezos.Keys NuGet Generate or parse keys, sign data, verify signature
Netezos.Ledger NuGet Interact with Tezos Ledger App

Netezos.Rpc

Netezos.Rpc provides an access to the Tezos node via RPC API. There is the main class TezosRpc which you need to build queries, supported by the Tezos RPC API.

Basic usage

Let's create an instance of the TezosRpc class, build a simple query and execute it by calling GetAsync() method.

using (var rpc = new TezosRpc("https://mainnet-tezos.giganode.io/"))
{
    // get the head block
    var head = await rpc.Blocks.Head.GetAsync();
    
    // get only the hash of the head block
    var hash = await rpc.Blocks.Head.Hash.GetAsync();
}

Note that the real HTTP request is sent only when you call GetAsync(). Until then, you work with just the query object, which can also be used to get subqueries.

Accessing blocks

You can access any block in two ways: by forward or backward indexing.

// gets the block with level = 1
var firstBlock = rpc.Blocks[1]; // forward indexing

// gets the last block (e.g. with level = 400000)
var lastBlock = rpc.Blocks.Head;

// gets the block with level = 400000 - 10 = 399990
var tenthFromLast = rpc.Blocks[-10]; // backward indexing

RpcList and RpcDictionary

The results of many RPC API methods can be interpreted as arrays or dictionaries that allow you to get many objects or only one by specifying a key or an index.

var operations = rpc.Blocks.Head.Operations;
var firstEndorsement = rpc.Blocks.Head.Operations[0][0];

var contracts = rpc.Blocks.Head.Context.Contracts;
var myContract = rpc.Blocks.Head.Context.Contracts["KT1..."];

Query parameters

If some RPC API method has query parameters, the corresponding query object have the overridden GetAsync() methods.

var activeDelegates = await rpc.Blocks.Head.Context.Delegates.GetAsync(DelegateStatus.Active);

var bakingRights = await rpc.Blocks.Head.Helpers.BakingRights.GetAsync(maxPriority: 1, all: true);

POST methods

There are several ways to pass the data to the server.

Some of the RPC queries contain overridden methods which take required and optional parameters. This is enough for the most cases.

var protoData = await rpc.Blocks.Head.Helpers.Forge.ProtocolData
    .PostAsync(0, "nceUHEeriV43iAfcxsCFf2Ygqn2cQZnuGKump9JEmhaVXt79CvXdY", "0000000349a42671");

If the overridden method does not meet your needs, you can simply pass the object with required fields and it will be automatically serialized to JSON before being sent.

var protoData = await rpc.Blocks.Head.Helpers.Forge.ProtocolData
    .PostAsync(new
    {
        priority = 0,
        nonce_hash = "nceUHEeriV43iAfcxsCFf2Ygqn2cQZnuGKump9JEmhaVXt79CvXdY",
        proof_of_work_nonce = "0000000349a42671"
    });

In addition, you can simply pass a valid JSON string.

var protoData = await rpc.Blocks.Head.Helpers.Forge.ProtocolData
    .PostAsync(@"{""priority"": 0, ""nonce_hash"": ""nceUHEe..."", ""proof_of_work_nonce"":  ""00000...""}");

Examples

netezos's People

Contributors

groxan avatar dmirgaleev avatar

Watchers

James Cloos 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.