It's time to have a go at Skirmish 9 of the Soroban RPCiege!
For a short recap on what RPCiege is, see my previous post.
Skirmish 9 is about upgrading our contract.
We're pointed to the game contract, which is a deployer: it will deploy a contract for us to work with.
Let's call it, then see what we have to work with.
(You'll notice I took the lazy route with the salt again: copied the example value and adjusted it slightly. You'll have to generate your own unique one)
A little spoiler: after you've used the deploy
function, you don't need to do anything with the deployer contract anymore.
Now that we have a contract, let's see what it does.
Last time we used -h
to let soroban-cli show us information about the functions. This time, we'll use fetch
soroban contract fetch --network rpciege --id <your_contract_id_here> -o skirmish_9.wasm
This lets soroban-sli download the contract (through the specified RPC server) and store it in the specified -o
file.
Then, we can inspect it:
soroban contract inspect --wasm skirmish_9.wasm
It's not as pretty as -h
, but it does show all functions and their parameters at once.
Here we can see that the run
function doesn't take any parameters, and that the upgrade_contract
function takes one parameter, named hash
. It takes a value of the types BytesN.
Luckily, soroban-cli will handle the conversion from String to BytesN for us.
If you've completed any of the other skirmishes, you may notice that there's no parameter for _nft_dest
.
That means we can't claim those slick trading cards!
But you've probably connected the dots by now:
- Contract with missing function parameter
- Upgradable contract
- ??
- Profit!
Yes, you need to write a new contract now.
I'm not going to show the exact Rust code to use.
You could write one from scratch, or modify one you have. I don't know if it must have a function called run
, but I named my function that.
I know it doesn't need to do anything, but you can be creative.
Just make sure it also has a parameter _nft_dest
.
Now soroban contract build
it, and let's get to upgrading.
To upgrade a contract, three things are needed:
- An existing contract with code to upgrade itself (already provided)
- A new wasm thats been installed on the ledger. (It doesn't have to be deployed though)
- A hash to identify which wasm you want to use.
To install the wasm of your new upgrade, you can use:
soroban contract install --network rpciege --source <your identity> --wasm <path_to_your_wasm>
The install
command will return you the hash of your installed contract.
So, we finally reach the conclusion:
- You have a target contract, with an
upgrade_contract
function that takes a--hash
argument. - You also have your own contract, installed, and its hash
Happy cieging!