This is a note where I write what I have learned so far in Internet Computer Protocol.
Installation
What I did is just cloning the repository
git clone --branch=0.20.1 https://github.com/dfinity/sdk --depth=1 dfinity-sdk
and just compile the sdk away.
pushd dfinity-sdk
cargo build --release -j2
I don’t need all that much cores.
What are those git flags?
To explain a bit why there is
--branch
and--depth
, I added--depth=1
so I have a shallow-copy of the repository at depth 1. I also added--branch=0.20.1
to point to a branch or tag. Here, I chose tag0.20.1
. This avoids unnecessary fetching of data of about possibly 1k+ commits.This also avoids me wasting huge amounts of space when I only one specific history of the repository.
Following over the tutorial
Since I use Rust, I guess I should use the Rust SDK. Although, I am kind of interested of using Motoko but for now, let’s put it aside.
The documentation is informative — https://internetcomputer.org/docs/current/developer-docs/getting-started/hello-world. Okay, I will begin with a simple Hello World.
But I have waited a bit for this to compile.
And yes, I made a mistake okay? Because I copied an untagged branch or commit, hence, the copy.
Now that it was compiled, I can run dfx new hello-icp
.
Selected
- Rust
- No frontend canister
- No additional features
Oh that’s a cute logo right there.
Checking the newly created directory
So it seems like I found some things here in the hello-icp
directory.
.
├── Cargo.lock
├── Cargo.toml
├── dfx.json
├── README.md
└── src
└── hello-icp-backend
├── Cargo.toml
├── hello-icp-backend.did
└── src
└── lib.rs
It seems it is a newly created Rust project that follows a workspace configuration as shown from the TOML file
[workspace]
members = [
"src/hello-icp-backend"
]
resolver = "2"
I am going to check what’s the contents of the members. Specifically, I am just going to check the Cargo.toml
file.
[package]
name = "hello-icp-backend"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]
[dependencies]
candid = "0.10"
ic-cdk = "0.13"
ic-cdk-timers = "0.7" # Feel free to remove this dependency if you don't need timers
Aha! I guess dfx
is a good tool to setup a new project after all. But maybe in the future I don’t need it but it’s still a good idea that this tool exists.
Seems it only has a hello world because the library crate only has
#[ic_cdk::query]
fn greet(name: String) -> String {
format!("Hello, {}!", name)
}
But I haven’t tested that yet. I will check tomorrow, it seems the documentation made a mistake or something because dfx deploy
does not work because the setting up a new project is missing the part that it does need an identity created before deployment.
I will sleep for now and update this the next day.