How to transfer cycles between wallets in motoko?

I’ve seen various NFT projects charge ICP for mint, but I’m a little unsure how they are doing it, considering arbitrary canisters can not hold/transfer ICP yet? Are you able to facilitate P2P ICP transfers through Motoko or something?

My project at https://hwqwz-ryaaa-aaaai-aasoa-cai.raw.ic0.app/ does a bunch of this. Mostly you have to use cycles and there is a motoko canister called ExperimentalCycles.

You can see my canister code at https://hwqwz-ryaaa-aaaai-aasoa-cai.raw.ic0.app/candy.mo

And the license manager code at https://hwqwz-ryaaa-aaaai-aasoa-cai.raw.ic0.app/licenseManager.mo

Basically this keeps a counter and then every X number of calls it will send a buck worth of cycles to the creator of the library.

The canister and app also implements people paying me ICPs to get a distribution license…I had to use the ledger shim (Annouce Ledger Candid: your missing candid interface to the NNS ledger). Basically they send ICP to my account, and the block to the dapp canister. It confirms the block with the ledger and give them credit. It isn’t wrapped ICP, but it is close.

I’m working on the github where I can host more of this in a straightforward manner.

3 Likes

Ah okay, can you clarify how validating and transferring ICP between wallets works? How do you confirm the block with the ledger? Is this possible to test on local development network?

Hijacking this thread but this is a cool project you got there and too much information to digest there, what happens when someone send ICP to the account? should one be able to directly get minted an NFT?

It is a 3 step process: 1. Send ICP to a regular address 2. Tell canister the block so it can check the ledger and give you credits and claim an NFT if you have enough. 3. Log the block so it can never be redeemed again.

If you are using dfx you have to run two commands. Click “Claim using DFX” to see the instructions.

If you have any motoko questions, please post them here and I’ll be happy to answer questions… Or create a new thread and I can answer them there. If you have economic questions please post them over at DSCVR I’d like to keep the dev board clear of those.

1 Like

Ok, thanks! So is the sending of the ICP when I click the “claim with this app” implemented just in front end or also motoko?

Depends:

  1. Internet Identity: we use send_dfx to ledger to send whatever balance you have in the app specific address and then call claim on our canister
  2. Stoic: we ask you how much to send and then send it with send_dfx and then call claim
  3. Plug: we ask you how much and then use their api to have you authorized the transfer and then call claim.