see others md file :
- IOTA Smart Contract (ISC) Deploy
- IOTA Smart Contract (ISC) Compile
- IOTA Smart Contract (ISC) Interaction
- little DID doc (to review)
- Wasp (commit 3cd522ede8b496c0acc34221d56e2bfc76effe39 (HEAD -> develop, origin/develop, origin/HEAD))
- Go 1.19.5
- Linux/Wsl
- Docker
- Rust
- https://blog.iota.org/iota-smart-contracts-protocol-alpha-release/ IOTA Smart contract explained
- https://docs.rs/identity_iota/latest/identity_iota/ IOTA DID rust doc
- https://wiki.iota.org/shimmer/smart-contracts/guide/core_concepts/smart-contract-anatomy/ anatony of a smart contract in IOTA
Run docker-compose up
to start the setup.
Press Ctrl-C
to shut down the setup, but don't press it twice to force it. Otherwise, you can corrupt the Hornet database.
You can also shut down the setup with docker-compose down
in a new terminal.
Run docker-compose down --volumes
to shut down the nodes and to remove all databases.
If you made changes to the Wasp code and want to use it inside the setup, you need to recreate the Wasp image.
Run docker-compose build
Run wasp-cli init
to generate a seed, and you are ready to go.
seed generated : 0x8a79b784060d66b51515ad43d45eefd76034d17c2dce39f1a71a9155c48dcdcb do not use this in mainnet
The nodes will then be reachable under these ports:
-
Wasp:
- API: http://localhost:9090
- Dashboard: http://localhost:7000 (username: wasp, password: wasp)
- Nanomsg: tcp://localhost:5550
-
Hornet:
- API: http://localhost:14265
- Faucet: http://localhost:8091
- Dashboard: http://localhost:8081 (username: admin, password: admin)
- To test smart contracts and run unit tests against smart contract functionality, the “solo” environment written in Go can be used.
- Goshimer not used anymore for rust smart contract
- A Wasp Node has it's own wallet. Where we need to send funds to, to deploy smart contracts.
- Smart contracts for the IOTA network can be implemented in Rust and then compiled to a WebAssembly file.
- Rust building env
cargo new <project_name>
* Cargo.toml # define dependencies of the smart contract
* src/lib.rs # Source of the smart contract
* pkg/
* target/
- compile a rust lib to wasm :
- Create a new Rust project using cargo
- add the IOTA contract Library to the
Cargo.toml
file - Compile the contract using the
cargo build --target wasm32-unknown-unknown
command. - Deploy the compiled contract to the IOTA Tangle by sending a transaction containing the WASM bytecode.
- To deploy a ISC with
wasp-cli
you need to be in the same file than thewasp-cli.json
config file.
- wasp-cli is a command line tool for interacting with Wasp and its smart contracts.
- To generate ISC use the schema tool, it is a tool that make use of the yaml format to generate rust contract. Check this link for more information : https://wiki.iota.org/shimmer/smart-contracts/guide/wasm_vm/schema/
- We need to have the wasp repo cloned localy.
- After that add the bin folder inside the Wasp repo to the Path
export PATH=$PATH:$(go env GOPATH)/bin
assuming you already have Go - After that inside the wasp repo use
make wasm
to install schema tool - we then need to create a Schema space with
schema -init nameOfyourEnv
- then go inside this folder
- You will see a
schema.yaml
file, this is the core of out Smart contract, by specifying each state, params and functions into this file it will generate all you core Smart contract. - to generate the code use
schema -rs
for rust code orschema -go
for go. - then move inside the
nameOfyourEnvimpl
folder created, you will see thefuncs.rs
file, it's the only file you will need to change to create the logic of your contract. - to build go inside the
nameOfyourEnvwasm
folder created, and runwasm-pack build
- You now have the wasm file located on the
pkg
folder
-
use Docker on WSL2 :
- Download Docker Desktop for Windows.
- From the Docker menu, select Settings and then General.
- Select the Use WSL 2 based engine check box.
- Select Apply & Restart.
-
Clean cargo build
cargo clean
-
add a lib to Cargo.toml via cmd line ex :
cargo add serde_with
-
unregister a wsl distrib :
wsl --unregister <distrib_name>
- to get the distrib name use :
wsl -l -v
- to get the distrib name use :
-
to get feedback after deployting use
wasp-cli chain request <hash given after deployement>
https://wiki.iota.org/shimmer/smart-contracts/guide/wasm_vm/schema/ https://wiki.iota.org/shimmer/smart-contracts/guide/wasm_vm/typedefs/ https://wiki.iota.org/shimmer/smart-contracts/guide/wasm_vm/state/ https://wiki.iota.org/shimmer/smart-contracts/guide/wasm_vm/params/
System has not been booted with systemd as init system (PID 1). Can't operate.
sudo nano /etc/wsl.conf
[boot]
systemd=true
wsl.exe --shutdown
error[E0463]: can't find crate for core
rustup target add wasm32-unknown-unknown
error: failed to run custom build command for libsodium-sys v0.2.7
solution : libsodium-sys cant be generated into wasm.
error: sudo: add-apt-repository: command not found
solution :
sudo apt update
sudo apt install software-properties-common
sudo apt update
error : Cannot make install into wasp repo
solution : The problem was that some functionnalities used needed go aboce 1.16, but i had 1.13 installed into /usr/bin/go. But the want i wanted to use was located in /usr/local/go. I had to delete the /usr/bin one. And added the /usr/local one to the path.
error : cannot use "The version of quic-go you're using can't be built on Go 1.20 yet
solution : deletin go and installing version 1.19 (aka the one specified in the go.mod file)
error : cannot find command schema
solution : Go into the wasp repo and and the bin folder to path with export PATH=$PATH:$(go env GOPATH)/bin
error : Missing Lifetime Operator when generating wasm with wasm-pack build
solution : You just need to add <'a>
to all the struct
and ScFunc
in the contract.rs
file.