Skip to content

Latest commit

 

History

History

Backend

Random Backend

This is the REST API of Random ,a platform where users can take place in the traditional baba ijebu lottery game on chain(Algorand)

Project Structure

This project is made up of 3 main folders

  • contracts
  • scripts
  • test

Contracts

The contracts folder contains the pyTeal code used to write the smart contracts.It is compiled to TEAL bytecode and can be deployed to mainnet or testnet.

To compile the pyteal

  • Run the python file lotto.py. This also generates the app.teal bytecode and abi contract.json

Scripts

This folder contains all the scripts written to interact with the smart contract in typescript.The code to deploy the contract is in deploy.ts.You are to input your account credentials in config.ts.The atomic transaction composer used to call ABI methods from the contract is in call.ts.

To deploy the contract,run

npx ts-node scripts/deploy.ts

Download and Build on local

Clone the repository

    git clone https://github.com/Jaybee020/

Cd into backend folder

    cd backend

Install node dependencies

   npm install

To start the express server

  npm start

Open your local browser and verify the server is running with http://localhost:6060/

API Reference

Get a user game profile by address

GET "/lottoGame/profile/:addr"

All parameters are to be in URL

Parameter Type Description
addr string Required. address of account we want to get game profile for.

response.body

{   status:true,
    data:userLottoInteraction[]

Search for playerCalls to lottoContract by lottoId

GET "/lottoGame/playerCalls/:addr/:lottoId"

All parameters are to be in URL

Parameter Type Description
addr string Required. account address to get lotto contract calls fot
lottoId string Required. lottoId to get filter by

response.body

{
    status:true,
    data:userLottoInteraction[]
            }
}

Get All Previous Games Id and other Game Patams

GET "/lottoGame/allLottoIdHistory"

response.body

{   status:true,
    data:allLottos
    }

Get lotto history details for a specific lottoId

GET "/lottoGame/lottoHistory/:lottoId"

All parameters are to be in URL

Parameter Type Description
lottoId string Required. lottoId to get details of

response.body

{   status:true,
        data: {
        lottoPayTxn: lottoPayTxn,
        lottoCallTxn: lottoCallTxn,
        lottoHistoryDetails: lottoHistoryDetails,
      },

Get all payment Txn to the lottoCall Contract

GET "/lottoGame/lottoPayTXnHistory"

response.body

{   status:true,
    data:lottoPayTxn,
      },

Get currentGameParams

GET "/lottoGame/currentGameParams"

response.body

{
    status: true,
    data: GameParams {
        ticketingStart: number;
        ticketingDuration: number;
        withdrawalStart: number;
        ticketFee: number;
        luckyNumber: number;
        winMultiplier: number;
        maxPlayersAllowed: number;
        maxGuessNumber: number;
        gameMaster: string;
        playersTicketBought: number;
        playersTicketChecked: number;
        totalGamePlayed: number;
        }
}

Post method to enter current game on contract

POST "/lottoGame/enterCurrentGame"

All parameters are to be in req.body.

Parameter Type Description
playerAddr string Required. address of player
guessNumber string Required. player guess number

This returns an array of transactions to be signed by the client

response.body

{   status:true,
    data:Transaction[]
}

Post method to reset and create a new game

POST "/lottoGame/endCurrentAndCreateNewGame"

All parameters are to be in req.body.

Parameter Type Description
ticketingStart number Optional. time when ticket sales should begin
ticketingDuration number Optional. how long ticket sales should last for
withdrawalStart number Optional. time when winners can withdraw
ticketFee number Optional. how many algos a ticket should cost
winMultiplier number Optional. ticketFee multiple winners should get
maxPlayersAllowed number Optional. maximum players allowed to participate in the round
maxGuessNumber number Optional. maximum value for guess and lucky number
gameMasterAddr string Required. address that wants to fund this game round.

This returns an array of transactions to be signed by the client

response.body

{
    status:true,
    data:Transaction[]
}

Post method to change guess number on contract

POST "/lottoGame/changePlayerGuessNumber"

All parameters are to be in req.body.

Parameter Type Description
playerAddr string Required. address of player
newGuessNumber string Required. new player guess number

This returns an array of transactions to be signed by the client

response.body

{   status:true,
    data:Transaction[]
}

Get player GuessNumber in current lotto Game

GET "/lottoGame/getPlayerGuessNumber/:addr"

All parameters are to be in URL

Parameter Type Description
addr string Required. playerAddress to get by

response.body

{
    status: true,
    data: Number
}

Get player GuessNumber in current lotto Game

GET "/lottoGame/getGeneratedRandomNumber"

response.body

{
    status: true,
    data: Number
}

Generate a new lucky number for the lotto Contract

POST "/lottoGame/generateLuckyNumber"

response.body

{
    status: true,
}

Check if a player is a winner in the lottery

POST "/lottoGame/checkUserWin"

All parameters are to be in req.body.

Parameter Type Description
playerAddr string Required. address of player

response.body

{
    status: true,
    data:Boolean
}