Skip to content

Commit

Permalink
Updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
DariuszDepta committed Sep 11, 2024
1 parent f500ca9 commit 07cefa4
Showing 1 changed file with 90 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
tags: ["multitest", "getting started", "counter", "CosmWasm"]
---

import { Card, Cards } from "nextra/components";
import { Callout, Card, Cards } from "nextra/components";

# Counter written in CosmWasm

Expand All @@ -16,7 +16,7 @@ feel free to check the detailed explanations provided for each code snippet.

### Cargo.toml

```toml filename="Cargo.toml" copy
```toml showLineNumbers filename="Cargo.toml" copy
[package]
name = "counter"
version = "0.1.0"
Expand Down Expand Up @@ -48,7 +48,94 @@ cw-multi-test = { version = "2", features = ["cosmwasm_2_0"] }
<Card title="🦘  Skip this time" href="#librs" icon="" children="" />
</Cards>

(todo: extremely detailed explanation)
`Cargo.toml` file is a configuration file for a Rust project, in our case for a smart contract
written in Rust. Here's a detailed explanation of each section and what it's doing.

**\[package\]**

```toml showLineNumbers{1} filename="Cargo.toml" copy
[package]
name = "counter"
version = "0.1.0"
edition = "2021"
```

- `[package]` section provides metadata about the Rust package (smart contract library in our case).
- `name = "counter"` specifies the name of the package, it's named **counter** like our smart
contract.
- `version = "0.1.0"` indicates the current version of the package and the counter smart contract.
- `edition = "2021"` specifies the Rust edition being used; editions in Rust are sets of language
and compiler improvements, with 2021 being one of the latest editions at the time, providing the
latest features and enhancements.

**\[lib\]**

```toml showLineNumbers{8} filename="Cargo.toml" copy
[lib]
crate-type = ["cdylib", "rlib"]
```

- `[lib]` section specifies settings for building the library.
- `crate-type` enumerates types of libraries to be produced during compiling.
- `"cdylib"` specifies that the package will be compiled as a C-compatible dynamic library; which is
required for smart contracts to run on the CosmWasm runtime.
- `"rlib"` specifies a Rust library file that can be used as a dependency for other Rust projects,
in our case for other smart contracts.

**\[features\]**

```toml showLineNumbers{11} filename="Cargo.toml" copy
[features]
# use library feature to disable all instantiate/execute/query exports
library = []
```

- `[features]` section defines optional features for the Rust package.
- `library = []` defines a feature named "library", which by convention disables exporting smart
contract entry-points when set.

**\[dependencies\]**

```toml showLineNumbers{15} filename="Cargo.toml" copy
[dependencies]
cosmwasm-schema = "2"
cosmwasm-std = { version = "2" }
cw-storage-plus = "2"
schemars = "0.8"
serde = "1.0"
```

- `[dependencies]` section lists the libraries that the package depends on.
- `cosmwasm-schema` is used for generating JSON schemas from Rust data structures, which is useful
for documentation and ensuring compatibility of messages and queries.
- `cosmwasm-std` is the standard library for CosmWasm contracts, providing common types and
utilities needed for interacting with the CosmWasm runtime.
- `cw-storage-plus` is a library that provides advanced storage abstractions and utilities on top of
the basic storage capabilities in CosmWasm, making it easier to manage state within contracts.
- `schemars` is a library for generating JSON schemas, which complements `cosmwasm-schema` by
providing additional features for schema generation.
- `serde` is a widely used serialization library in Rust, allowing easy conversion of Rust data
structures to and from formats like JSON, which is crucial for data interchange in smart
contracts.

**\[dev-dependencies\]**

```toml showLineNumbers{22} filename="Cargo.toml" copy
[dev-dependencies]
cw-multi-test = { version = "2", features = ["cosmwasm_2_0"] }
```

- `[dev-dependencies]` section lists dependencies that are only needed for development and testing.
- `cw-multi-test` is a name of **`MultiTest`** library, and should **ALWAYS** 🚨 be placed in
`[dev-dependencies]` section.

Overall, this Cargo.toml file configures a Rust project for a CosmWasm-based smart contract. It sets
up the basic package details, specifies how the contract should be compiled, defines dependencies
for core functionality and testing, and includes features to enable or disable certain parts of the
contract code. This setup ensures the contract can be developed, tested, and deployed effectively
within the CosmWasm ecosystem.

---

### lib.rs

Expand Down

0 comments on commit 07cefa4

Please sign in to comment.