# @defichainwizard/custom-transactions

> The npm custom transaction library for the DeFIChain Wizard

Latest version **0.6.3** (published 2022-09-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @defichainwizard/custom-transactions
pnpm add @defichainwizard/custom-transactions
yarn add @defichainwizard/custom-transactions
bun add @defichainwizard/custom-transactions
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.3 |
| Published | 2022-09-14 |
| First published | 2022-06-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 81.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | DeFiChain Wizard |
| Maintainers | shogoki, mastixmc |
| Keywords | defichain, defichainwizard |

## Links

- npm: https://www.npmjs.com/package/@defichainwizard/custom-transactions
- Repository: https://github.com/DeFiChain-Wizard/custom-transaction-library
- Homepage: https://github.com/DeFiChain-Wizard/custom-transaction-library#readme
- Issues: https://github.com/DeFiChain-Wizard/custom-transaction-library/issues
- npm.io page: https://npm.io/package/@defichainwizard/custom-transactions

## Dependencies (12)

- [crypto-js](https://npm.io/package/crypto-js.md) ^4.1.1
- [jest-config](https://npm.io/package/jest-config.md) ^28.1.3
- [@types/crypto-js](https://npm.io/package/@types/crypto-js.md) ^4.1.1
- [async-await-retry](https://npm.io/package/async-await-retry.md) ^2.0.0
- [@typescript-eslint/parser](https://npm.io/package/@typescript-eslint/parser.md) ^5.30.7
- [@defichain/whale-api-client](https://npm.io/package/@defichain/whale-api-client.md) 2.54.1
- [@defichain/whale-api-wallet](https://npm.io/package/@defichain/whale-api-wallet.md) 2.54.1
- [@defichain/jellyfish-network](https://npm.io/package/@defichain/jellyfish-network.md) 2.54.1
- [@defichain/jellyfish-api-core](https://npm.io/package/@defichain/jellyfish-api-core.md) ^2.54.1
- [@defichainwizard/custom-logging](https://npm.io/package/@defichainwizard/custom-logging.md) latest
- [@defichain/jellyfish-transaction](https://npm.io/package/@defichain/jellyfish-transaction.md) ^2.54.1
- [@defichain/jellyfish-transaction-builder](https://npm.io/package/@defichain/jellyfish-transaction-builder.md) ^2.54.1

## Recent versions

- 0.6.3 (latest) — 2022-09-14
- 0.6.2 — 2022-09-03
- 0.5.13 — 2022-08-25
- 0.5.12 — 2022-08-25
- 0.5.11 — 2022-08-09
- 0.5.10 — 2022-08-08
- 0.5.9 — 2022-08-07
- 0.5.8 — 2022-07-29
- 0.5.7 — 2022-07-29
- 0.5.6 — 2022-07-27
- 0.5.5 — 2022-07-26
- 0.5.3 — 2022-07-26
- 0.5.4 — 2022-07-25
- 0.5.2 — 2022-07-24
- 0.5.0 — 2022-07-24
- … 16 more at https://npm.io/package/@defichainwizard/custom-transactions/versions

## 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:

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

## Create a transaction object

We will use this object in the next examples.

```ts
// 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`.

```ts
// 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.

```ts
// 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
```

```ts
// get the CustomMessage from the passed string.
const customMessage = transaction.getCustomMessage(theStringFromAbove);
```

## Find the latest wizard transaction on the blockchain

```ts
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:

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

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

---
_Source: https://npm.io/package/@defichainwizard/custom-transactions · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
