Skip to content

Commit c53b9a0

Browse files
committed
Added Contrct creation chapter.
1 parent 5cd4975 commit c53b9a0

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Writing contracts",
3+
"position": 1,
4+
"link": {
5+
"type": "doc",
6+
"id": "introduction"
7+
}
8+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# Contract creation
6+
7+
The easiest and recommended way to start working on a new CøsmWasm contract is to generate it from
8+
the [`cw-template`](https://github.com/CosmWasm/cw-template).
9+
10+
```shell title="terminal"
11+
cargo generate CosmWasm/cw-template
12+
```
13+
14+
The [`cw-template`](https://github.com/CosmWasm/cw-template) will generate a lot of code for you.
15+
Because this tutorial aims to guide you step-by-step through the process of creating your first
16+
contract, for now, we will omit the use of the template and show you how to create it from the start.
17+
18+
## New project
19+
20+
As smart contracts are Rust library crates, we will start with creating one:
21+
22+
```shell title="terminal"
23+
cargo new --lib ./contract
24+
```
25+
26+
You created a simple Rust library, but it is not yet ready to be a smart contract.
27+
The first thing to do is to update the **Cargo.toml** file:
28+
29+
```toml title="Cargo.toml"
30+
[package]
31+
name = "contract"
32+
version = "0.1.0"
33+
edition = "2021"
34+
35+
[lib]
36+
crate-type = ["cdylib"]
37+
38+
[dependencies]
39+
cosmwasm-std = { version = "3", features = ["staking"] }
40+
```
41+
42+
As you can see, we have added a `crate-type` field in the library section. Generating the `cdylib` is
43+
required to create a proper web assembly binary. The downside of this is that such a library cannot
44+
be used as a dependency for other Rust crates. For now, it is not needed, but later we will show
45+
how to approach reusing contracts as dependencies.
46+
47+
Additionally, there is one core dependency for smart contracts: the
48+
[`cosmwasm-std`](https://docs.rs/cosmwasm-std/latest/cosmwasm_std/). This crate is a standard
49+
library for smart contracts. It provides essential utilities for communication with the outside
50+
world and a couple of helper functions and types. Every smart contract we will build will use this
51+
dependency.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Writing CøsmWasm contracts
2+
3+
This section is a step-by-step guide on how to write CøsmWasm contracts.

0 commit comments

Comments
 (0)