8000 GitHub - Olexandr88/nil.js at ssz-fix
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Olexandr88/nil.js

 
 

Repository files navigation

Nil.js


=nil; Foundation Typescript client to interact with the Nil network.

Table of Contents

Installation

npm install @nilfoundation/niljs

Getting started

There are two clients in the library to interact with the Nil network. The first one is the PublicClient class, which is used to interact with the Nil network without the need for a private key. It is used to get information about the network, such as block number and block hash.

import { PublicClient } from "@nilfoundation/niljs";

const endpoint = "https://localhost:8259";
const publicClient = new PublicClient({ endpoint });

publicClient.getBalance("your_address").then((balance) => {
  console.log(balance);
});

The second one is the WalletClient class, which is used to interact with the Nil network with a private key. It is used to send messages to the network.

import { WalletClient } from "@nilfoundation/niljs";

const endpoint = "https://localhost:8259";
const walletClient = new WalletClient({ endpoint });

walletClient
  .sendMessage({
    from: "your_address",
    to: "recipient_address",
    amount: 100,
  })
  .then((tx) => {
    console.log(tx);
  });

Initialize the Signer with the private key of the account you want to use to sign messages.

import { Signer } from "@nilfoundation/niljs";

const privateKey = "your_private_key";
const signer = new Signer({ privateKey });

signer.sign(new Uint8Array(32));

You can also sign messages automatically by passing the Signer instance to the WalletClient.

import { WalletClient } from "@nilfoundation/niljs";
import { Signer } from "@nilfoundation/niljs";

const endpoint = "https://localhost:8259";
const privateKey = "your_private_key";

const signer = new Signer({ privateKey });
const walletClient = new WalletClient({ endpoint, signer });

Licence

MIT

About

Client-side typescript library for =nil;

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 97.8%
  • JavaScript 1.3%
  • Solidity 0.9%
0