Live Demo
React | Tailwind | Soroban | Rust
Predict whether the sum of two dice will be greater than or less than 7 on Soroban (Japanese abacus).
The randomisation is based on random generator from the Soroban smart contracts written on the Stellar blockchain on the Futurenet.
Note: The Futurenet is a test network and the XLMs used here are test XLMs.
The Smart contract can be viewed here.
- Install Rust & Wasm32 Target
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknown
- Install Soroban CLI
cargo install --locked --version 20.0.0-rc.4.1 soroban-cli
- Configure the Futurenet:
soroban config network add --global futurenet \
--rpc-url https://rpc-futurenet.stellar.org \
--network-passphrase "Test SDF Future Network ; October 2022"
- Create an Identity on the Futurenet:
soroban config identity generate --global <your-name>
- Store the address of the account generated above:
soroban config identity address <your-name>
- Fund the address with text XLMs:
soroban config identity fund <address-found-above> --network futurenet
- Compile the Contract to a release wasm
cd contract-src
cargo build --target wasm32-unknown-unknown --release
- Deploy the Contract to Futurenet & store the contract address:
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/seven_up_seven_down.wasm \
--source <your-name> \
--network futurenet > .soroban/seven-up-seven-down
- Test the Contract by Invoking it from the CLI:
soroban contract invoke \
--id $(cat .soroban/seven-up-seven-down) \
--source <your-name> \
--network futurenet \
-- \
play \
--prediction down
And the output should be something like: ["You","won","with","down","as","number","was","1"]
.
- Now to integrate this with the React App, we need to generate bindings for the contract:
cd ..
soroban contract bindings typescript \
--network futurenet \
--contract-id $(cat ./contract-src/.soroban/seven-up-seven-down) \
--output-dir node_modules/seven-up-seven-down
The above should create an npm module in the node_modules
directory.
- Install dependencies in the React App
npm install
- Start the app
npm start
If you run into any versioning errors on the browser or something like "Maximum TTL reached", please run the helper script ./update-stellar-sdk.sh and then start the app again!