Connecting to the CKB network is extremely easy and only requires running one node on a machine. Once you've connected to the CKB network, you can use the RPC interface to interacting with the node.
About Nervos CKB
CKB is the layer 1 of Nervos Network, a public/permissionless blockchain. CKB uses Proof of Work and improved Nakamoto consensus to achieve maximized performance on average hardware and internet conditions without sacrificing decentralization and security, which are the core values of blockchain.
Run A CKB Node
You’ll need to deploy nodes to connect with the CKB network, read data from the blockchain, and broadcast transactions onto the CKB network. For more information, please see Run CKB With The Latest Release or Run CKB With Docker. You may also need an indexer to index live cells and transactions, and then you can try CKB Indexer. If you are looking for a one-stop solution that includes both node and indexer, you can try Perkins' Tent.
- OS: Ubuntu 18.04 LTS x86_64 (recommended)
- Processor: Mainstream CPU 4c
- RAM: 4G
- Storage: 100G SSD
Writing an integration
Before starting your integration, we recommend reading CKB Transaction Structure RFC to familiarize yourself with an essential data structure in CKB. Some common issues and corresponding example solutions (using CKB SDK Java) are listed below.
Generating and Parsing Address
CKB Address Format is an application-level recommendation for cell lock script display. The lock script consists of three key parameters, including code_hash, hash_type, and args. CKB address packages lock script into a single line, verifiable, and human read friendly format.
- Generate an Address: JavaAddressGeneratorTest or JsAddressGeneratorTest.
- Parse an Address: JavaAddressParserTest or JsAddressParserTest.
- Generate Private key: We won’t generate private keys for you on SDK. You need to produce it on your own, you can try web3j. CKB default lock script code using the same secp256k1 signature verification algorithm as used in bitcoin. For more information, please see SECP256k1Blake160.
The transmission of CKB between addresses is divided into three steps, constructing, signing, and submitting the transaction. You can use the following example to understand how to transfer CKB between addresses SingleSigWithCkbIndexerTxExample and TransferAllBalanceWithCkbIndexerExample. If you want to know the signing process, you can check How to sign the transaction. For the calculation of transaction fees, please see the Transaction Fee.
Retrieving data from node
- get_tip_block_number Returns, the number/height of blocks in the longest blockchain.
- get_block_by_number Get block by number/height.
- get_transaction Returns the information about a transaction requested by transaction hash. For more information, please see the CKB JSON-RPC protocols. Other available SDK: CKB SDK JS.
How to manage cells(like UTXO set)
Cell management mainly affects cell collection and address balance display. There are many ways to manage cells; here are two typical example solutions.
- Use your UTXO management framework to combine CKB JSON-RPC protocols to scan the entire CKB blockchain.
- Use CKB Indexer to collect cells and display balance.
- get_cells_capacity Returns the live cells total capacity by the lock or type script. You can use this RPC to display address balance.
Once you’ve fully integrated with the CKB network, please test on the testnet and mainnet.
When you integrate CKB into your system, you may face some challenges. Here is a Q&A that may help you.