RPCiege: How to Complete Skirmish No.1
Tags: programming, rust, blockchain, web3
Published: 2023-06-27 19:30:53

> Earn digital collectible playing cards in [RPCiege](https://rpciege.com/), a smart contract coding game teaching the fundamentals of developing and deploying performant and secure blockchain applications though small, fun, code puzzles.

Skirmish 1 of the RPCiege couldn't be any more straight forward. All you've gotta do is successfully invoke a Soroban smart contract on the `Futurenet` network via the official RPCiege RPC endpoint `https://futurenet.rpciege.com:443`. Definitely simple however the things you'll learn here will form the foundation for all other Skirmishes so be sure you take your time to fully understand each step of the process.

## Step 1: **Create a new Soroban smart contract project**

> _<small>Consult https://soroban.stellar.org/docs/getting-started/hello-world for more details</small>_

Using the Cargo CLI you installed during the Setup step create a new Rust project.

```bash
cargo new --lib <project-name>
```

From here `cd` into your new project and edit your `Cargo.toml` file:

```toml
[package]
name = "project-name"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[features]
testutils = ["soroban-sdk/testutils"]

[dependencies]
soroban-sdk = "0.8.4"

[dev_dependencies]
soroban-sdk = { version = "0.8.4", features = ["testutils"] }

[profile.release]
opt-level = "z"
overflow-checks = true
debug = 0
strip = "symbols"
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true
```

## Step 2: **Construct a new empty contract**

From here navigate to the `src` directory and modify the `lib.rs` file as follows:

```rust
#![no_std]

use soroban_sdk::{contractimpl, Address, Env};

pub struct Contract;

#[contractimpl]
impl Contract {
    pub fn run(_env: Env, _nft_dest: Option<Address>) {}
}

mod test;
```

Next create a `test.rs` file with the following contents:

```rust
#![cfg(test)]

use crate::{Contract, ContractClient};

use soroban_sdk::{Env};

#[test]
fn test() {
    let env = Env::default();
    let contract_id = env.register_contract(None, Contract);
    let client = ContractClient::new(&env, &contract_id);

    client.run(&Option::None);
}
```

Finally feel free to run:

```bash
cargo test
```

or if you're using [VSCode](https://code.visualstudio.com/) and have [Rust Analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) installed you can just run the tests inline right in the code editor itself!
![Run tests inline via Rust Analyzer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3y1olc2jygm8grkvc1i8.png)

## Step 3: **Deploy your contract to the `Futurenet` via the Soroban CLI**

Once you've completed constructing your contract you need to deploy it to the `Futurenet`. We can accomplish this via the Soroban CLI. Before we can do that we need to build our contract and compile it to the WASM format that the Soroban VM expects. To do that simply run:

```bash
cargo build --target wasm32-unknown-unknown --release
```

This will build and place your contract inside the `./target/wasm32-unknown-unknown/release/` directory of your project. From here you can deploy the `.wasm` file of your contract to the Soroban `Futurenet` like so:

```bash
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/hello_world.wasm \
--rpc-url https://futurenet.rpciege.com:443 \
--network-passphrase "Test SDF Future Network ; October 2022"
```

If all goes according to plan you should receive an output of the freshly deployed contract id. This was mine: `34447d1457fd860d5faec2434c1b6087fa3a7420655593866190b594b1136989`.

This is a bit of a messy command though and the Soroban CLI includes a pretty nifty feature which will speed up deploying and invoking contracts in the future via the `config` command.

```bash
soroban config -h
Read and update config

Usage: soroban config <COMMAND>

Commands:
  identity  Configure different identities to sign transactions
  network   Configure different networks
```

Let's go ahead and configure both a network and an identity for future use so we don't have to use the `--rpc-url` and `--network-passphrase` and we aren't borrowing the default Soroban `--source` which could result in sequence number conflicts if someone else were to also be executing a command with this default `Address`.

```bash
soroban config identity generate Default --global
```

Next we need to ensure this address is funded so it can be used as a fee source for all our `soroban` commands. To do this first we need to get the public address of our newly generated `Default` keypair.

```bash
soroban config identity address Default
```

Mine was `GBCXL3JLGJ6V2LFWKX5VZ2D42E65MVLX5LTAAN6H7C57J5US7JNCDOSB`. Finally then we can fund this new account on the `Futurenet` via our `Friendbot` faucet.

```bash
curl -I -X GET "https://friendbot-futurenet.stellar.org/?addr=GBCXL3JLGJ6V2LFWKX5VZ2D42E65MVLX5LTAAN6H7C57J5US7JNCDOSB"
```

With any luck you should get a successful `200` response.

With a new identity added and funded we're ready to add our `Futurenet` network shortcut.

```bash
soroban config network add Futurenet \
--global \
--rpc-url https://futurenet.rpciege.com:443 \
--network-passphrase "Test SDF Future Network ; October 2022"
```

Sweet! Now the command from above can be shortened to:

```bash
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/hello_world.wasm \
--source Default \
--network Futurenet
```

Pretty clean eh?

## Step 4: **Invoke your contract**

Now that our contract has been deployed to the `Futurenet` it's time to invoke it and win the skirmish!

```bash
soroban contract invoke \
--id <contract-id-from-above> \
--source Default \
--network Futurenet \
-- run \
--_nft_dest <stellar-mainnet-public-key>
```

- `<contract-id-from-above>` will be the contract id from your previous contract deployment in the prior step. e.g. remember mine was `34447...36989`
- `<stellar-mainnet-public-key>` should be your own mainnet Stellar public key where you’d like to receive your pack of
commemorative NFT cards. e.g. Mine is [`GDAYV...5EHHG`](https://stellar.expert/explorer/public/account/GDAYVCINVNUZ57EOCN4FK2VVWGQ3L3NW37L6UJLZCK3C7S7CNSS5EHHG).

## Step 5: **Claim your pack of digital collectible cards**

The final step to collect your rewards is to navigate to https://rpciege.com/claim and login with your `<stellar-mainnet-public-key>` account in order to claim your digital collectible card pack for this skirmish.

Congratulations! You've completed the first game, from here on out it'll only get more fun and fantastic!