Explore Courses Blog Tutorials Interview Questions
0 votes
in Blockchain by (4.1k points)

I have been trying to test the first entry point of this game which is play. But when it tries to compile it, there's some error showing. How do I proceed or is there something I am missing?

[%%version 0.4]

type game = {

  number : nat;

  bet : tez;

  player : key_hash;

type storage = {

  game : game option;

  oracle_id : address;


let%entry play (number : nat) storage = 

  if number>100p then Current.failwith "number must be <=100";

  if 2p.Current.amount()>Current.balance() then Current.failwith"less balance";

  match with

  |some g -> failwith ("game has already started",g)

  |None -> 

      let bet = Current.amount() in

      let storage = <- Some {number, bet, player} in

      (([]:operation list),storage)

1 Answer

0 votes
by (14.4k points)

Well, you actually made a pretty basic mistake while writing the code. You forgot to initialize and therefore you are getting the error. Add the following code lines and your code should work fine: 

let%init storage (oracle_id : address) =

  {game = (None : game option); oracle_id}

Browse Categories