Skip to content

Commit 9daba4c

Browse files
fixed token_transfer example
1 parent 5da40e2 commit 9daba4c

File tree

3 files changed

+9
-27
lines changed

3 files changed

+9
-27
lines changed

motoko/token_transfer/README.md

+7-17
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,10 @@ If you chose to download the ICRC-1 ledger files with the script, you need to re
103103
dfx start --background --clean
104104
```
105105

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

108108
```bash
109-
dfx identity new minter --storage-mode plaintext
110-
dfx identity use minter
111-
export MINTER=$(dfx identity get-principal)
109+
export MINTER=$(dfx --identity anonymous identity get-principal)
112110
```
113111

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

118116
:::
119117

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

122120
```bash
123-
dfx identity use default
124121
export DEFAULT=$(dfx identity get-principal)
125122
```
126123

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

129126
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:
130127

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

196191
actor {
197192

198-
type Account = {
199-
owner : Principal;
200-
subaccount : ?[Nat8];
201-
};
202-
203193
type TransferArgs = {
204194
amount : Nat;
205-
toAccount : Account;
195+
toAccount : Icrc1Ledger.Account;
206196
};
207197

208-
public shared ({ caller }) func transfer(args : TransferArgs) : async Result.Result<Icrc1Ledger.BlockIndex, Text> {
198+
public shared func transfer(args : TransferArgs) : async Result.Result<Icrc1Ledger.BlockIndex, Text> {
209199
Debug.print(
210200
"Transferring "
211201
# debug_show (args.amount)
@@ -222,7 +212,7 @@ actor {
222212
from_subaccount = null;
223213
// if not specified, the default fee for the canister is used
224214
fee = null;
225-
// we take the principal and subaccount from the arguments and convert them into an account identifier
215+
// the account we want to transfer tokens to
226216
to = args.toAccount;
227217
// 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
228218
created_at_time = null;

motoko/token_transfer/demo.sh

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ trap 'dfx stop' EXIT
55

66
echo "===========SETUP========="
77
dfx start --background --clean
8-
dfx identity new alice_token_transfer --storage-mode plaintext --force
98
export MINTER=$(dfx --identity anonymous identity get-principal)
109
export DEFAULT=$(dfx identity get-principal)
1110
dfx deploy icrc1_ledger_canister --argument "(variant { Init =

motoko/token_transfer/src/token_transfer_backend/main.mo

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
import Icrc1Ledger "canister:icrc1_ledger_canister";
22
import Debug "mo:base/Debug";
33
import Result "mo:base/Result";
4-
import Option "mo:base/Option";
5-
import Blob "mo:base/Blob";
64
import Error "mo:base/Error";
75

86
actor {
97

10-
type Account = {
11-
owner : Principal;
12-
subaccount : ?[Nat8];
13-
};
14-
158
type TransferArgs = {
169
amount : Nat;
17-
toAccount : Account;
10+
toAccount : Icrc1Ledger.Account;
1811
};
1912

20-
public shared ({ caller }) func transfer(args : TransferArgs) : async Result.Result<Icrc1Ledger.BlockIndex, Text> {
13+
public shared func transfer(args : TransferArgs) : async Result.Result<Icrc1Ledger.BlockIndex, Text> {
2114
Debug.print(
2215
"Transferring "
2316
# debug_show (args.amount)

0 commit comments

Comments
 (0)