Simple example of how to upgrade contracts in Sway
- Add proxy functionality to Forc.toml
[proxy]
enabled = true
- Deploy the contract using
forc deploy
forc deploy --mainnet
You will notice an address in your forc.toml under [proxy]
file after the deployment, this is your proxy contract address.
[proxy]
enabled = true
address = "0x33f45975f14434a7950446ce9c4cbbc64e5d3ffb5c5a8e7a9dce3f05ae962442"
- Go to Sway-Playground and paste the abi in
out/debug/sway-contract-upgrade-example-abi.json
as well as the address to interact withget_version
function and verify that the number is 7.
- Change line 3 in
src/main.sw
to a new number
const VERSION: u8 = 2u8;
- Redeploy the contract using
forc deploy
again
forc deploy --mainnet
- Go back to Sway-Playground and verify that the number is now your new number.
- Congratulations! You just upgraded your first contract in Sway!