How to call icrc1_ledger's icrc1_transfer function using the minter principal in motoko?

I have an icrc1_ledger canister set up locally for a custom token. I can interact with it via candid so I know it is live and working. I can call the icrc1_transfer via the CLI with my identity set to the minter account’s principal and it does what is expected, i.e. it mints the tokens and transfers them to the designated user.

However, I now want to call the icrc1_transfer function via an inter-canister call as the minter from ‘myCanister’ written in motoko. myCanister makes a call to icrc1_ledger/icrc1_transfer.

The call doesn’t seem to work (I think) because the incoming message to icrc1_ledger is not coming from the minter’s principal. My understanding is that the call will be made using the id of the canister. (The minter principal is the controller of myCanister, but that doesn’t seem to do the trick).

I’m not sure how this is supposed to work. Do I need to sign the transaction with the minter principal before it is sent? Is there a way for another canister to perform minting of tokens?

I could define myCanister’s principal as the minter principal in icrc1_ledger but that doesn’t seem like a realistic scenario - or maybe that’s the solution? I’d appreciate any pointers on (a) whether minting programmatically from another canister is possible, and (b) what approach should I use?

1 Like

Correct. On ICP the caller of a message is only one hop back. There is no way to get the original triggering principal of a transaction chain like on e.g. Ethereum. (Unless you pass it on specifically, but that requires trust in the other canisters in the call chain)

The minter has to sign the call and submit it directly to the ledger. No intermediate canisters are allowed.

That is the correct approach. You can then also add functionality to myCanister such that you can instruct myCanister to mint tokens for you.

Also, I suspect that you could profit from reading this page. It contains some potential misconceptions that people commonly have if they are used to other blockchains

1 Like