How to get current implementation address in Sway?

In ERC1967Upgrade you can call the _getImplementation function to return the current implementation address, what is the recommended way to do this in Sway?

Hey @cctdaniel this is a great question!

There is currently no official contract upgrade standard. However good news is that this is coming very soon. You can look out for the official release within this repository.

@DefiCake is working on a diamond standard (EIP 2535)
which I think would be very helpful to you. You can add a diamond loupe interface for introspection.

Is there an unofficial way to do contract upgrades? How are the existing protocols doing this? Also, what is the ETA for the official contract upgrade standard release?

Yes of course! You can use the newly introduced run_external function in the standard library. It leverages the LDC opcode and operates in a similar manner as how contract upgrades work on Ethereum.

Take closely at how the target contract project works with the proxy project in that PR above.

Note that this was release in Sway v0.52.0 so in order to use it you need create a new toolchain and download that forc version or higher.

1 Like