This repository contains a smart contract that demonstrates Flow EVM's native secure randomness with a simple game inspired by Hi-Lo and Pig.
Contracts adapted from: https://github.com/onflow/random-coin-toss
.
├── src
| ├── mocks
| | ├── MockCadenceRandomConsumer.sol # Used to create tests
| ├── CadenceArchUtils.sol # Util library for calling randomness
| ├── CadenceArchRandomConsumer.sol # Helper contract for randomness
| ├── PigLo.sol # The main contract with the game
│ ├── Xorshift128plus.sol.sol # Util library for bit shifting
├── test
| ├── CadenceRandomConsumer.t.sol #Tests for the random consumer
│ ├── PigLo.t.sol # Tests for PigLo contract
├── foundry.toml # Foundry configuration file
├── script
└── README.md # This fileBefore you begin, ensure you have met the following requirements:
- Foundry installed for compiling, testing, and deploying smart contracts.
- A compatible Solidity compiler version (check
foundry.tomlfor the exact version).
-
Clone the repository:
git clone https://github.com/TimMackenzie/pig-lo cd pig-lo -
Install dependencies (if any):
forge install
-
Compile the contracts:
forge build
The repository includes test files written for Foundry.
To run all tests:
forge testThe game contract that supports playing rounds of HiLo where score is reset upon any loss. This contract only works on the Flow EVM because it requires the secure randomness capabilities.
PigLo.t.sol:
This demonstrates a few primary paths, including a fuzz test. There may be missing edge cases that should be added.
To deploy the contracts to a network, you can use the deployment script provided under script/Deploy.s.sol. Make sure your deployment script is configured properly with network and contract addresses if necessary.
Run the deployment:
forge script script/Deploy.s.sol --rpc-url <your_rpc_url>If you’d like to contribute to this project, please fork the repository and use a feature branch. Pull requests are welcome.
This project is licensed under the MIT License - see the LICENSE file for details.
This README should give users and developers enough context to get started with your project, including installation, testing, and contributing.