Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Rust project READMEs #1073

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 26 additions & 28 deletions motoko/canister_logs/README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,64 @@
---
keywords: [beginner, motoko, canister logs, logging]
---

# Canister logs

[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/motoko/canister_logs)

## Prerequisites
This example requires an installation of:

- [x] DFX version 0.19.0 or newer
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/).
- [x] Download the following project files from GitHub: `git clone https://github.com/dfinity/examples/`
- [x] Install the [IC
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required.
- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`

You will need to have 3 terminal windows:
- Terminal A: Running a DFX instance and separating its output from anything else
- Terminal B: Deploying a canister and seeing its output
- Terminal C: Reading logs interactively
## Step 1: Setup project environment

Navigate into the folder containing the project's files and start a local instance of the replica with the command:

### Step 1: Navigate into the folder containing the project's files and start a local instance of the replica with the command:
```shell
dfx start --clean
```

You will need to have 3 terminal windows:
- Terminal A: Running a `dfx` instance and separating its output from anything else.
- Terminal B: Deploying a canister and seeing its output.
- Terminal C: Reading logs interactively.

```shell
# Terminal A -- for running DFX and separating its output from anything else.
$ cd examples/motoko/canister_logs
$ dfx start --clean
cd examples/motoko/canister_logs

# Terminal B -- for deploying the canister and calling its methods.
$ cd examples/motoko/canister_logs
cd examples/motoko/canister_logs

# Terminal C -- for polling logs.
$ cd examples/motoko/canister_logs
cd examples/motoko/canister_logs
```

### Step 2: Deploy the canister:
## Step 2: Deploy the canister

```shell
# Terminal B
$ dfx deploy
dfx deploy
```

### Step 3: Check canister logs:
## Step 3: Check canister logs

Expect to see logs from timer traps.

```shell
# Terminal B
$ dfx canister logs CanisterLogs
dfx canister logs CanisterLogs
[0. 2024-05-23T08:32:26.203980235Z]: right before timer trap
[1. 2024-05-23T08:32:26.203980235Z]: [TRAP]: timer trap
[2. 2024-05-23T08:32:31.836721763Z]: right before timer trap
[3. 2024-05-23T08:32:31.836721763Z]: [TRAP]: timer trap
```

### Step 4: Call `print` method and check the logs:
## Step 4: Call `print` method and check the logs

```shell
# Terminal B
$ dfx canister call CanisterLogs print hi
dfx canister call CanisterLogs print hi
()

# Expect to see new log entry.
$ dfx canister logs CanisterLogs
dfx canister logs CanisterLogs
...
[8. 2024-05-23T08:32:46.598972616Z]: right before timer trap
[9. 2024-05-23T08:32:46.598972616Z]: [TRAP]: timer trap
Expand All @@ -70,7 +68,7 @@ $ dfx canister logs CanisterLogs
...
```

### Step 5: Start constantly polling logs:
## Step 5: Start constantly polling logs

In order not to call `dfx canister logs CanisterLogs` after every canister call in a separate terminal window/pane C start a script that will constantly poll logs:

Expand All @@ -86,7 +84,7 @@ $ ./poll_logs.sh
...
```

### Step 6: Call `print`, `trap` and other canister methods:
## Step 6: Call `print`, `trap` and other canister methods

```shell
# Terminal B
Expand Down
21 changes: 6 additions & 15 deletions rust/basic_bitcoin/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
---
keywords: [advanced, rust, bitcoin, btc, integration, bitcoin integration]
---
# Basic Bitcoin

# Basic Bitcoin

[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/basic_bitcoin)

## Overview
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.

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

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

## Step 1: Building and deploying sample code

### Clone the smart contract

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

## Step 6: Retrieving block headers

You can also get a range of Bitcoin block headers by using the `get_block_headers`
You can also get a range of Bitcoin block headers by using the `get_block_headers`
endpoint on your canister.

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

This example is extensively documented in the following tutorials:

Expand Down
40 changes: 18 additions & 22 deletions rust/basic_dao/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
---
keywords: [advanced, rust, dao, decentralized organization, decentralized org]
---

# Basic DAO

[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/basic_dao)

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).

## Overview

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.

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`.
Expand All @@ -23,32 +15,34 @@ This example requires an installation of:

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

Begin by opening a terminal window.

### Step 1: Build the `basic_dao` canister:
## Step 1: Build the `basic_dao` canister

```bash
make clean; make
```

### Step 2: Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the command:
## Step 2: Setup the dev environment

Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the command:

```bash
cd basic_dao
dfx start --background
```

### Step 3: Create test identities with the commands:
## Step 3: Create test identities with the commands

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

### Step 4: Deploy basic_dao with the initial test accounts:
## Step 4: Deploy basic_dao with the initial test accounts

```bash
dfx deploy --argument "(record {
Expand All @@ -63,7 +57,7 @@ dfx deploy --argument "(record {
})"
```

### Step 5: List accounts and confirm you see the two test accounts:
## Step 5: List accounts and confirm you see the two test accounts

```bash
dfx canister call basic_dao list_accounts '()'
Expand All @@ -86,7 +80,7 @@ Output:
)
```

### Step 6: Call `account_balance` as Bob:
## Step 6: Call `account_balance` as Bob

```bash
dfx canister call basic_dao account_balance '()'
Expand All @@ -98,7 +92,7 @@ You should see the output:
(record { amount_e8s = 100_000_000 : nat64 })
```

### Step 7: Transfer tokens to Alice:
## Step 7: Transfer tokens to Alice

```bash
dfx canister call basic_dao transfer "(record { to = principal \"$ALICE\"; amount = record { amount_e8s = 90_000_000:nat;};})";
Expand All @@ -110,7 +104,7 @@ Output:
(variant { Ok })
```

### Step 8: List accounts and see that the transfer was made:
## Step 8: List accounts and see that the transfer was made

```bash
dfx canister call basic_dao list_accounts '()'
Expand All @@ -137,7 +131,9 @@ Output:
Note that the transfer fee was deducted from Bob's account.
:::

### Step 9: Let's make a proposal to change the transfer fee. You can call `get_system_params` to learn the current transfer fee:
## Step 9: Let's make a proposal to change the transfer fee

You can call `get_system_params` to learn the current transfer fee:

```bash
dfx canister call basic_dao get_system_params '()';
Expand Down Expand Up @@ -177,7 +173,7 @@ Output:
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"
```

### Step 10: We can then submit the proposal:
## Step 10: We can then submit the proposal

```bash
dfx canister call basic_dao submit_proposal '(record { canister_id = principal "rrkah-fqaaa-aaaaa-aaaaq-cai";
Expand All @@ -191,15 +187,15 @@ Note the output proposal ID:
(variant { Ok = 0 : nat64 })
```

### Step 11: Confirm the proposal was created:
## Step 11: Confirm the proposal was created

```bash
dfx canister call basic_dao get_proposal '(0:nat64)'
```

You should see `state = variant { Open };` in the output.

### Step 12: Vote on the proposal:
## Step 12: Vote on the proposal

```bash
dfx canister call basic_dao vote '(record { proposal_id = 0:nat64; vote = variant { Yes };})'
Expand Down Expand Up @@ -253,7 +249,7 @@ Output:
)
```

### Resources
## Resources
- [ic-cdk](https://docs.rs/ic-cdk/latest/ic_cdk/)
- [ic-cdk-macros](https://docs.rs/ic-cdk-macros)
- [JavaScript API reference](https://erxue-5aaaa-aaaab-qaagq-cai.ic0.app/)
Expand Down
10 changes: 1 addition & 9 deletions rust/basic_ethereum/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
---
keywords: [ advanced, rust, ethereum, eth, integration, ethereum integration ]
---

# Basic Ethereum

[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/basic_ethereum)

## Overview

This tutorial will walk you through how to deploy a
sample [canister smart contract](https://internetcomputer.org/docs/current/developer-docs/multi-chain/ethereum/overview)
**that can send and receive Ether (ETH)** on the Internet Computer.
Expand All @@ -24,7 +16,7 @@ the [Ethereum integration overview](https://internetcomputer.org/docs/current/de

## Prerequisites

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

## Step 1: Building and deploying sample code

Expand Down
6 changes: 0 additions & 6 deletions rust/canister-info/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
---
keywords: [beginner, rust, canister info]
---

# Canister info

[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/canister-info)

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.

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