Creating Zink Project
For creating a zink project, we need to install the zink toolchain zinkup
from crates.io
first, the package manager elko
will be installed along
with other tools:
cargo install zinkup
elko -h
Now, let’s create a zink project:
elko new my-awesome-contract
Created zink project `my-awesome-contract`
the Zink projects are based on the cargo projects, you can install
dependencies you need with cargo
, the basic Cargo.toml
will be like:
# ...
[lib]
crate-type = [ "cdylib" ]
[dependencies]
zink = "0.1.0"
# ...
open my-awesome-contract/src/lib.rs
//! my-awesome-project
#![no_std]
// For the panic handler.
#[cfg(not(test))]
extern crate zink;
/// Adds two numbers together.
#[no_mangle]
pub extern "C" fn addition(x: u64, y: u64) -> u64 {
x + y
}
you’ll see a standard WASM
library in rust:
#![no_std]
means we don’t need the std library in this project.extern crate zink
is for importing the panic handler from libraryzink
for this project.#[no_mangle]
is for exporting functionaddition
to WASM, and this will be one the methods of your contracts.