Skip to content

Commit 0c50a6c

Browse files
Merge pull request #1073 from dfinity/update-rust-readmes
Update Rust project READMEs
2 parents 39dbd87 + 5bc62dc commit 0c50a6c

File tree

31 files changed

+528
-939
lines changed

31 files changed

+528
-939
lines changed

rust/basic_bitcoin/README.md

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
---
2-
keywords: [advanced, rust, bitcoin, btc, integration, bitcoin integration]
3-
---
1+
# Basic Bitcoin
42

5-
# Basic Bitcoin
6-
7-
[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/basic_bitcoin)
8-
9-
## Overview
103
This tutorial will walk you through how to deploy a sample [canister smart contract](https://internetcomputer.org/docs/current/developer-docs/multi-chain/bitcoin/overview) **that can send and receive Bitcoin** on the Internet Computer.
114

125
## Architecture
@@ -24,15 +17,13 @@ For a deeper understanding of the ICP < > BTC integration, see the [Bitcoin inte
2417
## Prerequisites
2518

2619
* [x] Install the [IC
27-
SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/index.mdx).
20+
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
2821
For local testing, `dfx >= 0.22.0-beta.0` is required.
2922
* [x] On macOS, `llvm` with the `wasm32-unknown-unknown` target (which is not included in the XCode installation by default) is required.
3023
To install, run `brew install llvm`.
3124

3225
## Step 1: Building and deploying sample code
3326

34-
### Clone the smart contract
35-
3627
This tutorial has the same smart contract written in
3728
[Motoko](https://internetcomputer.org/docs/current/developer-docs/backend/motoko/index.md)
3829
using ECDSA, Schnorr, and Bitcoin API.
@@ -120,7 +111,7 @@ from three types of addresses:
120111
key. This precaution is to prevent attacks that can occur when creating
121112
taproot multisigner addresses using specific multisignature schemes. However,
122113
the Schnorr API of the internet computer does not support Schnorr
123-
multisignatures.
114+
multisignatures.
124115
3. A [P2TR
125116
address](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki)
126117
where the funds can be spent using the provided public key with the script
@@ -130,7 +121,7 @@ from three types of addresses:
130121
Note that P2TR *key path* spending with a tweaked key is currently not available
131122
on the IC because the threshold Schnorr signing interface does not allow
132123
applying BIP341 tweaks to the private key. In contrast, the
133-
tweaked public key is used to spend in the script path, which is availble on the
124+
tweaked public key is used to spend in the script path, which is available on the
134125
IC. For a technical comparison of different ways of how single-signer P2TR
135126
addresses can be constructed and used, you may want to take a look at [this
136127
post](https://bitcoin.stackexchange.com/a/111100) by Pieter Wuille.
@@ -218,7 +209,7 @@ reflected in your current balance.
218209

219210
## Step 6: Retrieving block headers
220211

221-
You can also get a range of Bitcoin block headers by using the `get_block_headers`
212+
You can also get a range of Bitcoin block headers by using the `get_block_headers`
222213
endpoint on your canister.
223214

224215
In the Candid UI, write the desired start height and optionally end height, and click on "Call":
@@ -242,7 +233,7 @@ In this tutorial, you were able to:
242233
* Connect the canister to the Bitcoin testnet.
243234
* Send the canister some testnet BTC.
244235
* Check the testnet BTC balance of the canister.
245-
* Use the canister to send testnet BTC to another testnet BTC address.
236+
* Use the canister to send testnet BTC to another testnet BTC address.
246237

247238
This example is extensively documented in the following tutorials:
248239

rust/basic_dao/README.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
---
2-
keywords: [advanced, rust, dao, decentralized organization, decentralized org]
3-
---
4-
51
# Basic DAO
62

7-
[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/basic_dao)
8-
93
This sample project demonstrates a basic [decentralized autonomous organization](https://en.wikipedia.org/wiki/Decentralized_autonomous_organization) (DAO) that can be deployed to the [Internet Computer](https://github.com/dfinity/ic). The basic DAO sample code is available in [Motoko](https://github.com/dfinity/examples/tree/master/motoko/basic_dao) and [Rust](https://github.com/dfinity/examples/tree/master/rust/basic_dao). You can see a quick introduction on [YouTube](https://youtu.be/3IcYlieA-EE).
104

11-
## Overview
12-
135
A `basic_dao` can be initialized with a set of accounts: mappings from principal IDs to a number of tokens. Account owners can query their account balance by calling `account_balance` and transfer tokens to other accounts by calling `transfer`. Anyone can call `list_accounts` to view all accounts.
146

157
Account owners can submit proposals by calling `submit_proposal`. A proposal specifies a canister, method, and arguments for this method. Account owners can cast votes (either `Yes` or `No`) on a proposal by calling `vote`. The amount of votes cast is equal to the amount of tokens the account owner has. If enough `Yes` votes are cast, `basic_dao` will execute the proposal by calling the proposal’s given method with the given args against the given canister. If enough `No` votes are cast, the proposal is not executed, and is instead marked as `Rejected`.
@@ -23,32 +15,34 @@ This example requires an installation of:
2315

2416
- [x] The Rust toolchain (e.g. cargo).
2517
- [x] [didc.](https://github.com/dfinity/candid/tree/master/tools/didc)
26-
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/).
18+
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
2719
- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
2820

2921
Begin by opening a terminal window.
3022

31-
### Step 1: Build the `basic_dao` canister:
23+
## Step 1: Build the `basic_dao` canister
3224

3325
```bash
3426
make clean; make
3527
```
3628

37-
### Step 2: Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the command:
29+
## Step 2: Setup the dev environment
30+
31+
Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the command:
3832

3933
```bash
4034
cd basic_dao
4135
dfx start --background
4236
```
4337

44-
### Step 3: Create test identities with the commands:
38+
## Step 3: Create test identities with the commands
4539

4640
```bash
4741
dfx identity new --disable-encryption Alice; dfx identity use Alice; export ALICE=$(dfx identity get-principal);
4842
dfx identity new --disable-encryption Bob; dfx identity use Bob; export BOB=$(dfx identity get-principal);
4943
```
5044

51-
### Step 4: Deploy basic_dao with the initial test accounts:
45+
## Step 4: Deploy basic_dao with the initial test accounts
5246

5347
```bash
5448
dfx deploy --argument "(record {
@@ -63,7 +57,7 @@ dfx deploy --argument "(record {
6357
})"
6458
```
6559

66-
### Step 5: List accounts and confirm you see the two test accounts:
60+
## Step 5: List accounts and confirm you see the two test accounts
6761

6862
```bash
6963
dfx canister call basic_dao list_accounts '()'
@@ -86,7 +80,7 @@ Output:
8680
)
8781
```
8882
89-
### Step 6: Call `account_balance` as Bob:
83+
## Step 6: Call `account_balance` as Bob
9084
9185
```bash
9286
dfx canister call basic_dao account_balance '()'
@@ -98,7 +92,7 @@ You should see the output:
9892
(record { amount_e8s = 100_000_000 : nat64 })
9993
```
10094
101-
### Step 7: Transfer tokens to Alice:
95+
## Step 7: Transfer tokens to Alice
10296
10397
```bash
10498
dfx canister call basic_dao transfer "(record { to = principal \"$ALICE\"; amount = record { amount_e8s = 90_000_000:nat;};})";
@@ -110,7 +104,7 @@ Output:
110104
(variant { Ok })
111105
```
112106
113-
### Step 8: List accounts and see that the transfer was made:
107+
## Step 8: List accounts and see that the transfer was made
114108
115109
```bash
116110
dfx canister call basic_dao list_accounts '()'
@@ -137,7 +131,9 @@ Output:
137131
Note that the transfer fee was deducted from Bob's account.
138132
:::
139133
140-
### Step 9: Let's make a proposal to change the transfer fee. You can call `get_system_params` to learn the current transfer fee:
134+
## Step 9: Let's make a proposal to change the transfer fee
135+
136+
You can call `get_system_params` to learn the current transfer fee:
141137
142138
```bash
143139
dfx canister call basic_dao get_system_params '()';
@@ -177,7 +173,7 @@ Output:
177173
blob "DIDL\03l\01\f2\c7\94\ae\03\01n\02l\01\b9\ef\93\80\08x\01\00\01 N\00\00\00\00\00\00"
178174
```
179175
180-
### Step 10: We can then submit the proposal:
176+
## Step 10: We can then submit the proposal
181177
182178
```bash
183179
dfx canister call basic_dao submit_proposal '(record { canister_id = principal "rrkah-fqaaa-aaaaa-aaaaq-cai";
@@ -191,15 +187,15 @@ Note the output proposal ID:
191187
(variant { Ok = 0 : nat64 })
192188
```
193189
194-
### Step 11: Confirm the proposal was created:
190+
## Step 11: Confirm the proposal was created
195191
196192
```bash
197193
dfx canister call basic_dao get_proposal '(0:nat64)'
198194
```
199195
200196
You should see `state = variant { Open };` in the output.
201197
202-
### Step 12: Vote on the proposal:
198+
## Step 12: Vote on the proposal
203199
204200
```bash
205201
dfx canister call basic_dao vote '(record { proposal_id = 0:nat64; vote = variant { Yes };})'
@@ -253,7 +249,7 @@ Output:
253249
)
254250
```
255251
256-
### Resources
252+
## Resources
257253
- [ic-cdk](https://docs.rs/ic-cdk/latest/ic_cdk/)
258254
- [ic-cdk-macros](https://docs.rs/ic-cdk-macros)
259255
- [JavaScript API reference](https://erxue-5aaaa-aaaab-qaagq-cai.ic0.app/)

rust/basic_ethereum/README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
---
2-
keywords: [ advanced, rust, ethereum, eth, integration, ethereum integration ]
3-
---
4-
51
# Basic Ethereum
62

7-
[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/basic_ethereum)
8-
9-
## Overview
10-
113
This tutorial will walk you through how to deploy a
124
sample [canister smart contract](https://internetcomputer.org/docs/current/developer-docs/multi-chain/ethereum/overview)
135
**that can send and receive Ether (ETH)** on the Internet Computer.
@@ -24,7 +16,7 @@ the [Ethereum integration overview](https://internetcomputer.org/docs/current/de
2416

2517
## Prerequisites
2618

27-
* [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/index.mdx).
19+
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
2820

2921
## Step 1: Building and deploying sample code
3022

rust/canister-info/README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
---
2-
keywords: [beginner, rust, canister info]
3-
---
4-
51
# Canister info
62

7-
[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/canister-info)
8-
93
The purpose of this dapp is to give developers a small (backend) dapp that uses the IC's `canister_info` management call to retrieve information about canisters including canister history.
104

115
You can find a detailed description of its methods in the form of doc comments in the source code.

rust/canister-snapshots/README.md

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
---
2-
keywords: [advanced, rust, backup, restore, snapshots]
3-
---
4-
5-
# Canister Snapshots Example
6-
7-
[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/canister-snapshots)
8-
9-
## Overview
1+
# Canister snapshots
102

113
This example demonstrates the process of taking and loading canister snapshots.
124
It features a canister named `chat`, which functions as a miniature database.
@@ -18,40 +10,38 @@ and subsequently restore the data after the simulated data loss.
1810

1911
This example requires an installation of:
2012

21-
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/index.mdx). Note: the Canister Snapshots feature requires `dfx` version `0.23.0-beta.3` or later.
13+
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). Note: the Canister Snapshots feature requires `dfx` version `0.23.0-beta.3` or later.
2214
- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
2315

24-
- ### Step 1: Begin by opening a terminal window and navigating into the project's directory
16+
Begin by opening a terminal window.
2517

26-
```sh
27-
cd examples/rust/canister-snapshots
28-
```
18+
## Step 1: Setup the project environment
2919

30-
- ### Step 2: Start a clean local Internet Computer replica and a web server
20+
Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the commands:
3121

32-
```sh
33-
dfx stop
34-
dfx start --clean
22+
23+
```bash
24+
cd examples/rust/canister-snapshots
25+
dfx start
3526
```
3627

3728
This terminal will stay blocked, printing log messages, until the `Ctrl+C` is pressed or `dfx stop` command is run.
3829

3930
Example output:
4031

4132
```sh
42-
% dfx stop && dfx start --clean
4333
Running dfx start for version 0.23.0-beta.3
4434
[...]
4535
Replica API running on 127.0.0.1:4943
4636
```
4737

48-
- ### Step 3: Open another terminal window in the same directory
38+
## Step 2: Open another terminal window in the same directory
4939

5040
```sh
5141
cd examples/rust/canister-snapshots
5242
```
5343

54-
- ### Step 4: Compile and deploy `chat` canister
44+
## Step 3: Compile and deploy `chat` canister
5545

5646
```sh
5747
dfx deploy
@@ -69,7 +59,7 @@ URLs:
6959
chat: http://127.0.0.1:4943/?canisterId=...
7060
```
7161

72-
- ### Step 5: Populate the database with data
62+
## Step 4: Populate the database with data
7363

7464
```sh
7565
dfx canister call chat append 'Hi there!'
@@ -85,7 +75,7 @@ Example output:
8575
(vec { "Hi there!" })
8676
```
8777
88-
- ### Step 6: Take canister snapshot
78+
## Step 5: Take canister snapshot
8979
9080
Canister `chat` is currently running, and snapshots should not be taken of active canisters.
9181
Therefore, the canister should be stopped before taking a snapshot and then restarted.
@@ -107,7 +97,7 @@ Created a new snapshot of canister chat. Snapshot ID: 00000000000000008000000000
10797
Starting code for canister chat, with canister_id bkyz2-fmaaa-aaaaa-qaaaq-cai
10898
```
10999
110-
- ### Step 7: Simulate data loss
100+
## Step 6: Simulate data loss
111101
112102
The `remove_spam` canister method intentionally includes a bug to simulate data loss.
113103
@@ -127,7 +117,7 @@ Example output:
127117
128118
There is no more data in the database.
129119
130-
- ### Step 8: Restore the canister state from the snapshot
120+
## Step 7: Restore the canister state from the snapshot
131121
132122
Canister `chat` is currently running, and snapshots should not be applied to active canisters.
133123
Therefore, the canister must be stopped before applying the snapshot and then restarted.

0 commit comments

Comments
 (0)