Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
CKB
https://github.com/nervosnetwork/ckb
Admin
CKB is the layer 1 of Nervos Network, a public/permissionless blockchain.
Tokens:
76,488
Snippets:
647
Trust Score:
7.9
License:
MIT
Update:
2 months ago
Context
Chat
Benchmark
47
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Install and Start CKB Systemd Service Source: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/linux-systemd/README.md Downloads the CKB systemd service unit file, installs it, reloads the systemd daemon, and starts the CKB node service. ```bash curl -L -O https://raw.githubusercontent.com/nervosnetwork/ckb/master/devtools/init/linux-systemd/ckb.service sudo cp ckb.service /etc/systemd/system/ sudo chown root:root /etc/systemd/system/ckb.service sudo chmod 644 /etc/systemd/system/ckb.service sudo systemctl daemon-reload sudo systemctl start ckb.service ``` -------------------------------- ### Install and Start CKB Miner Systemd Service Source: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/linux-systemd/README.md Downloads the CKB miner systemd service unit file, installs it, reloads the systemd daemon, and starts the CKB miner service. ```bash curl -L -O https://raw.githubusercontent.com/nervosnetwork/ckb/master/devtools/init/linux-systemd/ckb-miner.service sudo cp ckb-miner.service /etc/systemd/system/ sudo chown root:root /etc/systemd/system/ckb-miner.service sudo chmod 644 /etc/systemd/system/ckb-miner.service sudo systemctl daemon-reload sudo systemctl start ckb-miner.service ``` -------------------------------- ### Overview Version Example Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example of the version field format within the Overview data structure. ```json "version": "0.34.0 (f37f598 2020-07-17)" ``` -------------------------------- ### Duktape VM Script Log Example Source: https://github.com/nervosnetwork/ckb/wiki/Special-Live-Cells Example log output when the duktape VM is running, useful for debugging. ```text DEBUG ckb-script script group: Byte32(0xafe527276275a4a25defee32ed59ecebf4813256866a7577431e5293acd2048b) DEBUG OUTPUT: I'm running in JS! ``` -------------------------------- ### Get Indexer Tip RPC Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example request and response for retrieving the current indexed block tip. ```json { "id": 2, "jsonrpc": "2.0", "method": "get_indexer_tip" } ``` ```json { "jsonrpc": "2.0", "result": { "block_hash": "0x4959d6e764a2edc6038dbf03d61ebcc99371115627b186fdcccb2161fbd26edc", "block_number": "0x5b513e" }, "id": 2 } ``` -------------------------------- ### Enable CKB Node to Start on Boot Source: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/linux-systemd/README.md Configures the CKB node service to start automatically when the system boots up. ```bash sudo systemctl enable ckb.service ``` -------------------------------- ### GnuPG Verification Output Examples Source: https://github.com/nervosnetwork/ckb/blob/develop/docs/integrity-check.md Examples of potential outputs when running the GnuPG verification command. ```text gpg: Signature made Wed 05 Jun 2019 10:12:22 PM UTC using RSA key ID F4631C0A gpg: Can't check signature: No public key ``` ```text gpg: Signature made Wed 05 Jun 2019 10:12:22 PM UTC using RSA key ID F4631C0A gpg: Good signature from "Nervos CI <bot@nervos.org>" gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: 64B7 05B5 6078 1FC5 4047 7B82 4F37 F694 F463 1C0A ``` ```text gpg: Signature made Wed 05 Jun 2019 10:12:22 PM UTC using RSA key ID F4631C0A gpg: checking the trustdb gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u gpg: next trustdb check due at 2023-06-05 gpg: Good signature from "Nervos CI <bot@nervos.org>" ``` -------------------------------- ### Get Overview Request and Response Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example of a JSON-RPC request to get_overview using cached data and the corresponding response structure. ```json { "jsonrpc": "2.0", "method": "get_overview", "params": [null], "id": 1 } ``` ```json { "jsonrpc": "2.0", "result": { "sys": { "cpu_usage": 25.5, "memory": 134217728, "virtual_memory": 268435456, "disk_usage": { "read_bytes": 1048576, "total_read_bytes": 1073741824, "written_bytes": 524288, "total_written_bytes": 536870912 }, "global": { "total_memory": 8589934592, "used_memory": 4294967296, "global_cpu_usage": 150.0, "disks": [ { "total_space": 1000000000000, "available_space": 500000000000, "is_removable": false } ], "networks": [ { "interface_name": "eth0", "received": 1048576, "total_received": 1073741824, "transmitted": 524288, "total_transmitted": 536870912 } ] } }, "mining": { "difficulty": "0x1e083126", "hash_rate": "0x174876e800" }, "pool": { "pending": "0x64", "proposed": "0x32", "orphan": "0x5", "committing": "0x1f", "total_recent_reject_num": "0x3", "total_tx_size": "0x100000", "total_tx_cycles": "0x2dc6c", "last_txs_updated_at": "0x187b3d137a1", "max_tx_pool_size": "0x20000000" }, "cells": { "total_occupied_capacities": "0x15f1e59b76c000", "estimate_live_cells_num": "0x989680" }, "network": { "connected_peers": "0x33", "outbound_peers": "0x1f", "inbound_peers": "0x14", "peers": [ { "peer_id": 0, "is_outbound": true, "latency_ms": "0x98", "address": "/ip4/18.185.102.19/tcp/8115/p2p/QmXwUgF48ULy6hkgfqrEwEfuHW7WyWyWauueRDAYQHNDfN" }, { "peer_id": 1, "is_outbound": false, "latency_ms": "0xa5", "address": "/ip4/18.185.102.19/tcp/8115/p2p/QmXwUgF48ULy6hkgfqrEwEfuHW7WyWyWauueRDAYQHNDfN" }, { "peer_id": 2, "is_outbound": true, "latency_ms": "0x0", "address": "/ip4/18.185.102.19/tcp/8115/p2p/QmXwUgF48ULy6hkgfqrEwEfuHW7WyWyWauueRDAYQHNDfN" }, { "peer_id": 3, "is_outbound": true, "latency_ms": "0x8c", "address": "/ip4/18.185.102.19/tcp/8115/p2p/QmXwUgF48ULy6hkgfqrEwEfuHW7WyWyWauueRDAYQHNDfN" } ] }, "version": "0.100.0 (abc123def 2023-12-01)" }, "id": 1 } ``` -------------------------------- ### Start CKB Node Source: https://github.com/nervosnetwork/ckb/blob/develop/docs/dev-miner.md Starts the CKB node. Ensure this is run after modifying the configuration to use the desired PoW algorithm. ```shell ckb run ``` -------------------------------- ### Enable CKB Miner to Start on Boot Source: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/linux-systemd/README.md Configures the CKB miner service to start automatically when the system boots up. ```bash sudo systemctl enable ckb-miner.service ``` -------------------------------- ### Install CKB Fuzzing Components Source: https://github.com/nervosnetwork/ckb/blob/develop/script/fuzz/README.md Installs essential components and tools for fuzz testing, including Rust nightly components and utility crates. ```bash rustup component add llvm-tools-preview cargo install cargo-binutils cargo install rustfilt ``` ```bash cargo install cargo-fuzz ``` -------------------------------- ### ExtraLoggerConfig Filter Examples Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Examples of filter strings used to configure runtime logging levels for CKB modules. ```text info ``` ```text info,ckb-rpc=debug,ckb-sync=debug,ckb-relay=debug,ckb-tx-pool=debug,ckb-network=debug ``` -------------------------------- ### WebSocket RPC Subscription Example Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Demonstrates subscribing to new tip headers via a WebSocket connection in JavaScript. ```javascript let socket = new WebSocket("ws://localhost:28114") socket.onmessage = function(event) { console.log(`Data received from server: ${event.data}`); } socket.send(`{"id": 2, "jsonrpc": "2.0", "method": "subscribe", "params": ["new_tip_header"]}`) socket.send(`{"id": 2, "jsonrpc": "2.0", "method": "unsubscribe", "params": ["0x0"]}`) ``` -------------------------------- ### Response get_block with with_cycles Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example response when with_cycles is enabled. ```text { "id": 42, "jsonrpc": "2.0", "result": { "block": <Object> or "0x...", "cycles": [] } } ``` -------------------------------- ### ProposalShortId Example Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md A 10-byte fixed-length binary encoded as a 0x-prefixed hex string. ```text 0xa0ef4eb5f4ceeb08a4c8 ``` -------------------------------- ### Submit Block RPC Example Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Demonstrates the JSON-RPC request and response for submitting a new block to the network. ```json { "id": 42, "jsonrpc": "2.0", "method": "submit_block", "params": [ "work_id_example", { "header": { "compact_target": "0x1e083126", "dao": "0xb5a3e047474401001bc476b9ee573000c0c387962a38000000febffacf030000", "epoch": "0x7080018000001", "extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "nonce": "0x0", "number": "0x400", "parent_hash": "0xae003585fa15309b30b31aed3dcf385e9472c3c3e93746a6c4540629a6a1ed2d", "proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp": "0x5cd2b117", "transactions_root": "0xc47d5b78b3c4c4c853e2a32810818940d0ee403423bea9ec7b8e566d9595206c", "version": "0x0" }, "proposals": [], "transactions": [ { "cell_deps": [], "header_deps": [], "inputs": [ { "previous_output": { "index": "0xffffffff", "tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000" }, "since": "0x400" } ], "outputs": [ { "capacity": "0x18e64b61cf", "lock": { "code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5", "hash_type": "data", "args": "0x" }, "type": null } ], "outputs_data": [ "0x" ], "version": "0x0", "witnesses": [ "0x450000000c000000410000003500000010000000300000003100000028e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5000000000000000000" ] } ], "uncles": [] } ] } ``` ```json { "id": 42, "jsonrpc": "2.0", "result": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40" } ``` -------------------------------- ### Response get_block with verbosity 0 Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example response when verbosity is set to 0. ```text { "id": 42, "jsonrpc": "2.0", "result": "0x..." } ``` -------------------------------- ### Subscribe Request and Response Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example of initiating a subscription to a topic and the corresponding response containing the subscription ID. ```json { "id": 42, "jsonrpc": "2.0", "method": "subscribe", "params": [ "new_tip_header" ] } ``` ```json { "id": 42, "jsonrpc": "2.0", "result": "0xf3" } ``` -------------------------------- ### Setup CKB User, Group, and Permissions Source: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/linux-systemd/README.md Creates a dedicated 'ckb' user and group, sets ownership and permissions for the CKB data directory, and configures specific file permissions for TOML configuration files. ```bash sudo groupadd ckb sudo useradd \ -g ckb --no-user-group \ --home-dir /var/lib/ckb --no-create-home \ --shell /usr/sbin/nologin \ --system ckb sudo chown -R ckb:ckb /var/lib/ckb sudo chmod 755 /var/lib/ckb sudo chmod 644 /var/lib/ckb/ckb.toml /var/lib/ckb/ckb-miner.toml ``` -------------------------------- ### List Supported Chains for Initialization Source: https://github.com/nervosnetwork/ckb/blob/develop/docs/configure.md Run 'ckb init --list-chains' to see all available chain specifications that can be exported. ```bash ckb init --list-chains ``` -------------------------------- ### Set Up Multiple CKB Nodes Source: https://github.com/nervosnetwork/ckb/blob/develop/docs/configure.md To run multiple nodes, create separate directories for each node's configuration. Initialize each node with a specific chain and genesis message. Ensure to adjust listen ports and RPC URLs in 'ckb.toml' for each node to avoid conflicts. Add the P2P address of one node to the 'bootnodes' list of another to establish connections. ```bash mkdir node1 node2 ckb -C node1 init --chain dev --genesis-message dev-genesis ckb -C node2 init --chain dev --genesis-message dev-genesis # Change listen ports 8114/8115 to 8116/8117 in node2/ckb.toml. # Change `rpc_url` in node2/ckb.toml to use 8116. # start node1 ckb -C node1 run # If you want node2 connects node1, copy the P2P address of node1 in its log. # Add the address into the section `bootnodes` in `node2/ckb.toml`. # start node2 ckb -C node2 run ``` -------------------------------- ### TCP RPC Subscription Example Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Demonstrates subscribing to new tip headers via a TCP connection using telnet. ```bash telnet localhost 18114 > {"id": 2, "jsonrpc": "2.0", "method": "subscribe", "params": ["new_tip_header"]} < {"jsonrpc":"2.0","result":"0x0","id":2} < {"jsonrpc":"2.0","method":"subscribe","params":{"result":"...block header json...", "subscription":0}} < {"jsonrpc":"2.0","method":"subscribe","params":{"result":"...block header json...", "subscription":0}} < ... > {"id": 2, "jsonrpc": "2.0", "method": "unsubscribe", "params": ["0x0"]} < {"jsonrpc":"2.0","result":true,"id":2} ``` -------------------------------- ### Get cells by lock script request Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example JSON-RPC request to fetch cells filtered by a specific lock script in ascending order. ```json { "id": 2, "jsonrpc": "2.0", "method": "get_cells", "params": [ { "script": { "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", "hash_type": "type", "args": "0x5989ae415bb667931a99896e5fbbfad9ba53a223" }, "script_type": "lock" }, "asc", "0x64" ] } ``` -------------------------------- ### Get transactions by lock script request and response Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example of a JSON-RPC request to fetch transactions filtered by a lock script and the corresponding paginated response. ```json { "id": 2, "jsonrpc": "2.0", "method": "get_transactions", "params": [ { "script": { "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", "hash_type": "type", "args": "0x5989ae415bb667931a99896e5fbbfad9ba53a223" }, "script_type": "lock" }, "asc", "0x64" ] } ``` ```json { "jsonrpc": "2.0", "result": { "last_cursor": "0x809bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8015989ae415bb667931a99896e5fbbfad9ba53a22300000000005b59df000000010000000101", "objects": [ { "block_number": "0x5b033a", "io_index": "0x0", "io_type": "output", "tx_hash": "0x556060b62d16386da53f8a4b458314dfa2d1988a7bcc5c96c3bb2a350a3453a1", "tx_index": "0x4" }, { "block_number": "0x5b0671", "io_index": "0x0", "io_type": "input", "tx_hash": "0x8205b2b4cd6380d7e332c7a5b49bf776a0322ba19f46dc6ca1f8c59f7daee08d", "tx_index": "0x1" }, { "block_number": "0x5b0671", "io_index": "0x1", "io_type": "output", "tx_hash": "0x8205b2b4cd6380d7e332c7a5b49bf776a0322ba19f46dc6ca1f8c59f7daee08d", "tx_index": "0x1" }, { "block_number": "0x5b0e6d", "io_index": "0x0", "io_type": "output", "tx_hash": "0xe8f2180dfba0cb15b45f771d520834515a5f8d7aa07f88894da88c22629b79e9", "tx_index": "0x1" }, { "block_number": "0x5b0e90", "io_index": "0x0", "io_type": "output", "tx_hash": "0xece3a27409bde2914fb7a1555d6bfca453ee46af73e665149ef549fd46ec1fc6", "tx_index": "0x1" }, { "block_number": "0x5b0ead", "io_index": "0x0", "io_type": "input", "tx_hash": "0x5c48768f91e3795b418c53211c76fd038c464a24c4aa7e35bbbb6ac5b219f581", "tx_index": "0x1" }, { "block_number": "0x5b0ead", "io_index": "0x1", "io_type": "output", "tx_hash": "0x5c48768f91e3795b418c53211c76fd038c464a24c4aa7e35bbbb6ac5b219f581", "tx_index": "0x1" }, { "block_number": "0x5b0eeb", "io_index": "0x0", "io_type": "output", "tx_hash": "0x90e6981d6a5692d92e54344dc0e12d213447710fa069cc19ddea874619b9ba48", "tx_index": "0x1" }, { "block_number": "0x5b0f8c", "io_index": "0x0", "io_type": "output", "tx_hash": "0x9ea14510219ae97afa0275215fa77c3c015905281c953a3917a7fd036767429c", "tx_index": "0x1" }, { "block_number": "0x5b5638", "io_index": "0x0", "io_type": "input", ``` -------------------------------- ### Initialize CKB with Default Configuration Source: https://github.com/nervosnetwork/ckb/blob/develop/docs/quick-start.md Run this command to initialize the current directory with CKB's default configuration files. This sets up the necessary files for running a CKB node. ```shell ckb init ``` -------------------------------- ### Banned Address Example Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example of a P2P address string used in the BannedAddr type. ```text /ip4/192.168.0.2/tcp/8112/p2p/QmTRHCdrRtgUzYLNCin69zEvPvLYdxUZLLfLYyHVY3DZAS ``` -------------------------------- ### Initialize CKB Data Directory and Configuration Source: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/linux-systemd/README.md Creates the data directory for CKB and initializes configuration files for the mainnet chain, logging output to stdout. ```bash sudo mkdir /var/lib/ckb sudo /usr/local/bin/ckb init -C /var/lib/ckb --chain mainnet --log-to stdout ``` -------------------------------- ### Calculate DAO Field JSON-RPC Example Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example request and response for the calculate_dao_field method. ```json { "id": 42, "jsonrpc": "2.0", "method": "calculate_dao_field", "params": [ { "bytes_limit": "0x91c08", "cellbase": { "cycles": null, "data": { "cell_deps": [], "header_deps": [], "inputs": [ { "previous_output": { "index": "0xffffffff", "tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000" }, "since": "0x401" } ], "outputs": [ { "capacity": "0x18e64efc04", "lock": { "code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5", "hash_type": "data", "args": "0x" }, "type": null } ], "outputs_data": [ "0x" ], "version": "0x0", "witnesses": [ "0x650000000c00000055000000490000001000000030000000310000001892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df20114000000b2e61ff569acf041b3c2c17724e2379c581eeac30c00000054455354206d657373616765" ] }, "hash": "0xbaf7e4db2fd002f19a597ca1a31dfe8cfe26ed8cebc91f52b75b16a7a5ec8bab" }, "compact_target": "0x1e083126", "current_time": "0x174c45e17a3", "cycles_limit": "0xd09dc300", "dao": "0xd495a106684401001e47c0ae1d5930009449d26e32380000000721efd0030000", "epoch": "0x7080019000001", "extension": "0xb0a0079f3778c0ba0d89d88b389c602cc18b8a0355d16c0713f8bfcee64b5f84", "number": "0x401", "parent_hash": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40", "proposals": ["0xa0ef4eb5f4ceeb08a4c8"], "transactions": [], "uncles": [ { "hash": "0xdca341a42890536551f99357612cef7148ed471e3b6419d0844a4e400be6ee94", "header": { "compact_target": "0x1e083126", "dao": "0xb5a3e047474401001bc476b9ee573000c0c387962a38000000febffacf030000", "epoch": "0x7080018000001", "extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "nonce": "0x0", "number": "0x400", "parent_hash": "0xae003585fa15309b30b31aed3dcf385e9472c3c3e93746a6c4540629a6a1ed2d", "proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp": "0x5cd2b118", "transactions_root": "0xc47d5b78b3c4c4c853e2a32810818940d0ee403423bea9ec7b8e566d9595206c", "version":"0x0" }, "proposals": [], "required": false } ], "uncles_count_limit": "0x2", "version": "0x0", "work_id": "0x0" } ] } ``` ```json { "id": 42, "jsonrpc": "2.0", "result": "0xd495a106684401001e47c0ae1d5930009449d26e32380000000721efd0030000" } ``` -------------------------------- ### Initialize CKB Development Chain Source: https://github.com/nervosnetwork/ckb/wiki/Chains Initializes a CKB development chain. Replace the placeholder with your actual pubkey hash. ```bash ckb init -c dev --ba-arg 0x5406f5abe8e3a7eba641f79556688c226d...... ``` -------------------------------- ### Dry Run Transaction JSON-RPC Example Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example request and response for the dry_run_transaction method to estimate execution cycles. ```json { "id": 42, "jsonrpc": "2.0", "method": "dry_run_transaction", "params": [ { "cell_deps": [ { "dep_type": "code", "out_point": { "index": "0x0", "tx_hash": "0xa4037a893eb48e18ed4ef61034ce26eba9c585f15c9cee102ae58505565eccc3" } } ], "header_deps": [ "0x7978ec7ce5b507cfb52e149e36b1a23f6062ed150503c85bbf825da3599095ed" ], "inputs": [ { "previous_output": { "index": "0x0", "tx_hash": "0x365698b50ca0da75dca2c87f9e7b563811d3b5813736b8cc62cc3b106faceb17" }, "since": "0x0" } ], "outputs": [ { "capacity": "0x2540be400", "lock": { "code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5", "hash_type": "data", "args": "0x" }, "type": null } ], "outputs_data": [ "0x" ], "version": "0x0", "witnesses": [] } ] } ``` ```json { "id": 42, "jsonrpc": "2.0", "result": { "cycles": "0x219" } } ``` -------------------------------- ### CKB Rich-Indexer Configuration (TOML) Source: https://github.com/nervosnetwork/ckb/blob/develop/util/rich-indexer/README.md Example configuration for CKB Rich-Indexer in ckb.toml, demonstrating custom filtering rules and initial tip hash. ```toml # CKB built-in indexer/rich-indexer settings. # Utilize the `ckb reset-data --indexer` and `ckb reset-data --rich-indexer` subcommands to efficiently clean existing indexes. [indexer_v2] # # Indexing the pending txs in the ckb tx-pool # index_tx_pool = false # # Customize block filtering rules to index only retained blocks block_filter = "block.header.number.to_uint() >= \"0x0\".to_uint()" # # Customize cell filtering rules to index only retained cells cell_filter = "let script = output.type;script!=() && script.code_hash == \"0x00000000000000000000000000000000000000000000000000545950455f4944\"" # # The initial tip can be set higher than the current indexer tip as the starting height for indexing. init_tip_hash = "0x8fbd0ec887159d2814cee475911600e3589849670f5ee1ed9798b38fdeef4e44" ``` -------------------------------- ### Local Node Info RPC Example Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Demonstrates the JSON-RPC request and response for retrieving information about the local node. ```json { "id": 42, "jsonrpc": "2.0", "method": "local_node_info", "params": [] } ``` ```json { "id": 42, "jsonrpc": "2.0", "result": { "active": true, "addresses": [ { "address": "/ip4/192.168.0.2/tcp/8112/p2p/QmTRHCdrRtgUzYLNCin69zEvPvLYdxUZLLfLYyHVY3DZAS", "score": "0xff" }, { "address": "/ip4/0.0.0.0/tcp/8112/p2p/QmTRHCdrRtgUzYLNCin69zEvPvLYdxUZLLfLYyHVY3DZAS", "score": "0x1" } ], "connections": "0xb", "node_id": "QmTRHCdrRtgUzYLNCin69zEvPvLYdxUZLLfLYyHVY3DZAS", "protocols": [ { "id": "0x0", "name": "/ckb/ping", "support_versions": [ "0.0.1" ] }, { "id": "0x1", "name": "/ckb/discovery", "support_versions": [ "0.0.1" ] } ], "version": "0.34.0 (f37f598 2020-07-17)" } } ``` -------------------------------- ### Initialize Dev Chain with Imported Spec Source: https://github.com/nervosnetwork/ckb/blob/develop/docs/devnet-from-existing-data.md Initialize the 'dev' chain using the 'ckb init' command, importing the downloaded mainnet spec file. Use '--force' to overwrite if necessary. Replace 'mainnet.toml' with 'testnet.toml' if using testnet data. ```shell ckb init --chain dev --import-spec ./mainnet.toml --force ``` -------------------------------- ### Export Testnet Configuration Source: https://github.com/nervosnetwork/ckb/blob/develop/docs/configure.md Initialize configuration files specifically for the testnet chain using 'ckb init --chain testnet'. ```bash ckb init --chain testnet ``` -------------------------------- ### Run CKB in Daemon Mode Source: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/README.md Use this command to start the CKB node in daemon mode on Linux/MacOS. The service will not start automatically after reboot. ```bash ckb run --daemon ``` -------------------------------- ### CKB WebSocket RPC Subscription Example Source: https://github.com/nervosnetwork/ckb/wiki/RPC-subscription Illustrates how to subscribe to new block headers using WebSockets. Includes setting up the WebSocket connection, handling incoming messages, sending a subscription request, and sending an unsubscribe request. ```javascript let socket = new WebSocket("ws://localhost:28114") socket.onmessage = function(event) { console.log(`Data received from server: ${event.data}`); } socket.send(`{"id": 2, "jsonrpc": "2.0", "method": "subscribe", "params": ["new_tip_header"]}`) socket.send(`{"id": 2, "jsonrpc": "2.0", "method": "unsubscribe", "params": [0]}`) ``` -------------------------------- ### Start CKB Miner Source: https://github.com/nervosnetwork/ckb/blob/develop/docs/dev-miner.md Starts the CKB built-in miner in a separate terminal. This is used to verify that the dev chain and miner are correctly configured for the Eaglesong PoW algorithm. ```shell ckb miner ``` -------------------------------- ### View Test Options Source: https://github.com/nervosnetwork/ckb/blob/develop/test/README.md Displays all available command-line options for running the integration tests. ```bash cargo run -- --help ``` -------------------------------- ### Create and Navigate to CKB Development Directory Source: https://github.com/nervosnetwork/ckb/blob/develop/docs/quick-start.md Use these commands to create a new directory for CKB development and change into it. All subsequent commands should be run from this directory. ```shell mkdir ckb-dev cd ckb-dev ``` -------------------------------- ### CellDep JSON Example Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Represents a cell dependency within a transaction. ```json { "dep_type": "code", "out_point": { "index": "0x0", "tx_hash": "0xa4037a893eb48e18ed4ef61034ce26eba9c585f15c9cee102ae58505565eccc3" } } ``` -------------------------------- ### get_block_by_number Request Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example JSON-RPC request for retrieving a block by its number. ```json { "id": 42, "jsonrpc": "2.0", "method": "get_block_by_number", "params": [ "0x400" ] } ``` -------------------------------- ### CKB TCP RPC Subscription Example Source: https://github.com/nervosnetwork/ckb/wiki/RPC-subscription Demonstrates how to subscribe to new block headers using telnet over a TCP connection to the CKB RPC endpoint. Shows initial subscription, receiving block headers, and unsubscribing. ```shell telnet localhost 18114 > {"id": 2, "jsonrpc": "2.0", "method": "subscribe", "params": ["new_tip_header"]} < {"jsonrpc":"2.0","result":0,"id":2} < {"jsonrpc":"2.0","method":"subscribe","params":{"result":"...block header json...","subscription":0}} < {"jsonrpc":"2.0","method":"subscribe","params":{"result":"...block header json...","subscription":0}} < ... > {"id": 2, "jsonrpc": "2.0", "method": "unsubscribe", "params": [0]} < {"jsonrpc":"2.0","result":true,"id":2} ``` -------------------------------- ### Request get_block Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example JSON-RPC request to fetch a block by its hash. ```json { "id": 42, "jsonrpc": "2.0", "method": "get_block", "params": [ "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40" ] } ``` -------------------------------- ### tx_pool_ready Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Checks if the transaction pool service is started and ready for requests. ```APIDOC ## tx_pool_ready ### Description Returns whether tx-pool service is started, ready for request. ### Parameters None ### Request Example { "id": 42, "jsonrpc": "2.0", "method": "tx_pool_ready", "params": [] } ``` -------------------------------- ### CellData JSON Example Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Represents the content and hash of a cell's data. ```json { "content": "0x7f454c460201010000000000000000000200f3000100000078000100000000004000000000000000980000000000000005000000400038000100400003000200010000000500000000000000000000000000010000000000000001000000000082000000000000008200000000000000001000000000000001459308d00573000000002e7368737472746162002e74657874000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b000000010000000600000000000000780001000000000078000000000000000a0000000000000000000000000000000200000000000000000000000000000001000000030000000000000000000000000000000000000082000000000000001100000000000000000000000000000001000000000000000000000000000000", "hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5" } ``` -------------------------------- ### Request get_fork_block Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example JSON-RPC request for retrieving a fork block by its hash. ```json { "id": 42, "jsonrpc": "2.0", "method": "get_fork_block", "params": [ "0xdca341a42890536551f99357612cef7148ed471e3b6419d0844a4e400be6ee94" ] } ``` -------------------------------- ### Import PGP Public Key Source: https://github.com/nervosnetwork/ckb/blob/develop/docs/integrity-check.md Use this command to retrieve the public key from the keyserver network. ```bash gpg --recv-keys 37F67AEEAC33DF1F ``` -------------------------------- ### Response get_block Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md Example JSON-RPC response containing the full block object. ```json { "id": 42, "jsonrpc": "2.0", "result": { "header": { "compact_target": "0x1e083126", "dao": "0xb5a3e047474401001bc476b9ee573000c0c387962a38000000febffacf030000", "epoch": "0x7080018000001", "extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hash": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40", "nonce": "0x0", "number": "0x400", "parent_hash": "0xae003585fa15309b30b31aed3dcf385e9472c3c3e93746a6c4540629a6a1ed2d", "proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp": "0x5cd2b117", "transactions_root": "0xc47d5b78b3c4c4c853e2a32810818940d0ee403423bea9ec7b8e566d9595206c", "version": "0x0" }, "proposals": [], "transactions": [ { "cell_deps": [], "hash": "0x365698b50ca0da75dca2c87f9e7b563811d3b5813736b8cc62cc3b106faceb17", "header_deps": [], "inputs": [ { "previous_output": { "index": "0xffffffff", "tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000" }, "since": "0x400" } ], "outputs": [ { "capacity": "0x18e64b61cf", "lock": { "code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5", "hash_type": "data", "args": "0x" }, "type": null } ], "outputs_data": [ "0x" ], "version": "0x0", "witnesses": [ "0x450000000c000000410000003500000010000000300000003100000028e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5000000000000000000" ] } ], "uncles": [] } } ``` -------------------------------- ### ProposalWindow Visualization Source: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md A visual representation of the proposal and commitment window parameters. ```text ProposalWindow { closest: 2, farthest: 10 } propose \ \ 13 14 [15 16 17 18 19 20 21 22 23] \_______________________/ \ commit ``` -------------------------------- ### Build mruby Binary with Docker Source: https://github.com/nervosnetwork/ckb/wiki/Special-Live-Cells Steps to build the mruby binary using Docker, including cloning the repository and running the build process. ```bash $ git clone --recursive https://github.com/nervosnetwork/ckb-mruby $ cd ckb-mruby $ sudo docker run --rm -it -v `pwd`:/code nervos/ckb-riscv-gnu-toolchain:bionic-20191012 bash root@982d1e906b76:/# apt-get update root@982d1e906b76:/# apt-get install -y ruby root@982d1e906b76:/code# cd /code root@982d1e906b76:/code# make root@982d1e906b76:/code# exit ``` -------------------------------- ### Run Specific Specs Source: https://github.com/nervosnetwork/ckb/blob/develop/test/README.md Execute specific integration test specs. The path to the CKB binary needs to be provided. ```bash cargo run -- --bin ../target/debug/ckb spec1 spec2 ```