CKB Studio — Hello World Tutorial

Jonathan Caras
NervOS CKB Israel
Published in
8 min readApr 17, 2020

Printing “Hello World!” to the NervOS Blockchain.

This tutorial will show you step by step how to publish simple text to a local instance of the NervOS CKB blockchain.

We will be using Mac 10.15.4, but any recent version should be ok. The IDE is CKB Studio from Obsidian. If you have never used CKB Studio, follow this tutorial I wrote that will walk you through installing. I am using CKB Studio v0.2.2.

If you are not familiar with NervOS CKB, I suggest you read our article on why we invested in NervOS.

Step: 1 Fire up CKB Studio and make sure everything is up to date

Obsidian is hard at work getting to v1.0, so you might be using a different version than I am (0.2.2). That should be ok for this tutorial.

Start off by running Docker.

I need to upgrade Docker, which is just a click away….

Tap “Install Update” you may need to put in your Mac password.

The upgrade completed quickly, and now just click “Get Started”

Step 2: Get a local version of CKB running on your computer

Now that you have CKB Studio up and running, it’s time to spin up a local version of CKB.

Tap Network on the top right.

Tap “CKB Versions”

Tap “Install”, select v0.31.0 (the most recent version at the time of this writing)

You may need to download the code. This happens automatically, and finished quickly.

Now you have a shiny new version of CKB installed on your computer.

Move your eyes down to the bottom left to the purple button with the Key on it.

You will now make a new Key Pair, this will create a wallet, a miner, and some cells with CBK in the Genesis block. Click “Create”

Now that you have a Public/Private key-pair and address, press “Save”

You will now see your address listed in your Keypair Manager

Now look in the top right, click the green “New Instance” button.

In the New Instance menu, add an instance name “HelloWorld” (it will freeze if you try to put a space in the instance name).

Check the CKB Version matches what we installed, and the miner is the account we created earlier.

Now, back in the main window, you will see your CKB Instance all ready to launch.

Click “Start”

You will see the gears start to turn as your NervOS blockchain will start up, complete with a new wallet, and miner.

Tap on the miner tab on the bottom left, to see how many blocks your hungry miner has found. (good job little miner!)

Step 3: Building a Transaction

First thing we need to do is get some tokens to be able to pay for our transaction. Good thing we got some in the Genesis block, and seeing as how we are the only miner on our local blockchain, we also get all those sweet block rewards.

Open back up your Keypair manager (bottom left) and copy your address.

Copy this address in the grey address window in the middle of your screen. It might say “Invalid Address” or something similar. Press the refresh button on the far left and you will see the cells of block rewards you are getting for your hard work as a miner.

Drag in a block to the Input window in the top left. You should see it appear like this.

Now let’s drag in another one for good measure.

Tap on the tab “TX Constructor” on the top middle.

Tap the green “+ New” button, to the right of the word “Outputs”

Now, lets fill in a capacity of 4000 CKB. (we got this from the cells you dragged earlier.

Now tap on the address under “Lock Script” and you will see your local wallet address. Select it.

Now we type “Hello World!” in the Data section. Make sure you are inputting it in the format of UFT8.

Step 4: Push your data to the blockchain via a new Transaction

Your screen should look like mine below. 2 cells with about 2000 CKB in each cell in Inputs, Output with 4000 CKB capacity, locked to your address, and our data package of “Hello World!”.

Tap the purple “Push Transaction” button.

Here is the raw data that will be sent to the blockchain in a transaction.

Two things interst us for this tutorial.

First in the “outputsData”, which contains the HEX equivalent of the data we are injecting to the blockchain.

“outputsData”: [

“0x2248656c6c6f20576f726c642122”

],

Let’s open up a HEX to ASCII converter and verify that the data we are putting onchain is the data we want.

https://www.rapidtables.com/convert/number/hex-to-ascii.html

Great! We are just about ready to submit our transaction.

The second area of our transaction to look at is the witness, which is our signing, notice how this is empty. Thats because we have not yet signed the transaction. We will do that in a moment.

“witnesses”: [

]\

Click the green button “ Signed with [your address]”, then push the transaction via the purple “Push Transaction” button.

And thats it! You should have a little pop up (it disappeared too quickly for my screenshot)

Step 5: Verify that the data was submitted to the chain

Now that we created, signed and submitted a transaction, we need to verify we got what we wanted on-chain.

Tap “Explorer” on the top right.

Go copy your address again, this is the address we want to view in the local explorer.

Paste this address into the grey address box.

Tap the refresh button to the left.

You will see many Cellbases for blocks at various block heights. Notice how they are all about the same about of CKB.

Press the load more button to see older blocks, be fast because this blockchain keeps churning, and we are manually looking for a block with our 4000 CKB.

Yay we found our block!

This block will have extra data. This is the data we submitted to the blockchain!

Notice that the data is in HEX and it matches the data we wanted to submit.

Highlight your mouse over the HEX to see the ASCII equivalent.

And there we see our “Hello World!” string.

Big thanks to Tannr and Matt Quinn for helping to make this tutorial happen.

In our next tutorial we will demo writing a smart contract using CKB.

Stay Tuned.

Feel free to follow me on Twitter @madcapslaugh. and to join our NervOS VR meetup group (you can come to the meet ups via VR, smartphone or laptop)

--

--