======================== CODE SNIPPETS ======================== TITLE: Start CKB Node (shell) DESCRIPTION: Starts the CKB node process using the configuration found in the current directory. The node will begin syncing with the network or reusing existing data if available. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/docs/quick-start.md#_snippet_2 LANGUAGE: shell CODE: ``` ckb run ``` ---------------------------------------- TITLE: Start CKB Miner (shell) DESCRIPTION: Starts the CKB miner process. This command requires the miner lock to be configured in `ckb.toml` and the `ckb run` process to be active. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/docs/quick-start.md#_snippet_4 LANGUAGE: shell CODE: ``` ckb miner ``` ---------------------------------------- TITLE: Initialize CKB Node Directory (shell) DESCRIPTION: Initializes the current directory with default CKB configuration files (`ckb.toml`). This command prepares the directory for running a CKB node. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/docs/quick-start.md#_snippet_1 LANGUAGE: shell CODE: ``` ckb init ``` ---------------------------------------- TITLE: Create and Navigate CKB Directory (shell) DESCRIPTION: Creates a new directory named `ckb-dev` and changes the current directory to it. This directory will be used to store the CKB node configuration and data. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/docs/quick-start.md#_snippet_0 LANGUAGE: shell CODE: ``` mkdir ckb-dev cd ckb-dev ``` ---------------------------------------- TITLE: Install Rust Components and Tools DESCRIPTION: Installs necessary Rust components (`llvm-tools-preview`) and cargo tools (`cargo-binutils`, `rustfilt`) required for fuzz testing and coverage analysis. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/script/fuzz/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` rustup component add llvm-tools-preview cargo install cargo-binutils cargo install rustfilt ``` ---------------------------------------- TITLE: Install and start CKB node systemd service DESCRIPTION: Downloads the CKB node systemd service file, copies it to the systemd directory, sets ownership and permissions, reloads the systemd daemon, and starts the CKB node service. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/linux-systemd/README.md#_snippet_3 LANGUAGE: bash CODE: ``` 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 ``` ---------------------------------------- TITLE: Install and start CKB miner systemd service DESCRIPTION: Downloads the CKB miner systemd service file, copies it to the systemd directory, sets ownership and permissions, reloads the systemd daemon, and starts the CKB miner service. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/linux-systemd/README.md#_snippet_7 LANGUAGE: bash CODE: ``` 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 ``` ---------------------------------------- TITLE: Example ProposalWindow Object (Text) DESCRIPTION: An example representation of the ProposalWindow structure, showing the `closest` and `farthest` fields with example values. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_151 LANGUAGE: text CODE: ``` ProposalWindow { closest: 2, farthest: 10 } ``` ---------------------------------------- TITLE: Install cargo-fuzz DESCRIPTION: Installs the `cargo-fuzz` tool, which is used to integrate fuzz testing into Rust projects. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/script/fuzz/README.md#_snippet_1 LANGUAGE: Shell CODE: ``` cargo install cargo-fuzz ``` ---------------------------------------- TITLE: TCP RPC Subscription Example (Bash) DESCRIPTION: Demonstrates how to establish a TCP connection using `telnet` and send JSON-RPC requests to subscribe (`subscribe`) and unsubscribe (`unsubscribe`) from the `new_tip_header` topic. Shows example request and response messages. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_128 LANGUAGE: bash CODE: ``` 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} ``` ---------------------------------------- TITLE: Example JSON for EpochView DESCRIPTION: This JSON snippet provides an example representation of the EpochView structure, showing the format and typical values for its fields. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_143 LANGUAGE: JSON CODE: ``` { "compact_target": "0x1e083126", "length": "0x708", "number": "0x1", "start_number": "0x3e8" } ``` ---------------------------------------- TITLE: MainLoggerConfig Filter Examples DESCRIPTION: Provides examples for configuring the `filter` field of the `MainLoggerConfig`, demonstrating how to set log levels globally or specifically for different CKB modules using a comma-separated string. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_148 LANGUAGE: Text CODE: ``` info ``` LANGUAGE: Text CODE: ``` info,ckb-rpc=debug,ckb-sync=debug,ckb-relay=debug,ckb-tx-pool=debug,ckb-network=debug ``` ---------------------------------------- TITLE: Query CKB Node RPC (shell) DESCRIPTION: Uses `curl` to send an RPC request to the running CKB node, assuming it's listening on port 8114. This specific request calls the `get_tip_header` method to retrieve the header of the current tip block. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/docs/quick-start.md#_snippet_3 LANGUAGE: shell CODE: ``` curl -d '{"id": 1, "jsonrpc": "2.0", "method":"get_tip_header","params": []}' \ -H 'content-type:application/json' 'http://localhost:8114' ``` ---------------------------------------- TITLE: Install and configure CKB binary DESCRIPTION: Copies the CKB binary to a system directory and sets appropriate ownership and permissions for execution. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/linux-systemd/README.md#_snippet_0 LANGUAGE: bash CODE: ``` sudo cp /path/to/ckb /usr/local/bin sudo chown root:root /usr/local/bin/ckb sudo chmod 755 /usr/local/bin/ckb ``` ---------------------------------------- TITLE: Example ProposalShortId Hex String (Text) DESCRIPTION: An example of a 10-byte fixed-length binary value encoded as a 0x-prefixed hex string, representing a ProposalShortId. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_150 LANGUAGE: text CODE: ``` 0xa0ef4eb5f4ceeb08a4c8 ``` ---------------------------------------- TITLE: Starting CKB Node (Shell) DESCRIPTION: Starts the CKB node process. This command launches the configured dev chain, making it ready to accept connections and process blocks. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/docs/dev-miner.md#_snippet_2 LANGUAGE: Shell CODE: ``` ckb run ``` ---------------------------------------- TITLE: Example CellWithStatus Live State (JSON) DESCRIPTION: This JSON snippet shows an example of a CellWithStatus object when the cell is in the "live" state. It includes the cell's data, output details (capacity, lock, type), and the status. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_141 LANGUAGE: json CODE: ``` { "cell": { "data": { "content": "0x7f454c460201010000000000000000000200f3000100000078000100000000004000000000000000980000000000000005000000400038000100400003000200010000000500000000000000000000000000010000000000000001000000000082000000000000008200000000000000001000000000000001459308d00573000000002e7368737472746162002e74657874000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b000000010000000600000000000000780001000000000078000000000000000a0000000000000000000000000000000200000000000000000000000000000001000000030000000000000000000000000000000000000082000000000000001100000000000000000000000000000001000000000000000000000000000000", "hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5" }, "output": { "capacity": "0x802665800", "lock": { "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hash_type": "data" }, "type": null } }, "status": "live" } ``` ---------------------------------------- TITLE: Response get_epoch_by_number JSON DESCRIPTION: Example JSON RPC response for a successful `get_epoch_by_number` call. It returns an `EpochView` object containing details like compact target, length, number, and start number for the requested epoch. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_25 LANGUAGE: JSON CODE: ``` { "id": 42, "jsonrpc": "2.0", "result": { "compact_target": "0x20010000", "length": "0x3e8", "number": "0x0", "start_number": "0x0" } } ``` ---------------------------------------- TITLE: Example CellOutput JSON DESCRIPTION: Provides an example JSON representation of a CellOutput object, detailing the cell's capacity, lock script, and optional type script. Cell outputs create new cells. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_140 LANGUAGE: json CODE: ``` { "capacity": "0x2540be400", "lock": { "code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5", "hash_type": "data", "args": "0x" }, "type": null } ``` ---------------------------------------- TITLE: Running CKB with Rich-Indexer (SQLite) DESCRIPTION: Command to start the CKB node with the default Rich-Indexer using the embedded SQLite database. This requires no extra configuration and initiates the indexing process. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/util/rich-indexer/README.md#_snippet_0 LANGUAGE: bash CODE: ``` ckb run -C --rich-indexer ``` ---------------------------------------- TITLE: Example CKB Block Header JSON DESCRIPTION: This JSON object provides an example structure and typical values for a CKB block header (HeaderView). It illustrates the format of fields like compact_target, dao, epoch, hash, nonce, number, parent_hash, proposals_hash, timestamp, transactions_root, extra_hash, and version. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_146 LANGUAGE: json CODE: ``` { "compact_target": "0x1e083126", "dao": "0xb5a3e047474401001bc476b9ee573000c0c387962a38000000febffacf030000", "epoch": "0x7080018000001", "hash": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40", "nonce": "0x0", "number": "0x400", "parent_hash": "0xae003585fa15309b30b31aed3dcf385e9472c3c3e93746a6c4540629a6a1ed2d", "proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp": "0x5cd2b117", "transactions_root": "0xc47d5b78b3c4c4c853e2a32810818940d0ee403423bea9ec7b8e566d9595206c", "extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "version": "0x0" } ``` ---------------------------------------- TITLE: CKB Indexer get_cells RPC Response Example DESCRIPTION: An example of the JSON response structure returned by the CKB Indexer get_cells RPC method, showing a list of cell objects. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_61 LANGUAGE: json CODE: ``` { "jsonrpc": "2.0", "result": { "last_cursor": "0x4058c5f491aba6d61678b7cf7edf4910b1f5e00ec0cde2f42e0abb4fd9aff25a63012a49720e721553d0614dff29454ee4e1f07d070700000000002adf830000000200000001", "objects": [ { "block_number": "0x2adf83", "out_point": { "index": "0x1", "tx_hash": "0x23ec897027c1d2a2b39e2446162bac182f18581be048cb3896ad695559b6839e" }, "output": { "capacity": "0x54b42b70b4", "lock": { "args": "0x2a49720e721553d0614dff29454ee4e1f07d0707", "code_hash": "0x58c5f491aba6d61678b7cf7edf4910b1f5e00ec0cde2f42e0abb4fd9aff25a63", "hash_type": "type" }, "type": null }, "output_data": "0x", "tx_index": "0x2" } ] }, "id": 2 } ``` ---------------------------------------- TITLE: Enable CKB node service on boot DESCRIPTION: Configures the systemd service for the CKB node to automatically start when the system boots. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/linux-systemd/README.md#_snippet_4 LANGUAGE: bash CODE: ``` sudo systemctl enable ckb.service ``` ---------------------------------------- TITLE: Example CellInfo JSON DESCRIPTION: Provides an example JSON representation of a CellInfo object, combining CellData and CellOutput fields to give a complete view of a cell. This structure is useful for representing a cell's full state. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_138 LANGUAGE: json CODE: ``` { "data": { "content": "0x7f454c460201010000000000000000000200f3000100000078000100000000004000000000000000980000000000000005000000400038000100400003000200010000000500000000000000000000000000010000000000000001000000000082000000000000008200000000000000001000000000000001459308d00573000000002e7368737472746162002e74657874000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b000000010000000600000000000000780001000000000078000000000000000a0000000000000000000000000000000200000000000000000000000000000001000000030000000000000000000000000000000000000082000000000000001100000000000000000000000000000001000000000000000000000000000000", "hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5" }, "output": { "capacity": "0x802665800", "lock": { "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hash_type": "data" }, "type": null } } ``` ---------------------------------------- TITLE: Example CellInput JSON DESCRIPTION: Provides an example JSON representation of a CellInput object, showing how it references a previous output cell (previous_output) and includes a since value for transaction validity constraints. Cell inputs consume existing cells. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_139 LANGUAGE: json CODE: ``` { "previous_output": { "index": "0x0", "tx_hash": "0x365698b50ca0da75dca2c87f9e7b563811d3b5813736b8cc62cc3b106faceb17" }, "since": "0x0" } ``` ---------------------------------------- TITLE: Example CellData JSON DESCRIPTION: Provides an example JSON representation of a CellData object, showing its content (as hex bytes) and hash. CellData represents the actual data stored within a cell. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_136 LANGUAGE: json CODE: ``` { "content": "0x7f454c460201010000000000000000000200f3000100000078000100000000004000000000000000980000000000000005000000400038000100400003000200010000000500000000000000000000000000010000000000000001000000000082000000000000008200000000000000001000000000000001459308d00573000000002e7368737472746162002e74657874000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b000000010000000600000000000000780001000000000078000000000000000a0000000000000000000000000000000200000000000000000000000000000001000000030000000000000000000000000000000000000082000000000000001100000000000000000000000000000001000000000000000000000000000000", "hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5" } ``` ---------------------------------------- TITLE: Subscription Push Message Example (JSON) DESCRIPTION: An example of the JSON-RPC message format that the CKB node pushes to a subscriber when a new event occurs on a subscribed topic. It includes the method name (`subscribe`), the result payload, and the subscription ID. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_130 LANGUAGE: json CODE: ``` { "jsonrpc": "2.0", "method": "subscribe", "params": { "result": { ... }, "subscription": "0x2a" } } ``` ---------------------------------------- TITLE: Enable CKB miner service on boot DESCRIPTION: Configures the systemd service for the CKB miner to automatically start when the system boots. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/linux-systemd/README.md#_snippet_8 LANGUAGE: bash CODE: ``` sudo systemctl enable ckb-miner.service ``` ---------------------------------------- TITLE: Example CellWithStatus Unknown State (JSON) DESCRIPTION: This JSON snippet provides a simple example of a CellWithStatus object when the cell's status is "unknown". It shows a null cell and the unknown status. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_142 LANGUAGE: json CODE: ``` { "cell": null, "status": "unknown" } ``` ---------------------------------------- TITLE: Configure CKB Logger Filter - All Info (Text) DESCRIPTION: Example configuration string for the `filter` field of `ExtraLoggerConfig`. Sets the log level to 'info' for all modules in the CKB node. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_144 LANGUAGE: text CODE: ``` info ``` ---------------------------------------- TITLE: Run CKB Fuzz Test DESCRIPTION: Executes a specific fuzz test target (`transaction_scripts_verifier_data1`) using `cargo-fuzz` with the nightly Rust toolchain, utilizing all available CPU cores. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/script/fuzz/README.md#_snippet_2 LANGUAGE: Shell CODE: ``` cargo +nightly fuzz run -j $(nproc) transaction_scripts_verifier_data1 ``` ---------------------------------------- TITLE: Calling get_pool_tx_detail_info RPC (JSON Request) DESCRIPTION: Example JSON request payload to invoke the `get_pool_tx_detail_info` RPC method, querying details for a specific transaction hash in the pool. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_120 LANGUAGE: JSON CODE: ``` { "id": 42, "jsonrpc": "2.0", "method": "get_pool_tx_detail_info", "params": [ "0xa0ef4eb5f4ceeb08a4c8524d84c5da95dce2f608e0ca2ec8091191b0f330c6e3" ] } ``` ---------------------------------------- TITLE: Get Transaction and Witness Proof RPC Response (JSON) DESCRIPTION: Example JSON RPC response payload for the `get_transaction_and_witness_proof` method. It returns the block hash, the transactions proof, and the witnesses proof. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_33 LANGUAGE: json CODE: ``` { "jsonrpc": "2.0", "result": { "block_hash": "0x7978ec7ce5b507cfb52e149e36b1a23f6062ed150503c85bbf825da3599095ed", "transactions_proof": { "indices": [ "0x0" ], "lemmas": [] }, "witnesses_proof": { "indices": [ "0x0" ], "lemmas": [] } }, "id": 42 } ``` ---------------------------------------- TITLE: Setup CKB user, group, and permissions DESCRIPTION: Creates a dedicated system user and group for running CKB, sets the home directory, disables login, and assigns ownership and permissions to the data directory and configuration files. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/linux-systemd/README.md#_snippet_2 LANGUAGE: bash CODE: ``` 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 ``` ---------------------------------------- TITLE: Get Transaction and Witness Proof RPC Request (JSON) DESCRIPTION: Example JSON RPC request payload for the `get_transaction_and_witness_proof` method. It takes an array of transaction hashes and an optional block hash to generate a Merkle proof. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_32 LANGUAGE: json CODE: ``` { "id": 42, "jsonrpc": "2.0", "method": "get_transaction_and_witness_proof", "params": [ [ "0xa4037a893eb48e18ed4ef61034ce26eba9c585f15c9cee102ae58505565eccc3" ] ] } ``` ---------------------------------------- TITLE: Initialize CKB data directory and config DESCRIPTION: Creates the data directory for CKB and initializes the configuration files for joining the mainnet, directing logs to stdout. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/devtools/init/linux-systemd/README.md#_snippet_1 LANGUAGE: bash CODE: ``` sudo mkdir /var/lib/ckb sudo /usr/local/bin/ckb init -C /var/lib/ckb --chain mainnet --log-to stdout ``` ---------------------------------------- TITLE: Request estimate_fee_rate CKB RPC (JSON) DESCRIPTION: Example JSON request payload for calling the `estimate_fee_rate` RPC method to get fee estimates. It includes the standard JSON-RPC fields: id, jsonrpc version, method name, and an empty params array. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_53 LANGUAGE: json CODE: ``` { "id": 42, "jsonrpc": "2.0", "method": "estimate_fee_rate", "params": [] } ``` ---------------------------------------- TITLE: Response get_deployments_info RPC (JSON) DESCRIPTION: Example JSON response payload returned by the `get_deployments_info` RPC method. It includes the current epoch, block hash, and detailed information about various deployments, including their state and threshold. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_127 LANGUAGE: json CODE: ``` { "id": 42, "jsonrpc": "2.0", "result": { "epoch": "0x1", "hash": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40", "deployments": { "testdummy": { "bit": 1, "min_activation_epoch": "0x0", "period": "0xa", "since": "0x0", "start": "0x0", "state": "failed", "timeout": "0x0", "threshold": { "numer": "0x3", "denom": "0x4" } } } } } ``` ---------------------------------------- TITLE: Initialize CKB with Secp256k1 Block Assembler (Shell) DESCRIPTION: This command initializes the CKB directory, setting the block assembler using a secp256k1 compressed public key. It combines the `ckb init` command with the output of `ckb cli secp256k1-lock --format cmd` to automatically provide the necessary `--ba-code-hash` and `--ba-arg` options. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/CHANGELOG.md#_snippet_3 LANGUAGE: Shell CODE: ``` ckb init $(ckb cli secp256k1-lock --format cmd) ``` ---------------------------------------- TITLE: WebSocket RPC Subscription Example (JavaScript) DESCRIPTION: Shows how to use JavaScript's `WebSocket` API to connect to a CKB node, set up an `onmessage` handler to receive push notifications, and send `subscribe` and `unsubscribe` JSON-RPC messages. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_129 LANGUAGE: javascript CODE: ``` 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"]}`) ``` ---------------------------------------- TITLE: Running CKB with Rich-Indexer (PostgreSQL) DESCRIPTION: Command to start the CKB node with the Rich-Indexer configured to use an external PostgreSQL database. Requires the --rich-indexer flag and the PostgreSQL connection settings in ckb.toml. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/util/rich-indexer/README.md#_snippet_5 LANGUAGE: bash CODE: ``` ckb run -C --rich-indexer ``` ---------------------------------------- TITLE: Starting CKB Built-in Miner (Shell) DESCRIPTION: Executes the built-in CKB miner. This command starts the mining process using the configuration defined in `ckb-miner.toml` to find blocks on the running CKB dev chain. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/docs/dev-miner.md#_snippet_4 LANGUAGE: Shell CODE: ``` ckb miner ``` ---------------------------------------- TITLE: View CKB Integration Test Options DESCRIPTION: Displays all available command-line options for running the CKB integration tests using `cargo run`. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/test/README.md#_snippet_2 LANGUAGE: bash CODE: ``` cargo run -- --help ``` ---------------------------------------- TITLE: Subscribe to CKB RPC Topic - JSON DESCRIPTION: Example JSON request to subscribe to a specific CKB RPC topic, such as `new_tip_header`. The `params` array contains the name of the topic to subscribe to. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_131 LANGUAGE: json CODE: ``` { "id": 42, "jsonrpc": "2.0", "method": "subscribe", "params": [ "new_tip_header" ] } ``` ---------------------------------------- TITLE: Example CellDep JSON DESCRIPTION: Provides an example JSON representation of a CellDep object, illustrating how it specifies a cell dependency with dep_type and out_point. Cell dependencies are used to reference cells containing code or data required by a transaction. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_137 LANGUAGE: json CODE: ``` { "dep_type": "code", "out_point": { "index": "0x0", "tx_hash": "0xa4037a893eb48e18ed4ef61034ce26eba9c585f15c9cee102ae58505565eccc3" } } ``` ---------------------------------------- TITLE: Export Testnet Configuration (Shell) DESCRIPTION: Initializes the current directory with configuration files specifically tailored for the Pudge testnet. Use this to set up a testnet node. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/docs/configure.md#_snippet_2 LANGUAGE: Shell CODE: ``` ckb init --chain testnet ``` ---------------------------------------- TITLE: Calling set_network_active RPC Method - JSON Request DESCRIPTION: Example JSON RPC request to call the `set_network_active` method. This method enables or disables all P2P network activity. The example shows disabling the network by passing `false`. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_97 LANGUAGE: json CODE: ``` { "id": 42, "jsonrpc": "2.0", "method": "set_network_active", "params": [ false ] } ``` ---------------------------------------- TITLE: Example LocalNode JSON Object DESCRIPTION: Illustrates the structure and typical values of the `LocalNode` JSON object, representing the local CKB node's status and configuration, including network addresses, connections, protocols, and version. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_147 LANGUAGE: JSON CODE: ``` { "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)" } ``` ---------------------------------------- TITLE: Calling set_ban RPC Method - JSON Request DESCRIPTION: Example JSON RPC request to call the `set_ban` method. This method is used to insert or delete an IP/subnet from the banned list. The example shows inserting a single IP with an absolute ban time and reason. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_93 LANGUAGE: json CODE: ``` { "id": 42, "jsonrpc": "2.0", "method": "set_ban", "params": [ "192.168.0.2", "insert", "0x1ac89236180", true, "set_ban example" ] } ``` ---------------------------------------- TITLE: CKB RPC Alert Type Example - JSON DESCRIPTION: Example JSON representation of the `Alert` RPC type. An alert is used to broadcast critical messages via the P2P network and includes fields like ID, version range, priority, message, expiration time, and signatures. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_135 LANGUAGE: json CODE: ``` { "id": "0x1", "cancel": "0x0", "min_version": "0.1.0", "max_version": "1.0.0", "priority": "0x1", "message": "An example alert message!", "notice_until": "0x24bcca57c00", "signatures": [ "0xbd07059aa9a3d057da294c2c4d96fa1e67eeb089837c87b523f124239e18e9fc7d11bb95b720478f7f937d073517d0e4eb9a91d12da5c88a05f750362f4c214dd0", "0x0242ef40bb64fe3189284de91f981b17f4d740c5e24a3fc9b70059db6aa1d198a2e76da4f84ab37549880d116860976e0cf81cd039563c452412076ebffa2e4453" ] } ``` ---------------------------------------- TITLE: Request get_indexer_tip CKB Indexer RPC (JSON) DESCRIPTION: Example JSON request payload for calling the `get_indexer_tip` RPC method within the Indexer module. It requests the current tip of the CKB indexer. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_55 LANGUAGE: json CODE: ``` { "id": 2, "jsonrpc": "2.0", "method": "get_indexer_tip" } ``` ---------------------------------------- TITLE: Initialize CKB Configuration Files (Shell) DESCRIPTION: Exports the bundled default CKB configuration files into the current working directory. This is the first step to customize node settings. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/docs/configure.md#_snippet_0 LANGUAGE: Shell CODE: ``` ckb init ``` ---------------------------------------- TITLE: Response get_indexer_tip CKB Indexer RPC (JSON) DESCRIPTION: Example JSON response payload returned by the `get_indexer_tip` RPC method. It provides the standard JSON-RPC fields and the result containing the block hash and block number of the indexed tip. SOURCE: https://github.com/nervosnetwork/ckb/blob/develop/rpc/README.md#_snippet_56 LANGUAGE: json CODE: ``` { "jsonrpc": "2.0", "result": { "block_hash": "0x4959d6e764a2edc6038dbf03d61ebcc99371115627b186fdcccb2161fbd26edc", "block_number": "0x5b513e" }, "id": 2 } ```