Receive funds in sophia smart contracts

I haven’t tested this yet. but in the docs I couldn’t find any information about this. I know in solidity there is a fallback function that can be marked as payable in order to allow the contract to receive payments.

is this possible in sophia, too? or does sophia allow Æ to be sent per default? how would I create I function that is called whenever the contract gets Æ sent without any data?

If you make a spend transaction to a contract, the contract’s account will get the tokens. Nothing will be run in the contract.

The only way of running a contract on chain is to make a call transaction.

We have discussed making contract payable/non-payable in order to prevent the contract receiving tokens by mistake, but in the current protocol this is not the case.

2 Likes

ok, thanks. few more questions regarding that topic:

  • do I understand correctly that everybody can send AE to any contract?
  • does that mean that if the contract doesn’t provide a “withdraw”-function the funds cannot be transfered out of the contract?
    • I mean it sounds like at this point of time I cannot prevent the contract from being funded
  • is it planned to add such “mistake-prevention” functionality?

Yes, anyone can spend to a contract.

No, there is no way to withdraw from a contract if there isn’t code in the contract for doing this.

Typically, making a spend transaction to an account isn’t something you would want to do at all.

We made the design decision to not run anything “by default” when spending to a contract. This to prevent behavior that goes against the Principle if Least Surprise. If you want to run anything at all, you need to make a call transaction.

However, we did not want to remove the possibility to spend to a contract, since it might solve some hairy potential problems (e.g. an under-funded contract that cannot do anything)

We do see that spending to a contract might cause some bad situations as well, so the suggestion was brought forward to optionally prevent It by declaring it in the contract.

This would be mostly to prevent mistakes, or to prevent some sort of malicious funding of a contract to change some constraint in the contract.

We are currently not working on this, but it is on the wish list from our active contract writers.