RPCiege: How to Complete Skirmish No.1

Tyler van der Hoeven - Jun 27 '23 - - Dev Community

Earn digital collectible playing cards in RPCiege, 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

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

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

cargo new --lib <project-name>
Enter fullscreen mode Exit fullscreen mode

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

[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
Enter fullscreen mode Exit fullscreen mode

Step 2: Construct a new empty contract

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

#![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;
Enter fullscreen mode Exit fullscreen mode

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

#![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);
}
Enter fullscreen mode Exit fullscreen mode

Finally feel free to run:

cargo test
Enter fullscreen mode Exit fullscreen mode

or if you're using VSCode and have Rust Analyzer installed you can just run the tests inline right in the code editor itself!
Run tests inline via Rust Analyzer

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:

cargo build --target wasm32-unknown-unknown --release
Enter fullscreen mode Exit fullscreen mode

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:

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"
Enter fullscreen mode Exit fullscreen mode

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.

soroban config -h
Read and update config

Usage: soroban config <COMMAND>

Commands:
  identity  Configure different identities to sign transactions
  network   Configure different networks
Enter fullscreen mode Exit fullscreen mode

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.

soroban config identity generate Default --global
Enter fullscreen mode Exit fullscreen mode

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.

soroban config identity address Default
Enter fullscreen mode Exit fullscreen mode

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

curl -I -X GET "https://friendbot-futurenet.stellar.org/?addr=GBCXL3JLGJ6V2LFWKX5VZ2D42E65MVLX5LTAAN6H7C57J5US7JNCDOSB"
Enter fullscreen mode Exit fullscreen mode

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.

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

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

soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/hello_world.wasm \
--source Default \
--network Futurenet
Enter fullscreen mode Exit fullscreen mode

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!

soroban contract invoke \
--id <contract-id-from-above> \
--source Default \
--network Futurenet \
-- run \
--_nft_dest <stellar-mainnet-public-key>
Enter fullscreen mode Exit fullscreen mode
  • <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.

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!

. . . . . . . . .
Terabox Video Player