Nolus Docs
TypeScript SDK

Getting started

Use nolus.js to read protocol state and submit transactions.

nolus.js is the official TypeScript SDK for the Nolus Protocol. It abstracts the CosmWasm contract interactions and IBC logic behind typed clients so applications can quote, open, monitor, and repay leveraged positions without dealing with raw CosmJS wire formats.

Modules

  • client - connects to the chain via Tendermint RPC.
  • wallet - wallet abstraction over CosmJS OfflineSigner.
  • contracts - typed clients for Lease, Leaser, LPP, Oracle, Treasury.
  • utils - asset parsing, denom formatting, key generation.
  • constants - chain defaults (bech32 prefix, gas config).

Install

npm install @nolus/nolusjs
# or
yarn add @nolus/nolusjs

Prerequisites

Initialize the client

import { NolusClient } from '@nolus/nolusjs';

NolusClient.setInstance(tendermintRpc);

Set up a wallet

Generate a mnemonic, derive a key, wrap it in a DirectSecp256k1Wallet, then get a Nolus offline signer:

import {
  ChainConstants,
  KeyUtils,
  nolusOfflineSigner,
} from '@nolus/nolusjs';
import { DirectSecp256k1Wallet, makeCosmoshubPath } from '@cosmjs/proto-signing';

const mnemonic = KeyUtils.generateMnemonic();
const path = [0].map(makeCosmoshubPath)[0];
const privateKey = await KeyUtils.getPrivateKeyFromMnemonic(mnemonic, path);

const offlineSigner = await DirectSecp256k1Wallet.fromKey(
  privateKey,
  ChainConstants.BECH32_PREFIX_ACC_ADDR,
);

const nolusWallet = await nolusOfflineSigner(offlineSigner);
nolusWallet.useAccount();

Talk to the contracts

Each contract class wraps read and write access to a CosmWasm contract. They take a CosmWasm client and a contract address:

import { NolusContracts } from '@nolus/nolusjs';

const cosm = await NolusClient.getInstance().getCosmWasmClient();

const oracle   = new NolusContracts.Oracle(cosm,   oracleAddress);
const leaser   = new NolusContracts.Leaser(cosm,   leaserAddress);
const lease    = new NolusContracts.Lease(cosm,    leaseAddress);
const lpp      = new NolusContracts.Lpp(cosm,      lppAddress);
const treasury = new NolusContracts.Treasury(cosm, treasuryAddress);

Where next

On this page