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

@defichainwizard/core

v0.2.5

Published

The npm core library for the frontend

Downloads

43

Readme

DeFiChain Wizard Core Library

This library can be used to access and retrieve certain wallet data that should be available from within the UI.

It can also send a custom transaction to the DeFiChain.

Installation

npm i @defichainwizard/core

What can be done with this library

  • Store and read the seed phrase (encrypted)
  • Store and read the wallet address
  • Store and read the vault address
  • Store and read the Blockhain configuration
  • Send a custom transaction to the DeFiChain Blockchain
  • Read basic Blockchain-Data
  • Read data from your wallet (e.g. tokens, ratio,...)

Basic Usage

You can import the classes to use like this:

import { Wallet, Seed } from "@defichainwizard/core";

Create the wallet and get some data

const wallet = await Wallet.build(myDFIAddress)

// returns the current UTXO balance
const balance = await wallet.getUTXOBalance();

// returns all active vaults
const vaults = await wallet.getVaults();

// returns a specific vault
const someVault = await wallet.getVault(myVaultId);

// get all tokens (incl. liquidity mining) from the wallet
const tokens = await wallet.listTokens();

// specify a certain vault to be used
await wallet.setCurrentVault(someVaultId);

// returns the current vault to be used
const vault = await wallet.getCurrentVault();

Get list of addresses

If you don't have the address yet or you want to get a list of all addresses of your account, you could also ask for a list of addresses first:

// all you need is your seed and your passphrase for the seed decryption
const seed = await Seed.build(mySeed, myPassphrase);

// will return the list of addresses as string array
const listOfAddresses = await Wallet.getAvailableAddresses(seed, myPassphrase);

Get some data from the vault

The vault return data is aligned with the Jellyfish API response, so you can grab the data the same way.

See: https://jellyfish.defichain.com/ocean/address#response-3

// returns a specific vault
const someVault = await wallet.getVault(myVaultId);

// get the minimum collateral ratio (e.g. 150)
const minimumCollateralRatio = someVault.loanScheme.minColRatio;

// get the current collateral ratio (e.g. 167)
const collateralRatio = someVault.collateralRatio;

Create the seed

The seed is only needed when you want to send a transaction. It will be encrypted and stored. In the browser NPM version, it will be stored in the local storage.

This API only support addresses from the light wallet, which means that you will have to provide the 24 words.


// mySeed can be an array of string (24 words) or the already encrypted string
const mySeed = await Seed.build(mySeed, myPassword);

// now we need the seed for some reason:

// returns the 24 word array as provided
const seedArray = await mySeed.asArray(myPassword);

// returns the seed as comma-separated string.
const seedString = await mySeed.asString(myPassword);

// no password for decryption needed
const seedEncrypted = await mySeed.asEncrypted();

Grabbing the encrypted seed from storage

// returns a new Seed object based on the currently stored encrypted string.

const mySeed = Seed.getSeedFromEncryptedString();

Send a custom transaction

Now that we have the wallet and the seed in place, let's send a custom transaction.

// sends a custom transaction with a custom message
const transactionId = await wallet.sendTransaction(
  "My custom message",
  seedEncrypted,
  myPassword
);

If you want to see the custom (RAW) transaction just use the following page and enter either the returned transaction ID or search for your wallet address:

https://chainz.cryptoid.info/dfi/