Coin Flip
Coin Flip is a game where the player tries to guess the outcome of a coin flip. It is one of the simplest contracts implementing random numbers.
Starting the Game
You have two options to start the example:
- Recommended: use the app through Gitpod (a web-based interactive environment)
- Clone the project locally.
Gitpod | Clone locally |
---|---|
https://github.com/near-examples/coin-flip-examples.git |
If you choose Gitpod, a new browser window will open automatically with the code. Give it a minute, and the front-end will pop up (ensure the pop-up window is not blocked).
If you are running the app locally, you should build and deploy a contract (JavaScript or Rust version) and a client manually.
Interacting With the Counter
Go ahead and log in with your NEAR account. If you don't have one, you can create one on the fly. Once logged in, use the tails
and heads
buttons to try to guess the next coin flip outcome.
Frontend of the Game
Structure of a dApp
Now that you understand what the dApp does, let us take a closer look to its structure:
- The frontend code lives in the
/frontend
folder. - The smart contract code in Rust is in the
/contract-rs
folder. - The smart contract code in JavaScript is in the
/contract-ts
folder.
Both Rust and JavaScript versions of the contract implement the same functionality.
Contract
The contract presents 2 methods: flip_coin
, and points_of
.
- 🌐 Javascript
- 🦀 Rust
Loading...