Skip to content

Commit 5da40e2

Browse files
🩹 fixed token_transfer and icp_transfer examples
1 parent 64b2a7d commit 5da40e2

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

motoko/icp_transfer/README.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ Replace the contents of the `src/icp_transfer_backend/main.mo` file with the fol
179179
import IcpLedger "canister:icp_ledger_canister";
180180
import Debug "mo:base/Debug";
181181
import Result "mo:base/Result";
182-
import Option "mo:base/Option";
183-
import Blob "mo:base/Blob";
184182
import Error "mo:base/Error";
185-
import Array "mo:base/Array";
186183
import Principal "mo:base/Principal";
187184

188185
actor {
@@ -193,10 +190,10 @@ actor {
193190
type TransferArgs = {
194191
amount : Tokens;
195192
toPrincipal : Principal;
196-
toSubaccount : ?Blob;
193+
toSubaccount : ?IcpLedger.SubAccount;
197194
};
198195

199-
public shared ({ caller }) func transfer(args : TransferArgs) : async Result.Result<IcpLedger.BlockIndex, Text> {
196+
public shared func transfer(args : TransferArgs) : async Result.Result<IcpLedger.BlockIndex, Text> {
200197
Debug.print(
201198
"Transferring "
202199
# debug_show (args.amount)
@@ -216,7 +213,7 @@ actor {
216213
// we are transferring from the canisters default subaccount, therefore we don't need to specify it
217214
from_subaccount = null;
218215
// we take the principal and subaccount from the arguments and convert them into an account identifier
219-
to = Blob.toArray(Principal.toLedgerAccount(args.toPrincipal, args.toSubaccount));
216+
to = Principal.toLedgerAccount(args.toPrincipal, args.toSubaccount);
220217
// 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
221218
created_at_time = null;
222219
};

motoko/icp_transfer/src/icp_transfer_backend/main.mo

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import IcpLedger "canister:icp_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";
7-
import Array "mo:base/Array";
85
import Principal "mo:base/Principal";
96

107
actor {
@@ -15,10 +12,10 @@ actor {
1512
type TransferArgs = {
1613
amount : Tokens;
1714
toPrincipal : Principal;
18-
toSubaccount : ?Blob;
15+
toSubaccount : ?IcpLedger.SubAccount;
1916
};
2017

21-
public shared ({ caller }) func transfer(args : TransferArgs) : async Result.Result<IcpLedger.BlockIndex, Text> {
18+
public shared func transfer(args : TransferArgs) : async Result.Result<IcpLedger.BlockIndex, Text> {
2219
Debug.print(
2320
"Transferring "
2421
# debug_show (args.amount)
@@ -38,7 +35,7 @@ actor {
3835
// we are transferring from the canisters default subaccount, therefore we don't need to specify it
3936
from_subaccount = null;
4037
// we take the principal and subaccount from the arguments and convert them into an account identifier
41-
to = Blob.toArray(Principal.toLedgerAccount(args.toPrincipal, args.toSubaccount));
38+
to = Principal.toLedgerAccount(args.toPrincipal, args.toSubaccount);
4239
// 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
4340
created_at_time = null;
4441
};

0 commit comments

Comments
 (0)