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 CosmJSOfflineSigner.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/nolusjsPrerequisites
- Node.js >= 16
- Access to a Nolus RPC node - see RPC endpoints.
- Contract addresses for Leaser, Lease, Oracle, LPP, and Treasury - published
per network in
nolus-networks. - Familiarity with CosmJS and the Cosmos SDK.
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);