Does Sway have a "fallback" equivalent?

Does Sway have a “fallback” equivalent like Solidity?

1 Like

It sounds like you’re referring to the “fallback function” feature described here, is that right?

Currently, we don’t have support for anything like this, and I don’t think we have any plans for something like this at present.

Intuitively, the feature sounds a little messy, in that it invokes a potentially payable contract function for messages that contain arbitrary call data (besides those that match another function).

My guess is that the motivation here is to capture attempts to call older versions of contract functions in newer versions of a contract so that the new contract can emit some event or log, rather than silently revert?

I’m not sure it’s a good idea to encourage contract developers to notify of API changes from the contract itself like this. In the FuelLabs ecosystem, it is the tools used to build and deploy contracts or run scripts (like forc or the SDKs) that should be raising the error about ABI incompatibility long before the bytecode makes it to a node for execution and long before any gas is spent.

All that said, I could be overlooking some greater motivating use-case!

2 Likes

No, at least not currently.

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.