0.22.2 • Published 3 days ago

@ckb-lumos/helpers v0.22.2

Weekly downloads
30
License
MIT
Repository
github
Last release
3 days ago

@ckb-lumos/helpers

Helper utilities for working with CKB transactions from lumos.

The difference between this and @ckb-lumos/base, is that @ckb-lumos/base contains only core definitions, while this module contains utilities used in a framework sense. One example is: you can pretty much use @ckb-lumos/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

const { minimalCellCapacity, generateAddress, parseAddress } = require("@ckb-lumos/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("@ckb-lumos/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)
0.22.2

26 days ago

0.22.1

1 month ago

0.22.0

1 month ago

0.22.0-next.5

2 months ago

0.22.0-next.4

4 months ago

0.22.0-next.3

4 months ago

0.22.0-next.2

4 months ago

0.22.0-next.1

5 months ago

0.22.0-next.0

5 months ago

0.21.1

5 months ago

0.21.0

5 months ago

0.20.0

10 months ago

0.21.0-next.0

9 months ago

0.21.0-next.1

7 months ago

0.21.0-next.2

6 months ago

0.21.0-next.3

6 months ago

0.20.0-alpha.3

12 months ago

0.20.0-alpha.2

1 year ago

0.19.0

2 years ago

0.20.0-alpha.0

1 year ago

0.20.0-alpha.1

1 year ago

0.19.0-beta.0

2 years ago

0.19.0-alpha.3

2 years ago

0.19.0-alpha.2

2 years ago

0.19.0-alpha.1

2 years ago

0.17.0

2 years ago

0.19.0-alpha.0

2 years ago

0.18.0

2 years ago

0.18.0-rc7

2 years ago

0.18.0-rc6

2 years ago

0.17.0-rc9

2 years ago

0.17.0-rc10

2 years ago

0.17.0-rc7

2 years ago

0.17.0-rc6

2 years ago

0.18.0-rc5

2 years ago

0.18.0-rc3

2 years ago

0.18.0-rc4

2 years ago

0.17.0-rc8

2 years ago

0.18.0-rc2

2 years ago

0.18.0-rc1

3 years ago

0.17.0-rc5

3 years ago

0.16.0

3 years ago

0.15.0

3 years ago

0.14.2-rc6

3 years ago

0.14.2-rc5

3 years ago

0.14.2-rc4

3 years ago

0.14.2-rc3

3 years ago

0.14.2-rc2

3 years ago

0.14.2-rc1

3 years ago

0.14.1

3 years ago

0.14.0

3 years ago

0.13.3

3 years ago

0.13.2

3 years ago

0.13.1

4 years ago

0.13.0

4 years ago

0.12.0

4 years ago

0.11.0-rc2

4 years ago

0.11.0-rc1

4 years ago

0.10.0

4 years ago

0.9.0

4 years ago

0.8.0

4 years ago

0.7.4

4 years ago

0.7.3

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.0

4 years ago

0.5.4

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.8

4 years ago

0.4.7

4 years ago

0.4.5

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.1

4 years ago

0.4.2

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.4

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago