Enable Canisters to Hold ICP

I had a look at the Delandlabs DFT standard, I’m not sure I can contribute anything meaningful to that project. Its complexity is way over my head, I just want to have a consumer-side abstraction for receiving tokens, I don’t care how the rest of the token works. Any way of sending them out again is fine with me, really. I’m also completely new in this community and have no connections.

Anyway, here’s some Candid code for the receiver interface:

type FungibleTransaction = record {
	CreditedSender: principal;
	Receiver: principal;
	Message: opt blob;
	Amount: Nat;
};
type TXError = nat8;

service FungibleToken {
	"ft_send": (Transaction) -> (opt TXError);
}
service FungibleTokenReceiver {
	"on_ft_received": (Transaction) -> ();
}

During sending, the sender can specify a sender account to be credited for the payment (when paying on someone else’s behalf), but the tokens are deducted from the caller’s account. The sending contract must try to call on_ft_received function on the receiver. If the receiver does not have such a function, or is not a canister, the resulting error should just be ignored silently. The on_ft_received event handler can be called by anyone, and must interpret the caller’s principal as the token type (usually, the caller would be the token ledger canister currently executing ft_send). Since the caller cannot be faked (to the best of my knowledge), the data is considered reliable, as long as the caller itself is trusted.
Now, whoever wants to be able to receive the tokens and be notified about it just needs to implement the event handler, but this is entirely optional. Users will probably need some different kind of subscription or have their own wallet canister or just do polling or whatever. This is not my concern here and can be solved by other standards. All I want to solve here is that canisters can easily receive money. No need to check for double spends, pool known TXs, query other canisters, etc.

1 Like

I’ve answered to this in the other thread Thoughts on the token standard - #141 by mariop

2 Likes

Hey @bogwar, great to see the new notify_top_up method on the cycles-minting-canister is up and working, and gives back the cycles-count :+1:

3 Likes

We’re still working on integrating it within dfx and nns-dapp, but yes it’s already usable :slight_smile:

2 Likes

Just checking on this thread… is it still not possible for a normal canister to hold and send ICP? Seems this topic has not had any updates and it’s not clear whether the token standard topic addresses this (as ICP is native)

2 Likes

It has been possible since Nov. 2021 according to this post:

1 Like

Thanks. Is there any motoko sample code? I can see a javascript library to use mentioned here:

And some rust sample code here:
https://internetcomputer.org/docs/current/developer-docs/integrations/ledger/interact-with-ledger#interact-with-icp-from-a-canister

1 Like

Motoko sample code is here: examples/motoko/ledger-transfer at master · dfinity/examples · GitHub

1 Like