Receiving ICP in Canister

How we can receive some ICP from the caller in a canister method.

For example :

public shared(msg) func receiveICP() : async Bool {
 
  sender : Principal  = msg.caller;

  //How i can receive the ICP like msg.data ? or something like that

}

Here how we can receive ICP from the caller similar to data in soldity. We get the ether send when calling a function.

You can only get cycles sent.

See. ExperimentalCycles :: Internet Computer

For ICP thereā€™s a [transaction_notification](https://github.com/dfinity/ic/blob/master/rs/rosetta-api/ledger_canister/src/main.rs#L259) function to implement on a canister side to be notified of a received ICP transfer (hint. TransactionNotification type)

1 Like

Welcome to the ICP Ledger rabbit hole!

  1. ICP is different, itā€™s more like an erc20 token on ethereum. Thereā€™s is a ledger canister that holds the balances and has a ā€˜sendā€™ and ā€˜account_balanceā€™ func. When you send ICP you are not actually sending anything, just making a canister call to the ledger canister. The only way to send ICP to a canister is to call the ICP ledger ā€˜sendā€™ (like you would sending an erc20 token)
  2. The ICP ledger does have a notify call, which then notifies the receiver of your tx. So you can use that to trigger something within your canister (e.g. mint ICO tokens or whatever). This uses the transaction notification endpoint. Thereā€™s not a lot of info out there, we do have an example we are working on but we are being held up byā€¦
  3. Thereā€™s no point right now in sending ICP to canisters because canisters can not ā€œsendā€ these out. You have to be whitelisted to send ICP from a canister currently, so any ICP sent to it will be held there until this is resolved :frowning:

This is one reason we are working on wtctoken.com - we can make it fairly easy for users to convert ICP to WTC and then send WTC to canisters for the purpose of say an ICO

7 Likes

Thanks alot Stephen.
TransactionNotification is the one we need to depend on now.

Question here
The internet Identity have principals right ? Are they capable of receiving ICP ?

Then the token is very local to canisters. How we can get the number of tokens available from a particular canisters ?

Example
dfx canister call sgymv-uiaaa-aaaaa-aaaia-cai transfer ā€˜(principal ā€œh6m2n-nrloa-igrxa-r3psa-6nvfe-e3qj2-aowjt-skmcn-z6i6j-sx5b7-paeā€, 1000:nat)ā€™

This is working now
dfx canister call sgymv-uiaaa-aaaaa-aaaia-cai balanceOf ā€˜(principal ā€œh6m2n-nrloa-igrxa-r3psa-6nvfe-e3qj2-aowjt-skmcn-z6i6j-sx5b7-paeā€)ā€™
returns 1_000

ic.rocks will show these tokens 1_000 when i deploy this in Mercury mainnet ?
Or we need to get the details only from the canister ?

Basically, cycles are the native tokens of Dfinity and $ICP is first ERC20 like token

Is my understanding right ?

Basically, cycles are the native tokens of ICP and ICP is first ERC20 like token

Is my understanding right ?

Cycles are more like the native token, but only canisters can hold cycles (users canā€™t) which makes it hard to use as a currency, hence again - WTC

ic.rocks doesnā€™t support token balances currently - there is an ongoing discussion around what a token standard could look like on ICP

1 Like

Very basic question

What is Principal and What is Address ?
My address
a5a9dce51088dc4584342667844fb29cd120020274a95f3329026693375a78b0

In explorer i can see 0 ICP so, can i send my ICP from exchange to this address ?

Logged In as vwwmp-om32r-tgzpy-3lx3m-a5qbm-5pst6-xfdoi-gtivj-trcp6-k3dch-5ae
Principal

How i can relate this in Ethereum or BTC for understanding ?

The hex address (64 long hex string) is also known as the AccountIdentifier, and is constructed using a sha224 of the principal, an index represented as 32 bytes, and the a checksum added in. We built some tooling around working with it. This allows a single principal to have 2 ** 32 seperate sub accounts.

Currently ICP can only be transferred to and from these AccountIdentifiers, some of the token standards only use the Principal as itā€™s easier to work with. The token standard we are building (and using for $WTC) allows you to send to either address and it will arrive to the user. These EXT tokens are also supported in our wallet (stoicwallet.com) - we have an erc20 like example too

3 Likes

Thank you stephen.

I have 0.25 ICP here
97c5811f179af86bcb47b32b535d4059b02072e76ddcef91a66025439f708e68

I want to send 0.25 ICP to
a5a9dce51088dc4584342667844fb29cd120020274a95f3329026693375a78b0

How i can send 0.25 ICP to the second account that Stoic Wallet ?

Deploy the extendable-token

Wondering now, How to mint tokens ?

Deployed erc20.mo

It is Fungible token, so it should have totalSupply already in place right ?
But no where it is mentioned how many tokens to generate in the code erc20.mo code ?

Please clarify stephen

Yeah you go, I just put a guide together to help with this: extendable-token/erc20.MD at main Ā· Toniq-Labs/extendable-token Ā· GitHub

You can test locally, or deploy and test live with Stoic :slight_smile:

2 Likes

Does this function let the canister accept cycles ?

public func acceptCycles() : async () {
let available = Cycles.available();
let accepted = Cycles.accept(available);
assert (accepted == available);
};

Yep, itā€™s something we are adding to all of our canisters as it allows topping up using WTC (wtctoken.com) or receiving cycles from another canister

1 Like

Can we send cycles from accounts? Instead of canisters.

Cycles from Accounts ā†’ Canisters is possible ?

Using WTC you can yeah

How to convert icp to WTC

And send that to my canister ?

Currently it is hard to mint WTC - check out the website which lists more detail, but you have to convert ICP to cycles in your cycles wallet, and then you need to send that to our token contract to mint WTC.

We are working on a simple minter tho, where you can just send ICP to a canister and it will automatically convert it to ICP. Once that is up and running it will be very simple to top up using WTC.

We are also adding a feature into Stoic (it was in an earlier version) where you can topup canisters using ICP directly (so you enter the canister ID, an amount of ICP and it will convert it and send the cycles).

3 Likes

Can i send ICP to your WTCMinter canisterID directily? Does it mint WTC for my accountID automoic?

Not yet, waiting on ICP restrictions to be lifted

thanksā€¦ ledger canister only allowed self-authenticating principal and whitelisted canister to send ICP