Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lock9 opened this issue Oct 28, 2020 · 7 comments
Labels
Question Used in questions

Comments

@lock9
Copy link
Contributor

lock9 commented Oct 28, 2020

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.

@lock9 lock9 added the Question Used in questions label Oct 28, 2020
@roman-khimov
Copy link
Contributor

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).

@shargon
Copy link
Member

shargon commented Oct 28, 2020

Hi @lock9, good to see you :)
You have an example here https://github.com/neo-project/neo-devpack-dotnet/blob/ff34e4244681c7e17e99f134772fe52455c890aa/templates/Template.NEP5.CSharp/NEP5.Crowdsale.cs#L26

@lock9
Copy link
Contributor Author

lock9 commented Oct 28, 2020

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 ?

@shargon
Copy link
Member

shargon commented Oct 28, 2020

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.

@lock9
Copy link
Contributor Author

lock9 commented Oct 28, 2020

I'll try that then. Thanks @shargon

@lock9 lock9 closed this as completed Oct 28, 2020
@vncoelho
Copy link
Member

vncoelho commented Oct 28, 2020

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.

@lllwvlvwlll
Copy link
Member

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)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Used in questions
Projects
None yet
Development

No branches or pull requests

5 participants