Options
All
  • Public
  • Public/Protected
  • All
Menu

Package helpers

@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({
  cellOutput: {
    capacity: "0x174876e800",
    lock: {
      args: "0x36c329ed630d6ce750712a477543672adab57f4c",
      codeHash:
        "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
      hashType: "type",
    },
    type: null,
  },
  data: "0x",
  blockHash: null,
  blockNumber: null,
  outPoint: null,
})

// result will be 6100000000n shannons.

// Use `generateAddress` to get address from lock script.
const address = generateAddress({
  codeHash:
    "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
  hashType: "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({
  codeHash:
    "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
  hashType: "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)

Index

Type aliases

TransactionSkeletonType

TransactionSkeletonType: Record<TransactionSkeletonInterface> & Readonly<TransactionSkeletonInterface>

TransactionSkeletonType

TransactionSkeletonType: Record<TransactionSkeletonInterface> & Readonly<TransactionSkeletonInterface>

Variables

Const ADDRESS_FORMAT_FULL

ADDRESS_FORMAT_FULL: 0 = 0

full version identifies the hashType

Const ADDRESS_FORMAT_FULL

ADDRESS_FORMAT_FULL: 0 = 0

full version identifies the hashType

Const ADDRESS_FORMAT_FULLDATA

ADDRESS_FORMAT_FULLDATA: 2 = 2
deprecated

full version with hashType = "Data", deprecated

Const ADDRESS_FORMAT_FULLDATA

ADDRESS_FORMAT_FULLDATA: 2 = 2
deprecated

full version with hashType = "Data", deprecated

Const ADDRESS_FORMAT_FULLTYPE

ADDRESS_FORMAT_FULLTYPE: 4 = 4
deprecated

full version with hashType = "Type", deprecated

Const ADDRESS_FORMAT_FULLTYPE

ADDRESS_FORMAT_FULLTYPE: 4 = 4
deprecated

full version with hashType = "Type", deprecated

Const ADDRESS_FORMAT_SHORT

ADDRESS_FORMAT_SHORT: 1 = 1
deprecated

short version for locks with popular codeHash, deprecated

Const ADDRESS_FORMAT_SHORT

ADDRESS_FORMAT_SHORT: 1 = 1
deprecated

short version for locks with popular codeHash, deprecated

Const BECH32_LIMIT

BECH32_LIMIT: 1023 = 1023

Const BECH32_LIMIT

BECH32_LIMIT: 1023 = 1023

Let HAS_WARNED_FOR_DEPRECATED_ADDRESS

HAS_WARNED_FOR_DEPRECATED_ADDRESS: boolean = false

Const TransactionSkeleton

TransactionSkeleton: Factory<TransactionSkeletonInterface>

Const TransactionSkeleton

TransactionSkeleton: Factory<TransactionSkeletonInterface> = Record<TransactionSkeletonInterface>({cellProvider: null,cellDeps: List(),headerDeps: List(),inputs: List(),outputs: List(),witnesses: List(),fixedEntries: List(),signingEntries: List(),inputSinces: ImmutableMap(),})

Const addressToScript

addressToScript: typeof parseAddress

Const addressToScript

addressToScript: parseAddress = parseAddress

bytify

bytify: bytify

hexify

hexify: hexify

Const scriptToAddress

scriptToAddress: typeof generateAddress
deprecated

please migrate to encodeToAddress, the short format address will be removed in the future

Const scriptToAddress

scriptToAddress: generateAddress = generateAddress
deprecated

please migrate to encodeToAddress, the short format address will be removed in the future

Functions

byteArrayToHex

  • Parameters

    • a: number[]

    Returns HexString

byteArrayToHex

  • Parameters

    • a: number[]

    Returns HexString

createTransactionFromSkeleton

  • Parameters

    • txSkeleton: TransactionSkeletonType
    • Optional __namedParameters: { validate: undefined | false | true }
      • validate: undefined | false | true

    Returns Transaction

createTransactionFromSkeleton

  • Parameters

    • txSkeleton: TransactionSkeletonType
    • Default value __namedParameters: { validate: boolean } = {}
      • validate: boolean

    Returns Transaction

encodeToAddress

  • Parameters

    • script: Script
    • Optional __namedParameters: { config: undefined | Config }

    Returns Address

encodeToAddress

  • Parameters

    • script: Script
    • Default value __namedParameters: { config: undefined | Config } = {}

    Returns Address

generateAddress

  • deprecated

    please migrate to encodeToAddress, the short format address will be removed in the future

    Parameters

    • script: Script
    • Optional __namedParameters: { config: undefined | Config }

    Returns Address

generateAddress

  • deprecated

    please migrate to encodeToAddress, the short format address will be removed in the future

    Parameters

    • script: Script
    • Default value __namedParameters: { config: undefined | Config } = {}

    Returns Address

generatePredefinedAddress

  • generatePredefinedAddress(args: HexString, scriptType: string, __namedParameters?: { config: undefined | Config }): Address
  • Parameters

    • args: HexString
    • scriptType: string
    • Default value __namedParameters: { config: undefined | Config } = {}

    Returns Address

generateSecp256k1Blake160Address

  • generateSecp256k1Blake160Address(args: HexString, __namedParameters?: { config: undefined | Config }): Address
  • Parameters

    Returns Address

generateSecp256k1Blake160Address

  • generateSecp256k1Blake160Address(args: HexString, __namedParameters?: { config: undefined | Config }): Address
  • Parameters

    • args: HexString
    • Default value __namedParameters: { config: undefined | Config } = {}

    Returns Address

generateSecp256k1Blake160MultisigAddress

  • generateSecp256k1Blake160MultisigAddress(args: HexString, __namedParameters?: { config: undefined | Config }): Address
  • Parameters

    Returns Address

generateSecp256k1Blake160MultisigAddress

  • generateSecp256k1Blake160MultisigAddress(args: HexString, __namedParameters?: { config: undefined | Config }): Address
  • Parameters

    • args: HexString
    • Default value __namedParameters: { config: undefined | Config } = {}

    Returns Address

hexToByteArray

  • Parameters

    Returns number[]

hexToByteArray

  • Parameters

    Returns number[]

locateCellDep

  • locateCellDep(script: Script, __namedParameters?: { config: undefined | Config }): CellDep | null
  • Parameters

    • script: Script
    • Optional __namedParameters: { config: undefined | Config }

    Returns CellDep | null

locateCellDep

  • locateCellDep(script: Script, __namedParameters?: { config: undefined | Config }): CellDep | null
  • Parameters

    • script: Script
    • Default value __namedParameters: { config: undefined | Config } = {}

    Returns CellDep | null

minimalCellCapacity

  • minimalCellCapacity(fullCell: Cell, __namedParameters?: { validate: undefined | false | true }): bigint
  • Parameters

    • fullCell: Cell
    • Optional __namedParameters: { validate: undefined | false | true }
      • validate: undefined | false | true

    Returns bigint

minimalCellCapacity

  • minimalCellCapacity(fullCell: Cell, __namedParameters?: { validate: boolean }): bigint
  • Parameters

    • fullCell: Cell
    • Default value __namedParameters: { validate: boolean } = {}
      • validate: boolean

    Returns bigint

minimalCellCapacityCompatible

  • minimalCellCapacityCompatible(fullCell: Cell, __namedParameters?: { validate: undefined | false | true }): BI
  • Parameters

    • fullCell: Cell
    • Optional __namedParameters: { validate: undefined | false | true }
      • validate: undefined | false | true

    Returns BI

minimalCellCapacityCompatible

  • minimalCellCapacityCompatible(fullCell: Cell, __namedParameters?: { validate: boolean }): BI
  • Parameters

    • fullCell: Cell
    • Default value __namedParameters: { validate: boolean } = {}
      • validate: boolean

    Returns BI

objectToTransactionSkeleton

objectToTransactionSkeleton

parseAddress

  • Parameters

    • address: Address
    • Optional __namedParameters: { config: undefined | Config }

    Returns Script

parseAddress

  • Parameters

    • address: Address
    • Default value __namedParameters: { config: undefined | Config } = {}

    Returns Script

parseDeprecatedCkb2019Address

  • parseDeprecatedCkb2019Address(address: string, __namedParameters: { config: undefined | Config }): Script
  • Parameters

    • address: string
    • __namedParameters: { config: undefined | Config }

    Returns Script

parseDeprecatedCkb2019Address

  • parseDeprecatedCkb2019Address(address: string, __namedParameters: { config: undefined | Config }): Script
  • Parameters

    • address: string
    • __namedParameters: { config: undefined | Config }

    Returns Script

parseFullFormatAddress

  • parseFullFormatAddress(address: Address, __namedParameters: { config: undefined | Config }): Script
  • Parameters

    • address: Address
    • __namedParameters: { config: undefined | Config }

    Returns Script

parseFullFormatAddress

  • parseFullFormatAddress(address: Address, __namedParameters: { config: undefined | Config }): Script
  • Parameters

    • address: Address
    • __namedParameters: { config: undefined | Config }

    Returns Script

sealTransaction

sealTransaction

transactionSkeletonToObject

transactionSkeletonToObject

Generated using TypeDoc