0

Say for example i want to execute a smart contract that upon receiving $1000 from person A, immediately executes after it is received which then takes that $1000 and disperses to 5 addresses.

Is this possible? Any links I can read if it is? Im having a hard time finding out if it is. Thanks!

1 Answer 1

1

In general this is not possible as you meant it, every time that some EVM instructions are executed there must be someone who is paying for the GAS. So it's not possible to write functions that are automatically triggered and executed when arbitrary situations occur.

However, for your particular situation:

  • if you mean receiving Ether it would be possible simply writing a payable function
  • if the token that your contract is receiving implements a callback mechanism (as for the ERC1363) this would be possible implementing the ERC1363Receiver interface in your contract.
  • if you are deploying the token contract too you can virtually do whatever you want

I want to emphasize how in each of these three hypotheses someone has to pay for the GAS that for the first two cases it must be the one that transfers the token (not necessarily the owner).

1
  • Thank you. payable() was exactly what i was looking for Jan 5 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.