Skip to content

WarrenPanDDDD/Week2Assignment

Repository files navigation

Week 2 Assignment

Cronos dapp engineer training week2 task: a smart contract of a "Guess Number" game.

Contract File: contracts/GuessNumberGame.sol

Test File: test/GuessNumberGame.ts

The basic requirements, tests, and addtional task 1 are implemented.

Contract Deployment

Params to deploy:

  • nonceHash - keccak256 hash of the nonce to identify a game
  • nonceNumHash - keccak256 hash of the nonce + number, number is the one to be guessed by players
  • playerNum - how many players in this game. Number of players cannot be larger than 1000, because number is in range [0, 1000) and each player need to make a unique guess

Contract external functions

A guess() function to be called by players:

function guess(uint16 number) external payable {}

A Reveal() function to be called by host:

function reveal(bytes32 nonce, uint16 number) external onlyOwner {}

Contract events

  • StartGame - emit when contract deploys
event StartGame(bytes32 nonceHash, bytes32 nonceNumHash, uint playerNum, uint bet);
  • CommitGuess - emit when play call guess()
event CommitGuess(bytes32 nonceHash, address player, uint guess);
  • RevealAnswer - emit when host call reveal()
event RevealAnswer(bytes32 nonceHash);
  • RewardWinners - emit when distribute reward to a player successfully
event RewardWinners(bytes32 nonceHash, address player, uint reward);

Contract sample

I deployed a game with nonce = "HELLO", number = 689, playerNum = 2, bet = 0.1 ether at address 0x027d3a2854fc10323d511f9C612149a9d0310B08.

The contract has been verified using hardhat etherscan tool.

Please check out the transaction history with the contract. One contract creation Tx, two Guess() Txs, and one Reveal() Tx can be finded.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published