MoonVegas is a platform for playing the following games powered by EVM smart contracts:
- Raffle: Buy one or more tickets. When all tickets are sold, a random ticket is picked at random, and all the funds accumulated are transferred to the winner. The raffle then resets itself automatically. View game.
- Coin flip: Pick either heads or tails, select a bet amount. A coin is flipped at random. If the outcome is the one you picked, you get double your bet. Otherwise, the smart contract keeps it. View game.
It is built using Solidity (smart contract as the backend) and React + NextJS (frontend).
First, set up the .env
file. Use the .env.example
as a reference.
You will also need an account with tokens to make transactions on the network you are connected to (deploy smart contract, interact with it).
- Create a
secrets.json
file in thehardhat
directory. - Find your private key from MetaMask. If you don't know how to find it, follow this guide.
- Add your private key to the
secrets.json
file you just created (use thehardhat/secrets.example.json
as an example).
There are two ways to deploy the smart contracts: either run a node locally or use Moonbeam's testnet: Moonbase Alpha.
Warning: The smart contract tests are a bit flaky (fail ~1/10 times). This is due to the randomness of the games. If they fail, it will most likely work on a second try.
Locally
First, set the environment variable NEXT_PUBLIC_ENV
to localhost
in the .env
file you created above, to target the local node.
Then, you need to use Docker. Once Docker is installed, you can set up a Moonbeam node locally with the following commands:
docker pull purestake/moonbeam:v0.25.0 # Download Moonbeam Docker image (only run this command the first time)
docker run --rm --name moonbeam_development -p 9944:9944 -p 9933:9933 purestake/moonbeam:v0.25.0 --dev --ws-external --rpc-external # Run the node
Once the node is running, deploy the smart contracts to that node:
cd hardhat # All the smart contracts files are located in the ./hardhat directory
yarn install # Install dependencies
yarn run compile # Compile the smart contracts anytime you modify them, this also runs the tests
yarn run deploy:localhost --raffleticketprice 1 --coinflippoolamount 5 # Deploy the compiled Smart Contracts to the node running locally
Testnet (Moonbase Alpha)
First, set the environment variable NEXT_PUBLIC_ENV
to development
in the .env
file you created earlier, to target the testnet.
Then, deploy the smart contracts to testnet:
cd hardhat # All the smart contracts files are located in the ./hardhat directory
yarn install # Install dependencies
yarn run compile # Compile the smart contracts anytime you modify them. Yhis also runs the tests
yarn run deploy:moonbase --raffleticketprice 1 --coinflippoolamount 5 # Deploy the compiled Smart Contracts to the Moonbase Alpha testnet
Run the development server:
yarn install # Install dependencies
yarn dev # Run front-end locally
Open http://localhost:3000 with your browser to view.