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/custom-transactions

v0.6.3

Published

The npm custom transaction library for the DeFIChain Wizard

Downloads

28

Readme

DeFiChain Wizard Custom Transaction Library

This library can be used to send and retrieve custom (RAW) transactions from the DeFiChain.

Installation

npm i @defichainwizard/custom-transactions

Basic Usage

You can import the objects to use like this:

import {
  Transaction,
  TransactionConfig,
  CustomMessage,
} from "@defichainwizard/custom-transactions";

Create a transaction object

We will use this object in the next examples.

// The object properties are mandatory and enforced by typescript
const config: TransactionConfig = {
  client: this.client, // your whale api client
  account: this.account // your whale wallet account
  network: this.network, // the chosen network (e.g. mainnet)
  passphrase: this.passphrase // the passphrase as string array
};

// Create the transaction (it will automatically compress and encrypt the message)
const transaction = new Transaction(config);

Send a custom transaction

The message to send must be of type CustomMessage.

// Create your message to be sent
const message: CustomMessage = {
  version: "1.0",
  vaultId: "dsafasdfasdfasdfasd",
  pause: 0,
  compounding: {
    threshold: 1,
    mode: 1,
    token: "DFI",
  },
  poolpairs: {},
  rules: { keepMinRatio: 150, keepMaxRatio: 160 },
};

// Send the transaction
const txId = await transaction.send(message);

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/

Send a version message to the blockchain

In order to allow the frontend to see what version is installed on the backend, the backend must send a version message to the blockchain every time it starts up.

// Create your message to be sent
const versionMessage: Version = {
  version: "1.0"
};

// Send the transaction
const txId = await transaction.send(message);

Convert the extracted message from the transaction

This is needed if you have received a transaction from the blockchain. You can easily pass the extracted string to this function and it will return the CustomMessage object (decompressed and decrypted).

The compressed and encrypted message pretty much looks like this:

WzTxU2FsdGVkX193BZ6NqtpjOSJP4GTQDYEDHSUmbbMdhQNfcV9NQCjrzoGWL2QF8mW6D+NR9sKDpqu3K/BhE4kPuvnEeA5RSJ8+kgvCL8TVxtVgGC0tHr1DTBlccpk4BSV6Iv5d0g84TAvKqD9VKfaygY39R9umrHxxGTQ1MIj8yMxpbsKigGNarch9TzJuqLoPF5zJD2+y5dDBZgCPOsVqxKTrqjQe8KDwE0ibgXhPtDstYsGNw1DeLhWK2RG+i2U2zof1zTvvQMKb/+bs3yyH1qhvpdRDQNAiDDCii5XZir75588bUIlo4OkIbMuPiCtb8vLU79dc5O5/xG76vWw0dQzLyFq6MeJk6pNhC7vCRfuas/ENr58Rq4AHCADl2DJy
// get the CustomMessage from the passed string.
const customMessage = transaction.getCustomMessage(theStringFromAbove);

Find the latest wizard transaction on the blockchain

const config: BlockScannerConfig = {
    client: await myWallet.getClient(),
    address: await myWallet.getAddress(),
    lastConfigBlock: 2076745 // the block which contained the last wizard transaction
  };

  const bs = new BlockScanner(config);

This code returns a TransactionMessage object that will look like this:

{
  "blockTime": 2076745,
  "message": "6a004d8401577a5478553...451694f5030",
  "lastConfigBlock": 2076747
}

:warning: *This function can return UNDEFINED: If there is no config found, it will return undefined.