Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

/lottery package

Overview

Package lottery is an idiomatic gno.land port of the classic Solidity Lottery contract. Players Enter the current round (one entry per address per round). Once a round has at least two entrants, anyone may DrawWinner: a winner is picked deterministically from the block height (ChainHeight() % len(entrants), over the deterministically-sorted entrant set), recorded in the winners history, and a fresh round is opened.

There is no real randomness on-chain, so "random" selection is derived from the block height — the same source Solidity ports use via block.number.

Functions

CurrentRound

func CurrentRound() int

CurrentRound returns the currently open round number.

Command

gnokey query vm/qeval -remote "https://rpc.topaz.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/lottery.CurrentRound()"

Result

Enter

func Enter(cur realm)

Enter adds the caller to the current round's entrants. Each address may only enter a given round once; a duplicate entry panics.

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/lottery" -func "Enter" -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "topaz-1" -remote "https://rpc.topaz.testnets.gno.land" ADDRESSgnokey query -remote "https://rpc.topaz.testnets.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/lottery" -func "Enter" -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "topaz-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.topaz.testnets.gno.land" call.tx
  

HasEntered

func HasEntered(addr address) bool

HasEntered reports whether addr is in the current round.

Param

Command

gnokey query vm/qeval -remote "https://rpc.topaz.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/lottery.HasEntered()"

Result

NumEntrants

func NumEntrants() int

NumEntrants returns how many players have entered the current round.

Command

gnokey query vm/qeval -remote "https://rpc.topaz.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/lottery.NumEntrants()"

Result

Render

func Render(path string) string

Render shows the current round, its entrants, and the winners history.

Param

Command

gnokey query vm/qeval -remote "https://rpc.topaz.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/lottery.Render()"

Result