Introduction
In this blog, we will be going through building on the note-taking application sui blockchain. This series include:
- Part One: setup and basic contract.
- Part Two: multiple data-type of notes.
- Part Three: encryption on chain (SEAL).
- Part Four: Storage on-chain (Walrus).
- Part Five: Sui SDK integration.
Part One: (Basic Contract)
We will be writing the a basic smart contract for on note-taking app.
Steps
- Install the Sui SDK and set it to testnet.
- Run
sui move new <contract-name>
to create a new contract. - In the
sources
folder, navigate to<contract-name>.move
.
Breakdown
- Sui Move contracts are a collection of
.move
files called a package. - Each file can contain modules (a group of structs, objects, and functions).
Creating the Note Struct as an NFT
public struct Note has key, store {
id: UID,
title: String,
content: String,
timestamp: u64,
}
Let's create functions to interact with the Note
struct:
// Creates a Note and returns it to the user
public fun create(title: String, content: String, clock: &Clock, ctx: &mut TxContext): Note {
let note = Note {
id: object::new(ctx),
title,
content,
timestamp: clock.timestamp_ms(),
};
note
}
// Edits only the content of a Note
public fun edit(note: &mut Note, content: String) {
note.content = content;
}
// Reads the content of a Note
public fun view(note: &Note): (ID, String, String, u64) {
(object::id(note), note.title, note.content, note.timestamp)
}
// Deletes a Note
public fun delete(note: Note) {
let Note { id, .. } = note;
id.delete();
}
Notice that we need the Note
object from the user to edit, read, or delete it. These operations require different permission levels.
Next Up
We will upgrade the contract to accepted a different data types as content.