Upgrading Reach with long-running contracts #1451
-
I have a Reach program that, once deployed on Algorand, runs a This contract can run for a long time on the consensus network, and the application frontend connects to the API using the compiled backend JavaScript program, which has been compiled with a certain version of Reach. When I update Reach to a later version, even without making any changes to the smart contract, the backend program is rebuilt and the frontend is going to use the new backend. However, when trying to connect to the API, Reach gives an error because of an incompatible Algorand approval program ( What's the best approach to solve this problem? I was thinking about storing the Reach version hash and the respective compiled backend together with the contract ID of a deployed application, although storing all the versions of the compiled backend could be complicated, as it should be fetched dynamically by the frontend when connecting to the contract. Of course, an other option would be to terminate the old contract using the previous version and redeploy the new version. This is also tricky as in my frontend application I have a rather large number of contracts deployed at any given time, one for each NFT on the market. Also, I have long-running contracts that are keeping and updating the state of the game, so stopping them would require saving the state variables somewhere offchain, and applying the same state to the new version after deployment. Any help will be appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
If you are using non-standards functionality, like views and events, then you need to use the exact same Reach version (technically, you need the same backend version, which is an internal number, but it changes a lot). The best way to do that is to compile it once, commit the If you are using standards functionality, like API functions, you can replace your calls to Reach functions in the Eventually, when Algorand does support composability, we expect to make it much easier to use different Reach versions and, for example, "import" a contract spec into the Reach standard library and interact with it using that version's convenience functions. |
Beta Was this translation helpful? Give feedback.
If you are using non-standards functionality, like views and events, then you need to use the exact same Reach version (technically, you need the same backend version, which is an internal number, but it changes a lot). The best way to do that is to compile it once, commit the
build
file, and then fix the version in yourpackage-lock.json
andDockerfile
.If you are using standards functionality, like API functions, you can replace your calls to Reach functions in the
api
namespace with direct use ofalgosdk
. But, this is very difficult, because Algorand does not support composable contracts, so you need to study your Reach compilation output to use it effectively.Eventually, when Algoran…