RandomChooser
is a simple solidity contract designed to randomise numbers and store the result on-chain. It uses the Fisher-Yates shuffle algorithm for randomisation.
Please note, this contract doesn't use any Verifiable Random Function (VRF). Hence, it's a naive implementation of randomisation and shouldn't be used for scenarios where the randomness needs to be unpredictable and tamper-proof.
This project uses the Hardhat development environment for compilation, testing, and deployment of the contract. It uses several environment variables for configuration, which are set in a .env
file.
- Node.js and npm installed (Node.js version 14 or higher)
- An Infura account (for the API key)
- An Etherscan account (for the API key)
- A CoinMarketCap account (for the API key)
- A wallet with some test ETH (for the private key)
- Clone this repository to your local machine.
- Navigate to the root directory of the project in your terminal.
- Run
npm install
to install all the dependencies. - Create a
.env
file in the root directory of your project. - Set the following environment variables in the
.env
file:
INFURA_API_KEY=<Infura API key>
DEPLOYER_PK=<wallet pk>
ETHERSCAN_API_KEY=<Etherscan API key>
COINMARKETCAP_API_KEY=<CoinMarketCap API key>
Replace <Your Infura API key>
, <Your wallet's private key>
, <Your Etherscan API key>
, and <Your CoinMarketCap API key>
with your actual keys and private key.
This contract can be deployed to different networks including Goerli, Fuji, and Mainnet. To deploy the contract, run:
npx hardhat run scripts/deploy.js --network <network>
Replace <network>
with either goerli, fuji, or mainnet depending on the network you want to deploy to.
After the contract is deployed, Hardhat will verify the contract on Etherscan and print the contract address in the console.
-
randomiseSequence
: This function accepts a sequence of numbers, randomises them, and stores the result against a provided key. -
viewResults
: This function allows you to retrieve the randomised results stored against a given key.
Use this function to randomise a sequence of numbers.
key
: A string value which acts as the identifier for each randomised sequence.resultLimit
: A uint value representing the total number of results to produce.array
: An array of numbers to randomise.
- The length of the array must be at least equal to the
resultLimit
. - The result for the key should not already exist.
Use this function to view the randomised results for a given key.
key
: The key for which you want to view the results.
RandomComplete
: This event is emitted when a randomisation process completes. It includes the sender's address and the randomised result.
This project is licensed under the MIT License.
Henry @gitpancake