Skip to content

Commit

Permalink
chore: update default to dfx 0.21.0 (#907)
Browse files Browse the repository at this point in the history
* chore: update default to dfx 0.20.2

* 🩹 fixed token_transfer and icp_transfer examples

* fixed token_transfer example

* Update provision-darwin.sh

* Update provision-linux.sh

---------

Co-authored-by: Moritz Fuller <[email protected]>
Co-authored-by: Jason <[email protected]>
  • Loading branch information
3 people authored Jul 16, 2024
1 parent 5fb11d9 commit add2199
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/provision-darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rm node.pkg

# Install DFINITY SDK.
curl --location --output install-dfx.sh "https://raw.githubusercontent.com/dfinity/sdk/master/public/install-dfxvm.sh"
DFX_VERSION=${DFX_VERSION:=0.20.1} DFXVM_INIT_YES=true bash install-dfx.sh
DFX_VERSION=${DFX_VERSION:=0.21.0} DFXVM_INIT_YES=true bash install-dfx.sh
rm install-dfx.sh
echo "$HOME/Library/Application Support/org.dfinity.dfx/bin" >> $GITHUB_PATH
source "$HOME/Library/Application Support/org.dfinity.dfx/env"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/provision-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rm install-node.sh

# Install DFINITY SDK.
wget --output-document install-dfx.sh "https://raw.githubusercontent.com/dfinity/sdk/master/public/install-dfxvm.sh"
DFX_VERSION=${DFX_VERSION:=0.20.1} DFXVM_INIT_YES=true bash install-dfx.sh
DFX_VERSION=${DFX_VERSION:=0.21.0} DFXVM_INIT_YES=true bash install-dfx.sh
rm install-dfx.sh
echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH
source "$HOME/.local/share/dfx/env"
Expand Down
9 changes: 3 additions & 6 deletions motoko/icp_transfer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ Replace the contents of the `src/icp_transfer_backend/main.mo` file with the fol
import IcpLedger "canister:icp_ledger_canister";
import Debug "mo:base/Debug";
import Result "mo:base/Result";
import Option "mo:base/Option";
import Blob "mo:base/Blob";
import Error "mo:base/Error";
import Array "mo:base/Array";
import Principal "mo:base/Principal";

actor {
Expand All @@ -193,10 +190,10 @@ actor {
type TransferArgs = {
amount : Tokens;
toPrincipal : Principal;
toSubaccount : ?Blob;
toSubaccount : ?IcpLedger.SubAccount;
};

public shared ({ caller }) func transfer(args : TransferArgs) : async Result.Result<IcpLedger.BlockIndex, Text> {
public shared func transfer(args : TransferArgs) : async Result.Result<IcpLedger.BlockIndex, Text> {
Debug.print(
"Transferring "
# debug_show (args.amount)
Expand All @@ -216,7 +213,7 @@ actor {
// we are transferring from the canisters default subaccount, therefore we don't need to specify it
from_subaccount = null;
// we take the principal and subaccount from the arguments and convert them into an account identifier
to = Blob.toArray(Principal.toLedgerAccount(args.toPrincipal, args.toSubaccount));
to = Principal.toLedgerAccount(args.toPrincipal, args.toSubaccount);
// a timestamp indicating when the transaction was created by the caller; if it is not specified by the caller then this is set to the current ICP time
created_at_time = null;
};
Expand Down
9 changes: 3 additions & 6 deletions motoko/icp_transfer/src/icp_transfer_backend/main.mo
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import IcpLedger "canister:icp_ledger_canister";
import Debug "mo:base/Debug";
import Result "mo:base/Result";
import Option "mo:base/Option";
import Blob "mo:base/Blob";
import Error "mo:base/Error";
import Array "mo:base/Array";
import Principal "mo:base/Principal";

actor {
Expand All @@ -15,10 +12,10 @@ actor {
type TransferArgs = {
amount : Tokens;
toPrincipal : Principal;
toSubaccount : ?Blob;
toSubaccount : ?IcpLedger.SubAccount;
};

public shared ({ caller }) func transfer(args : TransferArgs) : async Result.Result<IcpLedger.BlockIndex, Text> {
public shared func transfer(args : TransferArgs) : async Result.Result<IcpLedger.BlockIndex, Text> {
Debug.print(
"Transferring "
# debug_show (args.amount)
Expand All @@ -38,7 +35,7 @@ actor {
// we are transferring from the canisters default subaccount, therefore we don't need to specify it
from_subaccount = null;
// we take the principal and subaccount from the arguments and convert them into an account identifier
to = Blob.toArray(Principal.toLedgerAccount(args.toPrincipal, args.toSubaccount));
to = Principal.toLedgerAccount(args.toPrincipal, args.toSubaccount);
// a timestamp indicating when the transaction was created by the caller; if it is not specified by the caller then this is set to the current ICP time
created_at_time = null;
};
Expand Down
24 changes: 7 additions & 17 deletions motoko/token_transfer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@ If you chose to download the ICRC-1 ledger files with the script, you need to re
dfx start --background --clean
```

### Step 5: Create a new identity that will work as a minting account:
### Step 5: Use the anonymous identity as the minting account:

```bash
dfx identity new minter --storage-mode plaintext
dfx identity use minter
export MINTER=$(dfx identity get-principal)
export MINTER=$(dfx --identity anonymous identity get-principal)
```

:::info
Expand All @@ -117,18 +115,17 @@ Transfers from the minting account will create Mint transactions. Transfers to t

:::

### Step 6: Switch back to your default identity and record its principal to mint an initial balance to when deploying the ledger:
### Step 6: Record your default identity's principal to mint an initial balance to when deploying the ledger:

```bash
dfx identity use default
export DEFAULT=$(dfx identity get-principal)
```

### Step 7: Deploy the ICRC-1 ledger locally:

Take a moment to read the details of the call made below. Not only are you deploying an ICRC-1 ledger canister, you are also:

- Setting the minting account to the principal you saved in a previous step (`MINTER`)
- Setting the minting account to the anonymous principal you saved in a previous step (`MINTER`)
- Minting 100 tokens to the DEFAULT principal
- Setting the transfer fee to 0.0001 tokens
- Naming the token Local ICRC1 / L-ICRC1
Expand Down Expand Up @@ -189,23 +186,16 @@ Replace the contents of the `src/token_transfer_backend/main.mo` file with the f
import Icrc1Ledger "canister:icrc1_ledger_canister";
import Debug "mo:base/Debug";
import Result "mo:base/Result";
import Option "mo:base/Option";
import Blob "mo:base/Blob";
import Error "mo:base/Error";

actor {

type Account = {
owner : Principal;
subaccount : ?[Nat8];
};

type TransferArgs = {
amount : Nat;
toAccount : Account;
toAccount : Icrc1Ledger.Account;
};

public shared ({ caller }) func transfer(args : TransferArgs) : async Result.Result<Icrc1Ledger.BlockIndex, Text> {
public shared func transfer(args : TransferArgs) : async Result.Result<Icrc1Ledger.BlockIndex, Text> {
Debug.print(
"Transferring "
# debug_show (args.amount)
Expand All @@ -222,7 +212,7 @@ actor {
from_subaccount = null;
// if not specified, the default fee for the canister is used
fee = null;
// we take the principal and subaccount from the arguments and convert them into an account identifier
// the account we want to transfer tokens to
to = args.toAccount;
// a timestamp indicating when the transaction was created by the caller; if it is not specified by the caller then this is set to the current ICP time
created_at_time = null;
Expand Down
1 change: 0 additions & 1 deletion motoko/token_transfer/demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ trap 'dfx stop' EXIT

echo "===========SETUP========="
dfx start --background --clean
dfx identity new alice_token_transfer --storage-mode plaintext --force
export MINTER=$(dfx --identity anonymous identity get-principal)
export DEFAULT=$(dfx identity get-principal)
dfx deploy icrc1_ledger_canister --argument "(variant { Init =
Expand Down
11 changes: 2 additions & 9 deletions motoko/token_transfer/src/token_transfer_backend/main.mo
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import Icrc1Ledger "canister:icrc1_ledger_canister";
import Debug "mo:base/Debug";
import Result "mo:base/Result";
import Option "mo:base/Option";
import Blob "mo:base/Blob";
import Error "mo:base/Error";

actor {

type Account = {
owner : Principal;
subaccount : ?[Nat8];
};

type TransferArgs = {
amount : Nat;
toAccount : Account;
toAccount : Icrc1Ledger.Account;
};

public shared ({ caller }) func transfer(args : TransferArgs) : async Result.Result<Icrc1Ledger.BlockIndex, Text> {
public shared func transfer(args : TransferArgs) : async Result.Result<Icrc1Ledger.BlockIndex, Text> {
Debug.print(
"Transferring "
# debug_show (args.amount)
Expand Down

0 comments on commit add2199

Please sign in to comment.