RPCIEGE - Skirmish 9
Tags: stellar, soroban, rust
Published: 2023-10-05 21:31:07

It's time to have a go at Skirmish 9 of the Soroban [RPCiege](https://www.rpciege.com)!
For a short recap on what RPCiege is, see my [previous](https://dev.to/row-bear/rpciege-skirmish-8-349g) post.

Skirmish 9 is about [upgrading](https://soroban.stellar.org/docs/basic-tutorials/upgrading-contracts) our contract.

Our mission:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/891pzml3wncfl28qz8ah.png)

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.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pblanct38t1eoa7ssyda.png)
(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
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oeh6p9o8e6bfq2fx41cz.png)

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:
1. Contract with missing function parameter
2. Upgradable contract
3. ??
4. 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:
1. An existing contract with code to upgrade itself (already provided)
2. A new wasm thats been installed on the ledger. (It doesn't have to be _deployed_ though)
3. 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.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7s3vuzt6ixk48vqdcfrg.png) 

So, we finally reach the conclusion:
1. You have a target contract, with an `upgrade_contract` function that takes a `--hash` argument.
2. You also have your own contract, installed, and its hash

Happy cieging!