Skip to main content

Setting up a project

Project setup can be broken down to 2 steps broadly, which are boiler plate generation and updating project name.

Boilerplate code

To initialise a project with boilerplate code:


wasmkit init <project-name>

To generate boilerplate code using a particular template (template names can be found at https://github.com/kubiklabs/wasmkit-templates):


wasmkit init <project-name> <template-name>


wasmkit init yellow # example
wasmkit init yellow cw20 # example with template

The generated directory will have the following initial structure:


.
├── Cargo.toml
├── README.md
├── contracts
│   └── counter
│   ├── Cargo.toml
│   ├── LICENSE
│   ├── README.md
│   ├── examples
│   │   └── schema.rs
│   └── src
│   ├── contract.rs
│   ├── error.rs
│   ├── lib.rs
│   ├── msg.rs
│   └── state.rs
├── package.json
├── scripts
│   └── sample-script.ts
├── test
│   ├── sample-test.ts
│   └── tsconfig.json
├── tsconfig.json
└── wasmkit.config.js
7 directories, 17 files

The contracts/ directory has all the rust files for the contract logic. scripts/ directory can contain .ts scripts that user can write according to the use case, a sample script has been added to give some understanding of how a user script should look like. test/ directory can contain .ts scripts to run tests for the deployed contracts.

Updating name of contract

Replace appearances of sample-project from following files to your project name (yellow in this case):


grep -r "sample-project"
./contracts/counter/README.md:const contract = new Contract('sample-project');
./README.md:const contract = new Contract('sample-project', runtimeEnv);
./package.json: "name": "sample-project",


sed -i 's/sample-project/yellow/g' `grep -ril 'sample-project' *`

Now compiling using wasmkit compile would create following structure in artifacts/ directory:


artifacts
├── contracts
│   └── counter.wasm
├── schema
│   └── counter
│   ├── execute_msg.json
│   ├── instantiate_msg.json
│   └── query_msg.json
└── typescript_schema
└── CounterContract.ts
5 directories, 5 files