npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-nil

v0.1.0

Published

nil-chain client side utils

Downloads

248

Readme

nil client utils

License npm version

This package is intended to simplify interaction with Nil blockchain during its DevNet phase and will probably be deprecated with the evolution of Nil.js

Table of Contents


Features

  • Type-Safe Interactions: Leverages TypeScript's strong typing to ensure reliable and predictable blockchain interactions.
  • Smart Contract Deployment: Easily deploy new smart contracts with customizable parameters.
  • Message Handling: Send and manage messages with comprehensive receipt processing.
  • Currency Management: Create and approve currencies within your wallet.

Installation

Ensure you have Yarn installed. Then, install the package using Yarn:

yarn add simple-nil

Peer Dependencies

This package relies on the following peer dependencies. Ensure they are installed in your project:

Install them using Yarn:

yarn add @nilfoundation/niljs viem

Getting Started

XClient

The XClient class manages blockchain communications, handles external calls, and interacts with the underlying blockchain network. It serves as the bridge between your wallet and the blockchain, facilitating message sending and currency management.

Initialization

import { XClient } from "simple-nil";

const client = new XClient({
  shardId: 1,
  rpc: "https://rpc.endpoint.com",
  signerOrPrivateKey:
    "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
});

Connecting with a different config

If you need to connect the client with a different signer (private key), shardId or rpc, you can use the connect method:

const newSignerPrivateKey =
  "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";

const newClient = client.connect({
  signerOrPrivateKey: newSignerPrivateKey
});

XWallet

The XWallet class provides functionalities to manage and interact with an XWallet instance on the blockchain. It allows for deploying contracts, approving spenders, creating currencies, and more.

Initialization

import { XWallet } from "simple-nil";
import { XWalletConfig } from "simple-nil/types";

const wallet = await XWallet.init({
  address: "0x1234567890abcdef1234567890abcdef12345678",
  rpc: "https://rpc.endpoint.com",
  signerOrPrivateKey:
    "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
  shardId: 1,
});
console.log("Initialized XWallet:", wallet.address);

Self-deployment

import { XWallet, XClient } from "simple-nil";

const deployedWallet = await XWallet.deploy({
  shardId: 1,
  rpc: "https://rpc.endpoint.com",
  signerOrPrivateKey:
    "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
});
console.log("Deployed XWallet Address:", deployedWallet.address);

XContract

The XContract class provides functionalities to interact with deployed smart contracts. It allows connecting to existing contracts, deploying new ones, and invoking contract methods.

Connecting to an Existing Contract

import { XContract, XWallet } from "simple-nil";

// Assuming you have an initialized XWallet instance
const wallet = await XWallet.init(options);

// Define the ABI of your contract
const abi = [
  /* Your Contract ABI */
];

// Address of the deployed contract
const contractAddress = "0xabcdef1234567890abcdef1234567890abcdef12";

// Connect to the contract
const contract = XContract.connect(wallet, abi, contractAddress);

Deploying a New Contract

import { XContract, XWallet } from "simple-nil";

// Assuming you have an initialized XWallet instance
const wallet = await XWallet.init(options);

// Define the ABI and bytecode of your contract
const artifact = {
  abi: [
    /* Your Contract ABI */
  ],
  bytecode: "0x6001600101", // Replace with your contract's bytecode
};

// Constructor arguments for your contract
const args = [
  /* Constructor Arguments */
];

const shardId = 1;
const salt = BigInt(Date.now());

const newContract = await XContract.deploy(
  wallet,
  artifact,
  args,
  shardId,
  salt,
);
console.log("Deployed Contract Address:", newContract.address);