Welcome, brave coder! Your mission, should you choose to accept it, involves inscribing the message "Hello Common Knowledge Base!"
into a cell on the CKB testnet using the mighty Lumos, a powerful JavaScript/TypeScript library crafted specifically for Nervos CKB. Once you've accomplished your mission, you'll uncover and verify the message on the CKB explorer.
Before embarking on your mission, it's beneficial to familiarize yourself with:
However, if you're a rookie, fear not! This mission is designed to equip you with the necessary skills, step by step.
Although some of the complexity is wrapped up, intuitively writing "Hello Common Knowledge Base!" into a cell on CKB testnet is really just three steps
:
git clone https://github.com/Flouse/ckb-tthw.git
cd ckb-tthw/js
# Install dependences such as @ckb-lumos, etc.
npm install
# Let's run it.
npm run start
# Result
# Transaction 0x39d6d7b6129b7e418c9ea6a353a5d85eb69f9ee5b4c7c43223fe0fad2b0e6200 sent.
# See https://pudge.explorer.nervos.org/transaction/0x39d6d7b6129b7e418c9ea6a353a5d85eb69f9ee5b4c7c43223fe0fad2b0e6200
Would you like to change onChainMemo
string and re-run it again?
Let's dive into two functions that take up most of the code space. The code and comments are quite self-explained.
This function creates a new transaction that adds a cell with the proposed on-chain message.
- Create a transaction skeleton that serves as a blueprint for the final transaction.
- Define the output cell, which includes the capacity and lock script, and add it to the transaction skeleton, which is a mutable data structure used to construct a CKB transaction incrementally.
- Modify the transaction skeleton to include the necessary capacity to cover the output cell by injecting enough input cells.
- Pay the transaction fee by
payFeeByFeeRate
function, again, provided by Lumos.
This function is self-explanatory:
- Sign the transaction skeleton using a test private key.
- Send the signed transaction to CKB testnet.
The cell data is the hexadecimal format of "Hello Common Knowledge Base!".
You might want to uncover your message on CKB Explorer by
- Go to your output URL
- Click on Cell Info of Output#0, then go to the
Data tab
- Copy the number string after
0x
- Paste it into CypherChef's magic tool to decode.
In this tutorial, you learned how to write a message into a cell on CKB testnet using Lumos. You also learned how to check the transaction on CKB explorer. Lumos provides a set of helper functions that make it easy to interact with the CKB blockchain. With Lumos, you can easily create, sign, and send transactions to the CKB blockchain.
- CKB basic theoretical knowledge
- CKB basic practical operation
- Lumos Examples
- Preview and interact with
simple transfer
code online through codesandbox. https://codesandbox.io/s/github/ckb-js/lumos/tree/develop/examples/secp256k1-transfer?file=/lib.ts - etc.
- Preview and interact with