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

ICRC 1 transfer method is wrong in the motoko implementation #96

Open
alejandrade opened this issue Mar 4, 2023 · 1 comment
Open

Comments

@alejandrade
Copy link

alejandrade commented Mar 4, 2023

As I understand, parameters are different than a record.
Currently, the code looks like this:

  public shared ({ caller }) func icrc1_transfer({
    from_subaccount : ?Subaccount;
    to : Account;
    amount : Tokens;
    fee : ?Tokens;
    memo : ?Memo;
    created_at_time : ?Timestamp;
  }) : async Result<TxIndex, TransferError>

dfx canister call <canister_id> icrc1_transfer '("<from_subaccount>", "<to>", <amount>, <fee>, "<memo>", <created_at_time>)'

It should be

      /// Arguments for a transfer operation
  public type TransferArgs = {
      from_subaccount : ?Subaccount;
      to : Account;
      amount : Tokens;
      fee : ?Tokens;
      memo : ?Blob;

      /// The time at which the transaction was created.
      /// If this is set, the canister will check for duplicate transactions and reject them.
      created_at_time : ?Nat64;
  };

  public shared ({ caller }) func icrc1_transfer(args: TransferArgs) : async Result<TxIndex, TransferError> {
    applyTransfer({
      spender = caller;
      source = #Icrc1Transfer;
      from = {
        owner = caller;
        subaccount = args.from_subaccount;
      };
      to = args.to;
      amount = args.amount;
      fee = args.fee;
      memo = args.memo;
      created_at_time = args.created_at_time;
    });
  };

dfx canister call icrc1 icrc1_transfer '(
    record {
      from_subaccount = null;
      to = record {account = "account-id", subaccount = null};
      amount = record {e8s = 100_000_000};
      fee = null;
      memo = null;
      created_at_time = null;
    }
  )'

@roman-kashitsyn
Copy link
Contributor

Sorry, I can't spot the difference between the TransferArgs in the "should be" section and the type in the Motoko implementation. Could you clarify?

  amount = record {e8s = 100_000_000};

Note that "amount" is of nat type in the ICRC-1 standard, not of a record type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants