A demo of using the Randomness Oracle Beacon Application to allow betting on a coin flip.
With the release of AVM7 including the vrf_verify
opcode, a smart contract can take in some proof computed through a VRF process off chain and verify that it was computed honestly.
The application that verifies and stores the randomness can be treated as an oracle and other applications may call it to get the random value for a given round.
The Oracle application in this example is on testnet with app id 115885218
and adheres to ARC-21
To read more about how VRF works and best practices when dealing with on-chain randomness, please see this post
To run the demo, in either Python or Typescript, clone down the repo and cd
into it
$ git clone [email protected]:algorand-devrel/coin-flipper.git
$ cd coin-flipper
To run the demo with python, create a virtual environment, source it, and install requirements
$ cd contracts
$ python -m venv .venv
$ source .venv/bin/activate
(.venv) $ pip install -r requirements.txt
Edit the main.py file to add your funded testnet account's mnemonic and run the program
(.venv) $ python main.py
This will create the application, fund it, opt your user in, and call the coin flip endpoint (choosing heads) then after some rounds will try to settle the bet.
To run the demo with the front end, cd into the frontend
directory and install the requirements
$ cd frontend
$ yarn
$ yarn run dev
Log in with a funded testnet account and go through the steps to create, opt in, flip, settle