Options
All
  • Public
  • Public/Protected
  • All
Menu

Package hd-cache

@ckb-lumos/hd-cache

HD Cache manager for lumos.

Usage

const {
  CacheManager,
  CellCollector,
  CellCollectorWithQueryOptions,
  getBalance,
} = require("@ckb-lumos/hd-cache");
const { Indexer } = require("@ckb-lumos/ckb-indexer");
const indexer = new Indexer("http://localhost:8114");
const cacheManger = CacheManager.loadFromKeystore(
  indexer,
  "You keystore path",
  "You password"
);
// start to sync cache from indexer
cacheManager.startForever();

// if your keystore is from ckb-cli or you set needMasterPublicKey to true, you can get you master public key info by
cacheManager.getMasterPublicKeyInfo(); // ckb-cli using this key by default

// now you can using following methods
cacheManager.getNextReceivingPublicKeyInfo();
cacheManager.getNextChangePublicKeyInfo();

// or collect cells  by CellCollectors
const cellCollector = new CellCollector(cacheManager);
// or with queryOptions
const cellCollector = new CellCollectorWithQueryOptions(
  new CellCollector(cacheManger),
  queryOptions
);

for await (const cell of cellCollector.collect()) {
  console.log(cell);
}

// get HD wallet balance
await getBalance(cellCollector);

how to quickly get transactionCollector

CKBIndexerTransactionCollector.asBaseTransactionCollector helps you to get a transactionCollector instance.

const CKB_URL = "http://127.0.0.1:8118/rpc";
const CKB_INDEXER_URL = "ttp://127.0.0.1:8120";
const indexer = new CkbIndexer(CKB_INDEXER_URL, CKB_URL);

const ExtendCollector = CKBIndexerTransactionCollector.asBaseTransactionCollector(
  nodeUri
);

const cacheManager = CacheManager.fromMnemonic(
  indexer,
  mnemonic,
  getDefaultInfos(),
  {
    TransactionCollector: ExtendCollector,
    rpc,
  }
);

Index

Variables

isCellMatchQueryOptions

isCellMatchQueryOptions: isCellMatchQueryOptions

mnemonicToSeedSync

mnemonicToSeedSync: mnemonicToSeedSync

publicKeyToBlake160

publicKeyToBlake160: publicKeyToBlake160

Functions

assertsNonNil

  • assertsNonNil<T>(value: T, name: string): assertsvalue is NonNullable<T>
  • Type parameters

    • T

    Parameters

    • value: T
    • name: string

    Returns assertsvalue is NonNullable<T>

defaultLogger

  • defaultLogger(level: string, message: string): void
  • Parameters

    • level: string
    • message: string

    Returns void

getBalance

  • getBalance(cellCollector: CellCollectorInterface): Promise<HexString>
  • Parameters

    • cellCollector: CellCollectorInterface

    Returns Promise<HexString>

getBalance

  • getBalance(cellCollector: CellCollectorInterface): Promise<HexString>
  • Parameters

    • cellCollector: CellCollectorInterface

    Returns Promise<HexString>

getDefaultInfos

getDefaultInfos

  • Parameters

    • Default value config: Config | undefined = undefined

    Returns LockScriptMappingInfo[]

lockScriptMatch

  • lockScriptMatch(script: Script, otherScript: Script): boolean
  • Parameters

    Returns boolean

outputToCell

publicKeyToMultisigArgs

  • Parameters

    Returns HexString

publicKeyToMultisigArgs

  • Parameters

    Returns HexString

serializeOutPoint

  • serializeOutPoint(outPoint: OutPoint): string
  • Parameters

    Returns string

serializeOutPoint

  • serializeOutPoint(outPoint: OutPoint): string
  • Parameters

    Returns string

Generated using TypeDoc