Neo: How can my SC detect if the incoming transaction has attached NEO, GAS or other NEP-5 token? (Neo 3)

Created on 28 Oct 2020  路  7Comments  路  Source: neo-project/neo

Hi,

I would like to have my contract to behave differently if it is invoked with attached tokens. On Neo 2, we could view the 'attachments', but I don't think this is possible on Neo 3.
How can I detect if my contract is receiving tokens? How can we mimic the ICO behavior on Neo 3?

Thanks.

question

Most helpful comment

Hi @lock9, good to see you active as well.

@shargon, if the Notification comes from another contract B that dynamic invoked called A. Could the notification be forged on B and verified on A and have the properties that simulate NEO or GAS?

I believe that "onPayment" will be a better generic solution. However, the notifications are also good as well.

All 7 comments

Maybe neo-project/proposals#108 and associated PRs? Otherwise it's about notifications, either System.Runtime.GetNotifications (if transaction is making a transfer and then calling your contract) or #2034 (for historic transfers).

Hi Shargon, good to see you too.

Is it safe to use notifications only? Why the invocation counter must be 1? Can you explain it to me @shargon ?

Is it safe to use notifications only?

Yes, because we check the originator's script hash

Why the invocation counter must be 1? Can you explain it to me @shargon ?

It's mandatory because if you call again to this method you will earn twice. This prevent reentrancy.

I'll try that then. Thanks @shargon

Hi @lock9, good to see you active as well.

@shargon, if the Notification comes from another contract B that dynamic invoked called A. Could the notification be forged on B and verified on A and have the properties that simulate NEO or GAS?

I believe that "onPayment" will be a better generic solution. However, the notifications are also good as well.

It's mandatory because if you call again to this method you will earn twice. This prevent reentrancy.

@shargon Will that scale with dynamic invokes which are nested within the second contract?

Question: I make an initial call to a contract 1 and transfer funds, then invoke a contract 2 to read the notification and mint. Within the invocation of the contract 2, it does a dynamic invoke to contract 3. Within contract 3, will invocation counter still be 1 (a global counter) or will it in increment on dynamic invokes (a local counter)?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

igormcoelho picture igormcoelho  路  53Comments

EdgeDLT picture EdgeDLT  路  59Comments

superboyiii picture superboyiii  路  42Comments

SueNEO picture SueNEO  路  30Comments

lock9 picture lock9  路  62Comments