======================== CODE SNIPPETS ======================== TITLE: Installing Dependencies and Starting Lumos Example (Shell) DESCRIPTION: These commands are used to install the necessary project dependencies and then execute the Lumos chained transfer example. `yarn install` or `npm install` fetches packages, while `yarn start` or `npm run start` runs the application. SOURCE: https://github.com/ckb-js/lumos/blob/develop/packages/transaction-manager/examples/chained-transfer-example/README.md#_snippet_0 LANGUAGE: sh CODE: ``` yarn install / npm install yarn start / npm run start ``` ---------------------------------------- TITLE: Building and Starting Lumos MetaMask Example DESCRIPTION: These commands are used to build the Lumos project, create a release, navigate into the specific 'omni-lock-metamask' example directory, and then start the example application. This sequence is a prerequisite for running the Lumos-MetaMask integration demonstration. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/omni-lock-metamask/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` npm run build npm run build-release cd examples/omni-lock-metamask npm start ``` ---------------------------------------- TITLE: Starting Next.js Development Server (Bash) DESCRIPTION: This snippet provides commands to initiate the Next.js development server using various package managers. Running one of these commands starts the application locally, making it accessible for development and testing, typically at `http://localhost:3000`. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/nextjs/README.md#_snippet_0 LANGUAGE: bash CODE: ``` npm run dev # or yarn dev # or pnpm dev # or bun dev ``` ---------------------------------------- TITLE: Quick Start for Docusaurus Website (Shell) DESCRIPTION: This shell script provides the necessary commands to quickly set up and run the Docusaurus 2 website locally. It first installs all project dependencies using `pnpm install` and then starts the development server with `pnpm start`. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/README.md#_snippet_0 LANGUAGE: sh CODE: ``` pnpm install pnpm start ``` ---------------------------------------- TITLE: Starting the SUDT Exchange Example Application (Bash) DESCRIPTION: This command initiates the local development server for the SUDT exchange example application. Running this command is a necessary prerequisite to access the web interface at http://localhost:1234 and proceed with issuing SUDT and exchanging it for CKB. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/exchange-sudt-for-ckb/README.md#_snippet_0 LANGUAGE: bash CODE: ``` npm start ``` ---------------------------------------- TITLE: Starting Lumos PW-Lock MetaMask Example DESCRIPTION: This snippet provides the necessary shell commands to navigate into the `pw-lock-metamask` example directory and initiate the application using npm. It assumes that the main Lumos project has been built prior to execution. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/pw-lock-metamask/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` cd examples/pw-lock-metamask npm start ``` ---------------------------------------- TITLE: Building and Running Omnilock Example with Lumos (Shell) DESCRIPTION: This snippet provides the command-line instructions to prepare and execute the Lumos Omnilock example. It involves building the main Lumos project, navigating into the specific example directory, and then starting the example application. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/omni-lock-secp256k1-blake160/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` npm run build cd examples/omni-lock-own-signature npm start ``` ---------------------------------------- TITLE: Installing Dependencies and Starting Lumos Project DESCRIPTION: This snippet provides the necessary commands to set up the Lumos project for the JoyID integration example. It involves installing project dependencies and then starting the application. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/joyid/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` pnpm install pnpm start ``` ---------------------------------------- TITLE: Building Production Bundle with Create React App (Shell) DESCRIPTION: This command builds the React application for production, optimizing and minifying the code into the `build` folder. The output is ready for deployment, with filenames including hashes for caching. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/create-react-app/README.md#_snippet_2 LANGUAGE: Shell CODE: ``` npm run build ``` ---------------------------------------- TITLE: Starting Development Server with Create React App (Shell) DESCRIPTION: This command runs the React application in development mode, typically opening it in a web browser at http://localhost:3000. It enables live reloading on code changes and displays lint errors in the console. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/create-react-app/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` npm start ``` ---------------------------------------- TITLE: Building Lumos Project (Shell) DESCRIPTION: This snippet provides the shell commands to clone the Lumos repository, navigate into its directory, install dependencies using pnpm, and build the project. It's a prerequisite for local development and testing. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/README.md#_snippet_0 LANGUAGE: sh CODE: ``` git clone https://github.com/ckb-js/lumos.git cd lumos pnpm install pnpm run build ``` ---------------------------------------- TITLE: Running Lumos Omnilock UniSat Example (Shell) DESCRIPTION: This snippet provides the shell commands required to set up and run the Lumos Omnilock UniSat example. It involves building the main Lumos project, navigating into the specific example directory, and then starting the application to demonstrate the integration. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/omni-lock-unisat/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` npm run build cd examples/omni-lock-unisat npm start ``` ---------------------------------------- TITLE: Ejecting Create React App Configuration (Shell) DESCRIPTION: This command removes the single build dependency from the project, copying all configuration files (webpack, Babel, ESLint, etc.) directly into the project. This provides full control over the build setup but is a one-way operation. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/create-react-app/README.md#_snippet_3 LANGUAGE: Shell CODE: ``` npm run eject ``` ---------------------------------------- TITLE: Setting up Local Verdaccio Registry (Shell) DESCRIPTION: This shell script installs Verdaccio globally, starts a local registry instance using a specified configuration file and port, and then configures npm to use this local registry with a fake authentication token. This setup is crucial for testing package publication workflows in a controlled local environment. SOURCE: https://github.com/ckb-js/lumos/blob/develop/devtools/README.md#_snippet_0 LANGUAGE: sh CODE: ``` npm install -g verdaccio verdaccio --config ./devtools/verdaccio.yaml --listen=4873 npm config set registry http://localhost:4873 npm config set //localhost:4873/:_authToken fake ``` ---------------------------------------- TITLE: Initializing Lumos Project with Bun DESCRIPTION: This snippet demonstrates how to set up a new project directory, initialize it using Bun, and install the `@ckb-lumos/lumos` library. It prepares the development environment for CKB interactions. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/00-tutorial-issue-and-transfer-xudt.md#_snippet_0 LANGUAGE: sh CODE: ``` mkdir xudt-from-scratch cd xudt-from-scratch bun init -y # try running the ts file created by default bun index.ts # based on the @ckb-lumos/lumos@0.0.0-canary-84521a5-20240530061434 bun install @ckb-lumos/lumos@canary ``` ---------------------------------------- TITLE: Launching Test Runner with Create React App (Shell) DESCRIPTION: This command launches the test runner in an interactive watch mode, allowing developers to run tests and see results as code changes. It's used for unit and integration testing of the React application. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/create-react-app/README.md#_snippet_1 LANGUAGE: Shell CODE: ``` npm test ``` ---------------------------------------- TITLE: Running Codec Examples with ts-node (Shell) DESCRIPTION: This snippet provides the command-line instruction to execute a TypeScript example file using `ts-node`. `ts-node` enables direct execution of TypeScript files without requiring a separate compilation step, which is useful for quick testing and running scripts. SOURCE: https://github.com/ckb-js/lumos/blob/develop/packages/codec/examples/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` ts-node mixed-codec-godwoken-v1-withdrawal-args.ts ``` ---------------------------------------- TITLE: Launching CKB Indexer for Data Sync (Shell) DESCRIPTION: This command starts the CKB indexer, configuring it to connect to the previously launched mock RPC server at `http://127.0.0.1:8118/rpc`. It specifies the indexer's local listening address as `127.0.0.1:8116` and designates `indexer-store-tmp` as the directory for storing synced block data. This setup enables the indexer to build a local, queryable database of CKB chain information. SOURCE: https://github.com/ckb-js/lumos/blob/develop/packages/testkit/README.md#_snippet_1 LANGUAGE: Shell CODE: ``` ckb-indexer -c http://127.0.0.1:8118/rpc -l 127.0.0.1:8116 -s indexer-store-tmp ``` ---------------------------------------- TITLE: Initializing Yarn Project (Shell) DESCRIPTION: This command initializes a new Node.js project using Yarn. Similar to `npm init`, it guides the user through creating a `package.json` file for project configuration and dependency management. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/00-intro.md#_snippet_2 LANGUAGE: Shell CODE: ``` yarn init ``` ---------------------------------------- TITLE: Installing Lumos with Yarn (Shell) DESCRIPTION: This command installs the `@ckb-lumos/lumos` package and its dependencies into the current project using Yarn. It provides the necessary tools for CKB blockchain development. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/00-intro.md#_snippet_4 LANGUAGE: Shell CODE: ``` yarn add @ckb-lumos/lumos ``` ---------------------------------------- TITLE: Installing Node.js and pnpm (Shell) DESCRIPTION: This snippet provides shell commands to update package lists, install Node.js, and then install pnpm globally using npm. These are prerequisites for building and running Lumos. SOURCE: https://github.com/ckb-js/lumos/blob/develop/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` sudo apt-get update sudo apt install nodejs npm install -g pnpm ``` ---------------------------------------- TITLE: Lumos DAO Transaction Example (TypeScript) DESCRIPTION: This comprehensive example demonstrates how to interact with the CKB DAO using the Lumos library. It covers initializing the Lumos configuration, generating SECP256K1 accounts, fetching cell details by outpoint, and performing deposit, withdraw, and unlock operations. The example also includes transaction sealing and sending to the CKB testnet. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/migrations/migrate-from-ckb-sdk-core.md#_snippet_2 LANGUAGE: TypeScript CODE: ``` import { BI, OutPoint, Cell, config, Indexer, RPC, hd, commons } from "@ckb-lumos/lumos" import { TransactionSkeleton, encodeToAddress, sealTransaction } from "@ckb-lumos/helpers" // ckt const CKB_RPC_URL = "https://testnet.ckb.dev/rpc" const CKB_INDEXER_URL = "https://testnet.ckb.dev/indexer" const rpc = new RPC(CKB_RPC_URL) const indexer = new Indexer(CKB_INDEXER_URL, CKB_RPC_URL) const CONFIG = config.createConfig({ PREFIX: "ckt", SCRIPTS: { ...config.predefined.AGGRON4.SCRIPTS, }, }) config.initializeConfig(CONFIG) export const generateSECP256K1Account = (privKey: string) => { const pubKey = hd.key.privateToPublic(privKey) const args = hd.key.publicKeyToBlake160(pubKey) const template = CONFIG.SCRIPTS["SECP256K1_BLAKE160"]! const lockScript = { codeHash: template.CODE_HASH, hashType: template.HASH_TYPE, args: args, } const address = encodeToAddress(lockScript, { config: CONFIG }) return { lockScript, address, pubKey, privKey, } } export const getCellByOutPoint = async (outpoint: OutPoint): Promise => { const tx = await rpc.get_transaction(outpoint.txHash) if (!tx) { throw new Error(`not found tx: ${outpoint.txHash}`) } const block = await rpc.getBlock(tx.txStatus.blockHash!) return { cellOutput: tx.transaction.outputs[0], data: tx.transaction.outputsData[0], outPoint: outpoint, blockHash: tx.txStatus.blockHash, blockNumber: block!.header.number, } } export const deposit = async (fromAddress: string, privKey: string) => { let txSkeleton = TransactionSkeleton({ cellProvider: indexer }) txSkeleton = await commons.dao.deposit(txSkeleton, fromAddress, fromAddress, BigInt(1000 * 10 ** 8)) txSkeleton = await commons.secp256k1Blake160.payFee(txSkeleton, fromAddress, BigInt(1 * 10 ** 8)) txSkeleton = commons.common.prepareSigningEntries(txSkeleton) const message = txSkeleton.get("signingEntries").get(0)?.message const Sig = hd.key.signRecoverable(message!, privKey) const tx = sealTransaction(txSkeleton, [Sig]) const hash = await rpc.sendTransaction(tx, "passthrough") return hash } export const withdraw = async (depositOutpoint: OutPoint, fromAddress: string, privKey: string) => { let txSkeleton = TransactionSkeleton({ cellProvider: indexer }) const depositCell = await getCellByOutPoint(depositOutpoint) txSkeleton = await commons.dao.withdraw(txSkeleton, depositCell, fromAddress) txSkeleton = await commons.secp256k1Blake160.payFee(txSkeleton, fromAddress, BigInt(1 * 10 ** 8)) txSkeleton = commons.common.prepareSigningEntries(txSkeleton) const message = txSkeleton.get("signingEntries").get(0)?.message const Sig = hd.key.signRecoverable(message!, privKey) const tx = sealTransaction(txSkeleton, [Sig]) const hash = await rpc.sendTransaction(tx, "passthrough") return hash } export const unlock = async ( depositOutpoint: OutPoint, withdrawOutpoint: OutPoint, fromAddress: string, privKey: string ) => { let txSkeleton = TransactionSkeleton({ cellProvider: indexer }) const depositCell = await getCellByOutPoint(depositOutpoint) const withdrawCell = await getCellByOutPoint(withdrawOutpoint) txSkeleton = await commons.dao.unlock(txSkeleton, depositCell, withdrawCell, fromAddress, fromAddress) txSkeleton = await commons.secp256k1Blake160.payFee(txSkeleton, fromAddress, BI.from(1 * 10 ** 8)) txSkeleton = commons.common.prepareSigningEntries(txSkeleton) const message = txSkeleton.get("signingEntries").get(0)?.message const Sig = hd.key.signRecoverable(message!, privKey) const tx = sealTransaction(txSkeleton, [Sig]) const hash = await rpc.sendTransaction(tx, "passthrough") return hash } const bootstrap = async () => { const alice = generateSECP256K1Account("0xd00c06bfd800d27397002dca6fb0993d5ba6399b4238b2f29ee9deb97593d2bc") const depositTx = await deposit(alice.address, alice.privKey) const depositOutpoint = { txHash: depositTx, index: "0x0" } const withdrawTx = await withdraw(depositOutpoint, alice.address, alice.privKey) const withdrawOutpoint = { txHash: withdrawTx, index: "0x0" } // wait 180 epoch const unlockTx = await unlock(depositOutpoint, withdrawOutpoint, alice.address, alice.privKey) console.log("unlockTx is", unlockTx) } bootstrap() ``` ---------------------------------------- TITLE: Installing Dependencies for lumos-molecule-codegen (Shell) DESCRIPTION: This shell command snippet outlines the necessary npm installations for utilizing the lumos-molecule-codegen CLI tool. It specifies installing @ckb-lumos/molecule as a development dependency and @ckb-lumos/codec as a regular dependency, which are prerequisites for code generation. SOURCE: https://github.com/ckb-js/lumos/blob/develop/packages/molecule/README.md#_snippet_1 LANGUAGE: Shell CODE: ``` npm install -D @ckb-lumos/molecule npm install @ckb-lumos/codec ``` ---------------------------------------- TITLE: Building and Running Lumos Solana Example DESCRIPTION: This snippet provides the necessary shell commands to build the Lumos project and then navigate into and execute the 'omni-lock-solana' example. These steps are prerequisites for running the demonstration of Omnilock and Phantom integration. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/omni-lock-solana/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` npm run build cd examples/omni-lock-solana npm start ``` ---------------------------------------- TITLE: Installing JoyID CKB Package with npm DESCRIPTION: This snippet demonstrates how to install the `@joyid/ckb` package, which is a prerequisite for using `@ckb-lumos/joyid`. It specifies a particular version to ensure compatibility. SOURCE: https://github.com/ckb-js/lumos/blob/develop/packages/joyid/README.md#_snippet_0 LANGUAGE: sh CODE: ``` npm install @joyid/ckb #@0.0.6 ``` ---------------------------------------- TITLE: Checking Lumos Build (Shell) DESCRIPTION: This command executes a TypeScript file using `npx ts-node` to verify if the Lumos project build was successful. It's a quick way to confirm the development environment is set up correctly. SOURCE: https://github.com/ckb-js/lumos/blob/develop/examples/README.md#_snippet_1 LANGUAGE: sh CODE: ``` npx ts-node misc/config-manager.ts ``` ---------------------------------------- TITLE: Migrating `CacheManager.loadFromKeystore` in JavaScript DESCRIPTION: The `CacheManager.loadFromKeystore` method has been deprecated. Users should migrate to `loadFromKeystoreJson` and provide the parsed JSON content of the keystore file directly, instead of just the file path, requiring manual file reading and parsing. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/migrations/migrate-to-v0.23.md#_snippet_1 LANGUAGE: JavaScript CODE: ``` JSON.parse(fs.readFileSync(path).toString()) ``` ---------------------------------------- TITLE: Creating Lumos Project Directory (Shell) DESCRIPTION: This snippet creates a new directory named `lumos-tutorial` and navigates into it. This is the initial step for setting up the project environment before initializing an npm or yarn project. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/00-intro.md#_snippet_0 LANGUAGE: Shell CODE: ``` mkdir lumos-tutorial cd lumos-tutorial ``` ---------------------------------------- TITLE: Initializing npm Project (Shell) DESCRIPTION: This command initializes a new Node.js project using npm. It prompts the user to answer several questions to set up the `package.json` file, which manages project metadata and dependencies. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/00-intro.md#_snippet_1 LANGUAGE: Shell CODE: ``` npm init ``` ---------------------------------------- TITLE: Setting Up Lumos Configuration and Utilities DESCRIPTION: This TypeScript snippet initializes the Lumos configuration for the CKB testnet, sets up an Indexer and RPC client, and defines helper functions for creating CKB `Script` and `CellDep` objects. It also prepares the owner's private key and derives the corresponding lock script and address for subsequent operations. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/00-tutorial-issue-and-transfer-xudt.md#_snippet_2 LANGUAGE: ts CODE: ``` import type { Cell, Script, CellDep } from "@ckb-lumos/lumos" import { config, hd, Indexer, RPC } from "@ckb-lumos/lumos" import { bytes, BytesLike, Uint128 } from "@ckb-lumos/lumos/codec" import { common } from "@ckb-lumos/lumos/common-scripts" import { ScriptConfig } from "@ckb-lumos/lumos/config" import { addCellDep, cellHelper, encodeToAddress, sealTransaction, TransactionSkeleton } from "@ckb-lumos/lumos/helpers" import { computeScriptHash } from "@ckb-lumos/lumos/utils" // to work with the testnet config.initializeConfig(config.TESTNET) // indexer for cell provider const indexer = new Indexer("https://testnet.ckb.dev") // rpc to interact with the CKB node const rpc = new RPC("https://testnet.ckb.dev") // paste the generated key for the owner const ownerPrivateKey = "<0x paste the key here>" // script config that will be used later const { XUDT, SECP256K1_BLAKE160 } = config.TESTNET.SCRIPTS const ownerLockScript = createScript(SECP256K1_BLAKE160, hd.key.privateKeyToBlake160(ownerPrivateKey)) const ownerAddress = encodeToAddress(ownerLockScript) // a helper to create a Script from a ScriptConfig function createScript(config: ScriptConfig, args: BytesLike): Script { return { codeHash: config.CODE_HASH, hashType: config.HASH_TYPE, args: bytes.hexify(args) } } // a helper to crete a CellDep from a ScriptConfig function createCellDep(config: ScriptConfig): CellDep { return { depType: config.DEP_TYPE, outPoint: { txHash: config.TX_HASH, index: config.INDEX } } } ``` ---------------------------------------- TITLE: Performing Prefix Search on Script Arguments (JavaScript) DESCRIPTION: This example demonstrates how to perform a prefix search on script arguments using the `argsLen` option. By providing a truncated `args` value and setting `argsLen` to the desired prefix length, the `CellCollector` can find cells whose script arguments start with the specified prefix. SOURCE: https://github.com/ckb-js/lumos/blob/develop/packages/ckb-indexer/README.md#_snippet_6 LANGUAGE: jsx CODE: ``` cellCollector = new CellCollector(indexer, { lock: { code_hash: "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", hash_type: "type", args: "0xa528f2b9a51118b193178db4cf2f3db92e7df3", // truncate the last byte of orignal args: 0xa528f2b9a51118b193178db4cf2f3db92e7df323 }, argsLen: 20, // default option is -1 fromBlock: "0x253b40", // "0x" + 2440000n.toString(16) toBlock: "0x253f28", // "0x" + 2441000n.toString(16) order: "desc", // default option is "asc" skip: 300, }); for await (const cell of cellCollector.collect()) { console.log(cell); } ``` ---------------------------------------- TITLE: Getting CKB Balance with Lumos Indexer in TypeScript DESCRIPTION: This TypeScript example demonstrates how to use `@ckb-lumos/lumos` to connect to a CKB RPC and Indexer, collect cells associated with a specific lock script, and calculate the total CKB balance. It utilizes the `Indexer` and `BI` (BigInt) classes for network interaction and large number arithmetic. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/01-run-lumos-in-the-browser.md#_snippet_1 LANGUAGE: ts CODE: ``` import { Script, Indexer, BI } from "@ckb-lumos/lumos" async function main(): Promise { const lock = { code_hash: "0x...", hash_type: "type", args: "0x..." } const CKB_RPC_URL = "https://testnet.ckb.dev/rpc" const CKB_INDEXER_URL = "https://testnet.ckb.dev/indexer" const indexer = new Indexer(CKB_INDEXER_URL, CKB_RPC_URL) const collector = indexer.collector({ lock }) let balance: BI = BI.from(0) for await (const cell of collector.collect()) { balance = balance.add(cell.cell_output.capacity) } return balance } main() ``` ---------------------------------------- TITLE: Using Root Lumos Package for Configuration and Address Parsing in TypeScript DESCRIPTION: This TypeScript example demonstrates the convenience of the new `@ckb-lumos/lumos` root package, which consolidates various subpackages. It shows how to import and use `helpers` for address parsing and `config` for initializing network configurations, simplifying imports and usage. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/01-run-lumos-in-the-browser.md#_snippet_3 LANGUAGE: ts CODE: ``` import { Script, Indexer, helpers, config } from "@ckb-lumos/lumos" config.initializeConfig(config.predefined.AGGRON4) const address = "ckt1qyqxgftlqzmtv05cwcyl4xlz6ryx6dgsyrasjrp27t" const lock: Script = helpers.parseAddress(address) ``` ---------------------------------------- TITLE: Releasing to Verdaccio in GitHub Actions (YAML) DESCRIPTION: This YAML snippet defines a step for a GitHub Actions workflow, designed to test package releases by publishing to a local Verdaccio registry within the CI/CD pipeline. It installs Verdaccio, configures npm for the local registry, and starts Verdaccio in the background, allowing for automated testing of the release process. SOURCE: https://github.com/ckb-js/lumos/blob/develop/devtools/README.md#_snippet_1 LANGUAGE: yaml CODE: ``` # TODO remove me when ready - name: Release to Verdaccio run: | npm install -g verdaccio npm config set registry http://localhost:4873 npm config set //localhost:4873/:_authToken fake nohup verdaccio --config ./devtools/verdaccio.yaml --listen=4873 >/dev/null 2>&1 & ``` ---------------------------------------- TITLE: Initializing CKB RPC and Indexer with Lumos (TypeScript) DESCRIPTION: This snippet demonstrates how to instantiate the CKB RPC and Indexer clients using the @ckb-lumos/lumos library. It sets up connections to the CKB testnet node and indexer services, which are essential for interacting with the blockchain and querying on-chain data. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/00-intro.md#_snippet_9 LANGUAGE: TypeScript CODE: ``` import { RPC, Indexer } from '@ckb-lumos/lumos'; const CKB_RPC_URL = "https://testnet.ckb.dev/rpc"; const CKB_INDEXER_URL = "https://testnet.ckb.dev/indexer"; const rpc = new RPC(CKB_RPC_URL); const indexer = new Indexer(CKB_INDEXER_URL, CKB_RPC_URL); ``` ---------------------------------------- TITLE: Loading and Saving XPubs with Lumos HD DESCRIPTION: This example illustrates the usage of `XPubStore` from `@ckb-lumos/hd` for managing extended public keys. It shows how to load an XPub from a file, convert it into an `AccountExtendedPublicKey` for derivation purposes, and save the XPub back to a specified path, facilitating read-only access to account structures. SOURCE: https://github.com/ckb-js/lumos/blob/develop/packages/hd/README.md#_snippet_1 LANGUAGE: javascript CODE: ``` const { XPubStore } = require("@ckb-lumos/hd") // load from xpub file. const xpub = XPubStore.load("you path") // to AccountExtendedPublicKey const accountExtendedPublicKey = xpub.toAccountExtendedPublicKey() // save xpub file. xpub.save("your path") ``` ---------------------------------------- TITLE: Initializing Lumos Configuration and Services DESCRIPTION: This code snippet initializes the Lumos configuration for the AGGRON4 testnet and sets up RPC and Indexer clients. These clients are essential for interacting with the CKB blockchain and querying cell data, respectively, forming the foundation for all subsequent operations. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/00-intro.md#_snippet_18 LANGUAGE: TypeScript CODE: ``` import { config } from '@ckb-lumos/lumos'; config.initializeConfig(config.predefined.AGGRON4); const CKB_RPC_URL = "https://testnet.ckb.dev/rpc"; const CKB_INDEXER_URL = "https://testnet.ckb.dev/indexer"; const rpc = new RPC(CKB_RPC_URL); const indexer = new Indexer(CKB_INDEXER_URL, CKB_RPC_URL); ``` ---------------------------------------- TITLE: Installing Lumos with npm (Shell) DESCRIPTION: This command installs the `@ckb-lumos/lumos` package and its dependencies into the current project using npm. Lumos is the primary library for interacting with the CKB blockchain in JavaScript/TypeScript. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/00-intro.md#_snippet_3 LANGUAGE: Shell CODE: ``` npm install @ckb-lumos/lumos ``` ---------------------------------------- TITLE: Downloading and Interacting with CKB Binaries using Lumos Runner in TypeScript DESCRIPTION: This snippet illustrates the process of downloading CKB related binaries using the `@ckb-lumos/runner` package, locating the downloaded executable, generating a CKB configuration file, and executing the binary with command-line arguments. It requires the `@ckb-lumos/runner` package and a mechanism to spawn child processes, such as Node.js's `child_process` module. SOURCE: https://github.com/ckb-js/lumos/blob/develop/packages/runner/README.md#_snippet_0 LANGUAGE: typescript CODE: ``` import { ckb, download } from '@ckb-lumos/runner' await download(ckb.getReleaseUrl(), 'path/to/a/directory') const ckbBinaryPath = ckb.findBinaryPath('path/to/a/directory') ckb.generateConfigSync(ckbBinaryPath, { ckbPort: 8114 }) spawn(ckbBinaryPath, ['--help']) ``` ---------------------------------------- TITLE: Setting up CKB Indexer and Deployment Options DESCRIPTION: This code defines the RPC and Indexer URLs for the CKB network and initializes an Indexer instance. It then sets up deployOptions by parsing a recipient address, defining the output script lock, and providing the binary data for the contract to be deployed. These options are essential for generating deployment transactions. SOURCE: https://github.com/ckb-js/lumos/blob/develop/packages/common-scripts/README.md#_snippet_4 LANGUAGE: JavaScript CODE: ``` const CKB_RPC_URL = "http://localhost:8114"; const CKB_INDEXER_URL = "http://localhost:8116"; const indexer = new Indexer(CKB_INDEXER_URL, CKB_RPC_URL); const address = "ckt1qyqptxys5l9vk39ft0hswscxgseawc77y2wqlr558h"; // Lock script of the deploy account const outputScriptLock = parseAddress(address); // Binary data you want to deploy const scriptBinary = Uint8Array.of(1); let deployOptions = { cellProvider: indexer, scriptBinary: scriptBinary, outputScriptLock: outputScriptLock, } ``` ---------------------------------------- TITLE: Installing Lumos Package with npm DESCRIPTION: This snippet provides the command to install the `@ckb-lumos/lumos` package, which is the consolidated package containing all subpackages, making it easier to use Lumos in web projects. It supports both npm and yarn package managers. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/01-run-lumos-in-the-browser.md#_snippet_0 LANGUAGE: shell CODE: ``` npm install @ckb-lumos/lumos ``` ---------------------------------------- TITLE: Serializing CKB Script Arguments with Lumos Base in TypeScript DESCRIPTION: This snippet demonstrates the serialization of CKB script arguments. The 'before' example uses `serializeArgs` from `ckb-sdk-utils`, while the 'after' example utilizes `blockchain.Bytes.pack` from `@ckb-lumos/base`. This migration standardizes argument serialization using the generic `Bytes` type provided by Lumos. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/migrations/migrate-form-ckb-sdk-utils.md#_snippet_20 LANGUAGE: TypeScript CODE: ``` import { serializeArgs } from "@nervosnetwork/ckb-sdk-utils" import { blockchain } from "@ckb-lumos/base" import { bytes } from "@ckb-lumos/codec" const args = "0x8536c9d5d908bd89fc70099e4284870708b6632356aad98734fcf43f6f71c304" // before serializeArgs(args) // 0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88 ``` LANGUAGE: TypeScript CODE: ``` import { serializeArgs } from "@nervosnetwork/ckb-sdk-utils" import { blockchain } from "@ckb-lumos/base" import { bytes } from "@ckb-lumos/codec" const args = "0x8536c9d5d908bd89fc70099e4284870708b6632356aad98734fcf43f6f71c304" // after bytes.hexify(blockchain.Bytes.pack(args)) // 0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88 ``` ---------------------------------------- TITLE: Initiating CKB Transfer with Lumos DESCRIPTION: This snippet demonstrates how to initiate a basic CKB transfer using a previously defined `transfer` function. It logs the transaction hash upon successful completion, showcasing a fundamental CKB operation. SOURCE: https://github.com/ckb-js/lumos/blob/develop/website/docs/00-intro.md#_snippet_16 LANGUAGE: TypeScript CODE: ``` transfer(address, bobAddress, 100 * 10 ** 8, privateKey).then((txHash: string) => console.log('txHash: ', txHash)); ```