# @yadomi29/helpers

> Helper functions for working with CKB

Latest version **0.24.0-next.0** (published 2022-08-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @yadomi29/helpers
pnpm add @yadomi29/helpers
yarn add @yadomi29/helpers
bun add @yadomi29/helpers
```

## 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.24.0-next.0 |
| Published | 2022-08-10 |
| First published | 2022-08-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12.0.0 |
| Dependencies | 6 |
| Unpacked size | 69.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 66 |
| Author | Xuejie Xiao |
| Maintainers | yadomi29 |

## Links

- npm: https://www.npmjs.com/package/@yadomi29/helpers
- Repository: https://github.com/nervosnetwork/lumos
- Homepage: https://github.com/nervosnetwork/lumos#readme
- Issues: https://github.com/nervosnetwork/lumos/issues
- npm.io page: https://npm.io/package/@yadomi29/helpers

## Dependencies (6)

- [bech32](https://npm.io/package/bech32.md) ^2.0.0
- [immutable](https://npm.io/package/immutable.md) ^4.0.0-rc.12
- [@yadomi29/bi](https://npm.io/package/@yadomi29/bi.md) ^0.24.0-next.0
- [@yadomi29/base](https://npm.io/package/@yadomi29/base.md) ^0.24.0-next.0
- [@yadomi29/toolkit](https://npm.io/package/@yadomi29/toolkit.md) ^0.24.0-next.0
- [@yadomi29/config-manager](https://npm.io/package/@yadomi29/config-manager.md) ^0.24.0-next.0

## Recent versions

- 0.24.0-next.0 (latest) — 2022-08-10
- 0.27.0-alpha.0 (next) — 2022-08-10
- 0.23.0 — 2022-08-10
- 0.22.0 — 2022-08-10

## README

# `@yadomi29/helpers`

Helper utilities for working with CKB transactions from lumos.

The difference between this and `@yadomi29/base`, is that `@yadomi29/base` contains only core definitions, while this module contains utilities used in a framework sense. One example is: you can pretty much use `@yadomi29/base` as a standalone library, while this library integrates more with `config` module so it knows whether the framework is running under testnet, or mainnet environment.

## Usage

```javascript
const { minimalCellCapacity, generateAddress, parseAddress } = require("@yadomi29/helpers")

// Get cell minimal capacity.
const result = minimalCellCapacity({
  cell_output: {
    capacity: "0x174876e800",
    lock: {
      args: "0x36c329ed630d6ce750712a477543672adab57f4c",
      code_hash:
        "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
      hash_type: "type",
    },
    type: null,
  },
  data: "0x",
  block_hash: null,
  block_number: null,
  out_point: null,
})

// result will be 6100000000n shannons.

// Use `generateAddress` to get address from lock script.
const address = generateAddress({
  code_hash:
    "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
  hash_type: "type",
  args: "0x36c329ed630d6ce750712a477543672adab57f4c",
})

// Then you will get mainnet address "ckb1qyqrdsefa43s6m882pcj53m4gdnj4k440axqdt9rtd", or you can generate testnet address by
const { predefined } = require("@yadomi29/config-manager")

const address = generateAddress({
  code_hash:
    "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
  hash_type: "type",
  args: "0x36c329ed630d6ce750712a477543672adab57f4c",
}, { config: predefined.AGGRON4 })

// Will get testnet address "ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83".

// Use `parseAddress` to get lock script from an address.
const script = parseAddress("ckb1qyqrdsefa43s6m882pcj53m4gdnj4k440axqdt9rtd")

// TransactionSkeleton <=> Object

// Convert TransactionSkeleton to js object
const obj = transactionSkeletonToObject(txSkeleton)
// then your can write to json file
fs.writeFileSync("your file", JSON.stringify(obj))

// Or convert js object to TransactionSkeleton
// If your object is from json file, make sure `cellProvider` is working properly.
const txSkeleton = objectToTransactionSkeleton(obj)
```

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