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

@nibiruchain/nibijs

v5.0.2

Published

The TypeScript SDK for the Nibiru blockchain.

Downloads

643

Readme

The NibiJS (@nibiruchain/nibijs) package makes it possible to interact with Nibiru from a Node.js or browser environment. nibijs provides simple abstractions for core data structures, serialization, key management, API requests, and the submission of transactions.

The nibijs source code can be found in the src directory.

Table of Contents

To learn more about Nibiru, see nibiru.fi/docs


Installation

@nibiruchain/nibijs is available on the npm registry.

npm install @nibiruchain/nibijs # or yarn add

Usage

The entrypoint for nibijs is the Sdk object, which is meant to mimic the root of a command line interface. It can be used for both queries and transactions.

Example: Creating a wallet

import { newRandomWallet } from "@nibiruchain/nibijs"

// Create a new Nibiru wallet
const wallet = await newRandomWallet()
const [{ address }] = await wallet.getAccounts()

// Save the mnemonic somewhere to re-use the account
console.log("mnemonic: ", wallet.mnemonic)
console.log("address: ", address)

Example: Querying

import { NibiruQuerier, Testnet } from "@nibiruchain/nibijs"

export const CHAIN = Testnet(2)
const querier = await NibiruQuerier.connect(CHAIN.endptTm)

// Query balances
const exampleAddress = "nibi17dz4cdw5fmm2cxd4ht9xvjmpw3ycmpkpcc6js9"
const balances = await querier.getAllBalances(exampleAddress)
console.log("balances: %o", balances)

// Query block
const blockHeight = 200000
const block = await querier.getBlock(blockHeight)
console.log("block: %o", block)

Example: Sending funds

import {
  NibiruTxClient,
  newSignerFromMnemonic,
  Testnet,
  NibiruQuerier,
} from "@nibiruchain/nibijs"
import { coins } from "@cosmjs/proto-signing"

export const CHAIN = Testnet(2)
const mnemonic = "your mnemonic here..."
const signer = await newSignerFromMnemonic(mnemonic)
const querier = await NibiruQuerier.connect(CHAIN.endptTm)
const txClient = await NibiruTxClient.connectWithSigner(CHAIN.endptTm, signer)
const [{ address: fromAddr }] = await signer.getAccounts()

// Check balance before sending tokens
const exampleAddress = "nibi1mzjkw9z5ugajxchl884y0c28lk2627hpuljuw4"
let balances = await querier.getAllBalances(exampleAddress)
console.log("balances: %o", balances)

const tokens = coins(5, "unibi")
const txResp = await txClient.sendTokens(
  fromAddr,
  exampleAddress,
  tokens,
  5000 // gas fee 5000 unibi
)
console.log(txResp)

// Execution could take several seconds
const delay = (ms) => new Promise((res) => setTimeout(res, ms))
await delay(10000)

// Check balance after send tokens
balances = await querier.getAllBalances(exampleAddress)
console.log("balances: %o", balances)

Codebase structure

| Directories of @nibiruchain/nibijs | Purpose/Utility | | :----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | common | home to several commonly needed types, constants and configurations such as Network. | | msg | Implements functions for creating messages (Msgs). These are objects that trigger state-transitions and get wrapped into transactions. | | query | For querying state via the consensus engine of a full-node and the application blockchain interface (ABCI). | | tx | For signing and to submitting transactions given a set of Msg objects. | | wallet | A simple wrapper around the Keplr wallet. This module will grow as support is added for other wallets (like MetaMask). |

@nibiruchain/protojs provides types generated from the protocol buffers of the Cosmos-SDK, Tendermint Core, and Nibiru Chain. For most use cases, it won't be necessary to interact with this layer.


Development Quick Start

  1. Install and use nvm.

    wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.6/install.sh | bash
    nvm use
  2. Install yarn.

    npm install -g yarn
  3. Then, install package dependencies. At the root of the repository, run

    yarn
  4. Initialize git submodules

    git submodule init
    git submodule update
  5. Lastly, compile the code in each package.

    yarn build

See HACKING.md for the full development guide. It includes instructions on:

  1. Running tests
  2. Generating code for the @nibiruchain/protojs package
  3. Generating documentation in HTML or Markdown from the comments of @nibiruchain/nibijs

🔓 License

This software is licensed under the MIT license. See LICENSE for full disclosure.

© 2023 Nibi, Inc.