=nil; Foundation Typescript client to interact with the Nil network.
npm install @nilfoundation/niljs
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 });