Skip to content

Commit 2dda500

Browse files
authored
Fixed chapter 06 (#11)
1 parent 2e51ab8 commit 2dda500

File tree

5 files changed

+235
-199
lines changed

5 files changed

+235
-199
lines changed

docs/tutorial/platform/04-hello-world.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ Now you have your bytecode stored on-chain, but no smart contract has been deplo
707707
You can confirm this with:
708708

709709
<Tabs groupId="local-docker">
710-
<TabItem value="Local" active>
710+
<TabItem value="Local" default>
711711
```shell
712712
./build/wasmd query wasm list-contract-by-code $ns_code_id
713713
```
@@ -742,7 +742,7 @@ To make it easy, you pick Alice as the minter.
742742
Get her address:
743743

744744
<Tabs groupId="local-docker">
745-
<TabItem value="Local" active>
745+
<TabItem value="Local" default>
746746
```shell
747747
alice=$(./build/wasmd keys show alice \
748748
--keyring-backend test \
@@ -787,7 +787,7 @@ Which should return something like:
787787
With the message ready, you can send the command to instantiate your first smart contract:
788788

789789
<Tabs groupId="local-docker">
790-
<TabItem value="Local" active>
790+
<TabItem value="Local" default>
791791
```shell
792792
./build/wasmd tx wasm instantiate $ns_code_id "$ns_init_msg_1" \
793793
--label "name service" --no-admin \
@@ -825,7 +825,7 @@ ns_instantiate_txhash_1=9881879B2A7663638D6DA81D6F9ECC7DBF8AA12B105817B06A761749
825825
Now that the transaction has likely been confirmed, you can retrieve it:
826826

827827
<Tabs groupId="local-docker">
828-
<TabItem value="Local" active>
828+
<TabItem value="Local" default>
829829
```shell
830830
./build/wasmd query tx $ns_instantiate_txhash_1 \
831831
--output json | jq
@@ -852,7 +852,7 @@ The authoritative way to get this information is to get it from the events,
852852
more precisely at the event of type `"instantiate"`:
853853

854854
<Tabs groupId="local-docker">
855-
<TabItem value="Local" active>
855+
<TabItem value="Local" default>
856856
```shell
857857
./build/wasmd query tx $ns_instantiate_txhash_1 \
858858
--output json | jq '.events[] | select(.type == "store_code") .attributes[] | select(.key == "code_id") .value'
@@ -897,7 +897,7 @@ Your smart contract address is `wasm14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr
897897
which you can retrieve with:
898898

899899
<Tabs groupId="local-docker">
900-
<TabItem value="Local" active>
900+
<TabItem value="Local" default>
901901
```shell
902902
ns_addr1=$(./build/wasmd query tx $ns_instantiate_txhash_1 \
903903
--output json | jq -r '.events[] | select(.type == "instantiate") .attributes[] | select(.key == "_contract_address") .value')
@@ -921,7 +921,7 @@ With the contract instantiated, you can query a few things about it.
921921
It is possible to get the same information by code id.
922922

923923
<Tabs groupId="local-docker">
924-
<TabItem value="Local" active>
924+
<TabItem value="Local" default>
925925
```shell
926926
./build/wasmd query wasm list-contract-by-code $ns_code_id
927927
```
@@ -953,7 +953,7 @@ so the correct method is to use the transaction's event proper.
953953
CosmWasm has kept some information about your new instance. At any time, you can retrieve it with:
954954

955955
<Tabs groupId="local-docker">
956-
<TabItem value="Local" active>
956+
<TabItem value="Local" default>
957957
```shell
958958
./build/wasmd query wasm contract $ns_addr1
959959
```
@@ -990,7 +990,7 @@ contract_info:
990990
At a later stage, your contract instances may hold a token balance. At any time, you can fetch this information with:
991991

992992
<Tabs groupId="local-docker">
993-
<TabItem value="Local" active>
993+
<TabItem value="Local" default>
994994
```shell
995995
./build/wasmd query bank balances $ns_addr1
996996
```
@@ -1022,7 +1022,7 @@ The instance keeps its state in storage. If you come from Ethereum, you are fami
10221022
The equivalent command in CosmWasm is `query wasm contract-state`. Conveniently, it also has the `all` subcommand. So let's see what the instance has in storage with:
10231023

10241024
<Tabs groupId="local-docker">
1025-
<TabItem value="Local" active>
1025+
<TabItem value="Local" default>
10261026
```shell
10271027
./build/wasmd query wasm contract-state all $ns_addr1
10281028
```
@@ -1100,7 +1100,7 @@ Now that you know that:
11001100
You can query the instance's state directly, without the `all` keyword. Either with the key in ASCII:
11011101

11021102
<Tabs groupId="local-docker">
1103-
<TabItem value="Local" active>
1103+
<TabItem value="Local" default>
11041104
```shell
11051105
./build/wasmd query wasm contract-state raw $ns_addr1 \
11061106
name_minter --ascii \
@@ -1124,7 +1124,7 @@ You can query the instance's state directly, without the `all` keyword. Either w
11241124
Or with the key in hex:
11251125

11261126
<Tabs groupId="local-docker">
1127-
<TabItem value="Local" active>
1127+
<TabItem value="Local" default>
11281128
```shell
11291129
./build/wasmd query wasm contract-state raw $ns_addr1 \
11301130
6E616D655F6D696E746572 --hex \
@@ -1219,7 +1219,7 @@ Press _Encode_ and on the right you see `wasm14hj2tavq8fpesdwxxcu44rty3hh90vhujr
12191219
Alternatively, you can do the same with wasmd:
12201220

12211221
<Tabs groupId="local-docker">
1222-
<TabItem value="Local" active>
1222+
<TabItem value="Local" default>
12231223
```shell
12241224
./build/wasmd keys parse ade4a5f5803a439835c636395a8d648dee57b2fc90d98dc17fa887159b69638b
12251225
```
@@ -1243,7 +1243,7 @@ the aptly-named [`PredictableAddressGenerator`](https://github.com/CosmWasm/wasm
12431243
If you want to pre-calculate a future address, you can use the command:
12441244

12451245
<Tabs groupId="local-docker">
1246-
<TabItem value="Local" active>
1246+
<TabItem value="Local" default>
12471247
```shell
12481248
./build/wasmd query wasm build-address --help
12491249
```
@@ -1312,7 +1312,7 @@ This smart contract does not need funds, but as a vehicle to demonstrate the con
13121312
you attach funds of **100 stake** to the call:
13131313

13141314
<Tabs groupId="local-docker">
1315-
<TabItem value="Local" active>
1315+
<TabItem value="Local" default>
13161316
```shell
13171317
./build/wasmd tx wasm execute $ns_addr1 "$ns_register_queen_to_alice" \
13181318
--amount 100stake \
@@ -1347,7 +1347,7 @@ ns_register_queen_to_alice_txhash=7966EBDD3766243FFFFE70D0A360305DE11B0BE77A3054
13471347
What happened? Let's look at the events that were emitted as part of this registration:
13481348

13491349
<Tabs groupId="local-docker">
1350-
<TabItem value="Local" active>
1350+
<TabItem value="Local" default>
13511351
```shell
13521352
./build/wasmd query tx $ns_register_queen_to_alice_txhash \
13531353
--output json \
@@ -1397,7 +1397,7 @@ There comes a long list of events. Note this particular one:
13971397
It is emitted by the bank module and is the trace that tells you that Alice paid the name service contract `100stake`. And indeed, you can confirm that now the smart contract instance holds tokens:
13981398

13991399
<Tabs groupId="local-docker">
1400-
<TabItem value="Local" active>
1400+
<TabItem value="Local" default>
14011401
```shell
14021402
./build/wasmd query bank balance $ns_addr1 stake
14031403
```
@@ -1428,7 +1428,7 @@ Better care next time...
14281428
Now, if you look at how the transaction is built:
14291429

14301430
<Tabs groupId="local-docker">
1431-
<TabItem value="Local" active>
1431+
<TabItem value="Local" default>
14321432
```shell
14331433
./build/wasmd query tx $ns_register_queen_to_alice_txhash \
14341434
--output json \
@@ -1487,7 +1487,7 @@ Although you see the word `funds` as a field of the message, it does not mean th
14871487
You can use the same way you used earlier. Call up all storage:
14881488

14891489
<Tabs groupId="local-docker">
1490-
<TabItem value="Local" active>
1490+
<TabItem value="Local" default>
14911491
```shell
14921492
./build/wasmd query wasm contract-state all $ns_addr1
14931493
```
@@ -1569,7 +1569,7 @@ ns_resolve_queen='{"resolve_record":{"name":"queen-of-the-hill"}}'
15691569
Then you pass it as a query to the smart contract:
15701570

15711571
<Tabs groupId="local-docker">
1572-
<TabItem value="Local" active>
1572+
<TabItem value="Local" default>
15731573
```shell
15741574
./build/wasmd query wasm contract-state smart $ns_addr1 "$ns_resolve_queen"
15751575
```

docs/tutorial/platform/05-first-contract.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ It was built with Rust 1.80.1 for CosmWasm 2.1.3. It may work with other version
2525
Most likely, you will start your CosmWasm project as a Rust project. Use `cargo` to initialize a new one.
2626

2727
<Tabs groupId="local-docker">
28-
<TabItem value="Local" active>
28+
<TabItem value="Local" default>
2929
```shell
3030
cargo new my-nameservice --lib --edition 2021
3131
```
@@ -68,9 +68,9 @@ pub struct InstantiateMsg {}
6868
You use the attribute macro [`cw_serde`](https://docs.cosmwasm.com/core/entrypoints#defining-your-own-messages) in order to make your for-now-empty _instantiate_ message serializable. Make its content available to the Rust project by replacing the sample code in `src/lib.rs` with:
6969

7070
```rust title="src/lib.rs"
71-
//with-coverage
71+
//diff-add
7272
+ pub mod msg;
73-
//no-coverage-start
73+
//diff-del-start
7474
- pub fn add(left: u64, right: u64) -> u64 {
7575
- left + right
7676
- }
@@ -79,15 +79,15 @@ You use the attribute macro [`cw_serde`](https://docs.cosmwasm.com/core/entrypoi
7979
- mod tests {
8080
- ...
8181
- }
82-
//no-coverage-end
82+
//diff-del-end
8383
```
8484

8585
Note that it says `pub` as the message needs to be known outside of the project, including tests.
8686

8787
Back in `src/msg.rs` you will notice that `cosmwasm_schema` now appears as an `unresolved import`. You see the same message if you try to build:
8888

8989
<Tabs groupId="local-docker">
90-
<TabItem value="Local" active>
90+
<TabItem value="Local" default>
9191
```shell
9292
cargo build
9393
```
@@ -115,7 +115,7 @@ error[E0432]: unresolved import `cosmwasm_schema`
115115
Indeed, you need to add the relevant dependency:
116116

117117
<Tabs groupId="local-docker">
118-
<TabItem value="Local" active>
118+
<TabItem value="Local" default>
119119
```shell
120120
cargo add cosmwasm-schema@2.1.3
121121
```
@@ -181,7 +181,7 @@ The module is also marked as public because the CosmWasm system needs to be able
181181
Once again, there is a missing dependency: `cosmwasm_std`. Add it:
182182

183183
<Tabs groupId="local-docker">
184-
<TabItem value="Local" active>
184+
<TabItem value="Local" default>
185185
```shell
186186
cargo add cosmwasm-std@2.1.3
187187
```
@@ -222,7 +222,7 @@ Again, add the following line to `src/lib.rs`.
222222

223223
```rust title="src/lib.rs"
224224
pub mod contract;
225-
//with-coverage
225+
//diff-add
226226
+ mod error;
227227
pub mod msg;
228228
```
@@ -232,7 +232,7 @@ Note that it is not `pub` as it only needs to be available within the Rust libra
232232
And don't forget to add the corresponding dependency:
233233

234234
<Tabs groupId="local-docker">
235-
<TabItem value="Local" active>
235+
<TabItem value="Local" default>
236236
```shell
237237
cargo add thiserror@1.0.63
238238
```
@@ -250,23 +250,23 @@ And don't forget to add the corresponding dependency:
250250
Now that the new error type has been declared, you can use it in `src/contract.rs`:
251251

252252
```diff-rs title="src/contract.rs"
253-
//no-coverage-start
253+
//diff-del-start
254254
- use crate::msg::InstantiateMsg;
255255
- use cosmwasm_std::{entry_point, DepsMut, Env, MessageInfo, Response, StdError};
256-
//no-coverage-end
257-
//with-coverage-start
256+
//diff-del-end
257+
//diff-add-start
258258
+ use crate::{error::ContractError, msg::InstantiateMsg};
259259
+ use cosmwasm_std::{entry_point, DepsMut, Env, MessageInfo, Response};
260260
+
261261
+ type ContractResult = Result<Response, ContractError>;
262-
//with-coverage-end
262+
//diff-add-end
263263
264264
#[cfg_attr(not(feature = "library"), entry_point)]
265265
pub fn instantiate(
266266
...
267-
//no-coverage
267+
//diff-del
268268
- ) -> Result<Response, StdError> {
269-
//with-coverage
269+
//diff-add
270270
+ ) -> ContractResult {
271271
...
272272
}
@@ -288,7 +288,7 @@ At this stage, you should have something similar to the [`improve-error-reportin
288288
You can already build with the `cargo build` command. How about building to WebAssembly? You need to add the WebAssembly compiling target for that, if it was not yet installed.
289289

290290
<Tabs groupId="local-docker">
291-
<TabItem value="Local" active>
291+
<TabItem value="Local" default>
292292
```shell
293293
rustup target add wasm32-unknown-unknown
294294
```
@@ -315,7 +315,7 @@ You can already build with the `cargo build` command. How about building to WebA
315315
With the target installed, you can compile to WebAssembly with:
316316

317317
<Tabs groupId="local-docker">
318-
<TabItem value="Local" active>
318+
<TabItem value="Local" default>
319319
```shell
320320
cargo build --release --target wasm32-unknown-unknown
321321
```
@@ -347,7 +347,7 @@ wasm = "build --release --target wasm32-unknown-unknown"
347347
With this alias defined, you can now use `cargo wasm` instead of writing `cargo build --release --target wasm32-unknown-unknown`. Change your command to:
348348

349349
<Tabs groupId="local-docker">
350-
<TabItem value="Local" active>
350+
<TabItem value="Local" default>
351351
```shell
352352
cargo wasm
353353
```
@@ -372,7 +372,7 @@ name = "my-nameservice"
372372
version = "0.1.0"
373373
edition = "2021"
374374

375-
//with-coverage-start
375+
//diff-add-start
376376
+ # Linkage options. More information: https://doc.rust-lang.org/reference/linkage.html
377377
+ [lib]
378378
+ crate-type = ["cdylib", "rlib"]
@@ -392,7 +392,7 @@ edition = "2021"
392392
+ panic = 'abort'
393393
+ incremental = false
394394
+ overflow-checks = true
395-
//with-coverage-end
395+
//diff-add-end
396396

397397
[dependencies]
398398
...
@@ -453,7 +453,7 @@ Note how:
453453
With the test ready, you can run it with the following command:
454454

455455
<Tabs groupId="local-docker">
456-
<TabItem value="Local" active>
456+
<TabItem value="Local" default>
457457
```shell
458458
cargo test
459459
```

0 commit comments

Comments
 (0)