Example: A Minimal Script
A Minimal Scriptβ
As we have learned before, a Script that returns 0 is considered successful. The simplest CKB Script code in Rust looks like this:
pub fn program_entry() -> i8 {
0
}
The simplest CKB Script code, often called always-success, always returns 0 as its return code. You might think this simplest Script code is also the dumbest one because if you use this as your Lock Script, your tokens could be taken by anyone.
However, this simplest Script proves useful in a development environment. When testing Scripts on a local blockchain for your dApp, you might allow the testing Cells to have an always-success Lock Script to simplify your testing workflow.
Despite its utility, the always-success Script is not very interesting due to its simplicity.
Here we will start with a more interesting idea:
Personally I dislike carrot. I do know that carrot is great from a nutritional point of view, but I still want to avoid it due to the taste. Now what if I want to set a rule, that none of my Cells on CKB has data that begin with the word
carrot?
Letβs write a Script code to ensure this.
Below is a step-by-step guide, and you can also clone the full code example from the Github at carrot-script.
Carrot-Forbidden Scriptβ
The first step is to create a new Script project. We use ckb-script-templates for this purpose. Make sure you have the following dependencies installed: