Jump to content
Stake Forum
Dan

Using the Stake API

Featured Comment

Using the Stake API
Graphql endpoint: https://api.stake.com/graphql

Authentication

You can authenticate with graphql via the http header. We utilise jwt token's for authentication which can be found via https://stake.com/settings/tokens or for an unrestricted token (access to everything on your account) you can obtain it from your browser's local storage.

Authenticated requests require that you use this token in your header by adding it to the "x-access-token" property.

{
  "x-access-token": "token goes here"
}

 

Schema

Our schema is now locked down and private. To help support developers, I have created this topic to provide assistance to those who would like insights into certain queries or mutations. When someone requests details for a certain aspect of the schema, I will append this topic with the relevant details required to conduct such a query or mutation.

Terminology: Queries are the equivalent of a GET request, where you are asking for information to be returned, whereas a mutation is a POST request where you generally invoke an action.

 

Examples

Send Message Mutation (sends a message to a chat channel)  [Authenticated]

mutation {
  sendMessage(chatId: "chat_id_goes_here", message: "message_goes_here") {
    id
    user {
      name
    }
  }
}

Public Chats Query (search for all public chat channels) [Unrestricted]

query {
  publicChats {
    id
    name
  }
}

Bet List Query (lookup a players bet history)  [Unrestricted]

{
  user(name: "Dan") {
    houseBetList(limit: 50, offset: 0) {
      id
      iid
      bet {
        ... on CasinoBet {
          game
          payout
          amountMultiplier
          payoutMultiplier
          amount
          currency
          createdAt
        }
      }
    }
  }
}

Bet Info Query (lookup a players bet history)  [Unrestricted]

bet(iid: "house:6645313440") {
    id
    iid
    bet {
      ... on CasinoBet {
        game
        payout
        payoutMultiplier
        createdAt
        currency
        user {
          name
        }
      }
    }
  }

Roll Dice (play stakes dice game) [Authenticated]

mutation {
  diceRoll(amount: 1, target: 50, condition: above, currency: doge) {
    id
    payout
    amountMultiplier
    payoutMultiplier
    createdAt
    nonce
  }
}

 

Please use this topic to submit a request on how to do a certain action with our API and I will ensure to get back to you with the necessary information.

Share this post


Link to post
Share on other sites
1 hour ago, Dan said:

I have updated the topic to ensure all the queries above work. Please submit any further requests for how certain calls are made to our API.

this one used to work but now returns an error (still works on the other site):

Quote


  user(name: "hui") {
    betList(limit: 50) {
      iid
      amount
      payoutMultiplier
      payout
      game
      currency
      state {
        __typename
      }
    }
  }
 

 

Share this post


Link to post
Share on other sites
45 minutes ago, hui said:

this one used to work but now returns an error (still works on the other site):

 

Did you not see the updates query on the topic?

Share this post


Link to post
Share on other sites

Can you please provide API examples for:
- bet info when you provide 1x specific bet id (id with comma and the iid one - plain text)
- Mines Game related queries (preparing the game, next mine bet, cashout - basically the functionality for a bet from start to cashout / loss)

(Was building my app when Stake got maintainance so i have not finished yet and need the queries info)

Share this post


Link to post
Share on other sites
23 hours ago, DreamStage said:

Can you please provide API examples for:
- bet info when you provide 1x specific bet id (id with comma and the iid one - plain text)
- Mines Game related queries (preparing the game, next mine bet, cashout - basically the functionality for a bet from start to cashout / loss)

(Was building my app when Stake got maintainance so i have not finished yet and need the queries info)

query Bet($iid: String!) {
  bet(iid: $iid) {
    ...BetFragment
  }
}

fragment BetFragment on Bet {
  id
  iid
  type
  bet {
    ... on CasinoBet {
      ...CasinoBetFragment
    }
  }
}

fragment CasinoBetFragment on CasinoBet {
  id
  active
  payoutMultiplier
  amountMultiplier
  amount
  payout
  updatedAt
  currency
  game
  user {
    id
    name
  }
}

 

Mines is a stateful game and therefor has various different actions associated to it. Here are the main ones:

Mines Active Bet (query for an active miens game)  [Authenticated]

query minesActiveBet {
  user {
    id
    activeCasinoBet(game: mines) {
      ...CasinoBetFragment
      state {
        ...MinesStateFragment
      }
    }
  }
}

Mines Bet (start a new mines game)  [Authenticated]

mutation minesBet(
  $amount: Float!
  $currency: CurrencyEnum!
  $minesCount: Int!
  $fields: [Int!]
) {
  minesBet(
    amount: $amount
    currency: $currency
    minesCount: $minesCount
    fields: $fields
  ) {
    ...CasinoBetFragment
    state {
      ...MinesStateFragment
    }
  }
}

Mines Next (bet on an active mines game)  [Authenticated]

mutation minesNext($fields: [Int!]!) {
  minesNext(fields: $fields) {
    ...CasinoBetFragment
    state {
      ...MinesStateFragment
    }
  }
}

Mines Cashout (cashout active mines game)  [Authenticated]

mutation minesCashout {
  minesCashout {
    ...CasinoBetFragment
    state {
      ...MinesStateFragment
    }
  }
}

 

The following two fragments are used in the above mutations and queries:

CasinoBetFragment

fragment CasinoBetFragment on CasinoBet {
  id
  active
  payoutMultiplier
  amountMultiplier
  amount
  payout
  updatedAt
  currency
  game
  user {
    id
    name
  }
}

MinesStateFragement

fragment MinesStateFragment on CasinoGameMines {
  mines
  minesCount
  rounds {
    field
    payoutMultiplier
  }
}

Share this post


Link to post
Share on other sites
25 minutes ago, DreamStage said:

Can you please provide API examples for:
- bet info when you provide 1x specific bet id (id with comma and the iid one - plain text)
- Mines Game related queries (preparing the game, next mine bet, cashout - basically the functionality for a bet from start to cashout / loss)

(Was building my app when Stake got maintainance so i have not finished yet and need the queries info)

Bet Info Query (lookup a players bet history)  [Unrestricted]

bet(iid: "house:6645313440") {
    id
    iid
    bet {
      ... on CasinoBet {
        game
        payout
        payoutMultiplier
        createdAt
        currency
        user {
          name
        }
      }
    }
  }

 

Share this post


Link to post
Share on other sites
Just now, Dan said:

Bet Info Query (lookup a players bet history)  [Unrestricted]


bet(iid: "house:6645313440") {
    id
    iid
    bet {
      ... on CasinoBet {
        game
        payout
        payoutMultiplier
        createdAt
        currency
        user {
          name
        }
      }
    }
  }

 

Ha, I got here 1st mate...

Share this post


Link to post
Share on other sites
1 hour ago, Okseo122 said:

Hey Dan, i have a command to remove balance from my vault and i want to know where to paste it.

Anyone any answers for my q?

Share this post


Link to post
Share on other sites
3 minutes ago, Okseo122 said:

Anyone any answers for my q?

Removing balance from vault isn't something you should be doing via the API, is there perhaps a reason why you want to know how to do such functionality?

Share this post


Link to post
Share on other sites
1 minute ago, Dan said:

Removing balance from vault isn't something you should be doing via the API, is there perhaps a reason why you want to know how to do such functionality?

The reason is that i cant claim BTC faucet and there's balance in my vault that i cant see. Support member: Dusan, said me the command to remove balance from vault.

Share this post


Link to post
Share on other sites
37 minutes ago, Okseo122 said:

The reason is that i cant claim BTC faucet and there's balance in my vault that i cant see. Support member: Dusan, said me the command to remove balance from vault.

mutation {
  createVaultWithdrawal(
    currency: btc
    amount: 0.0000000088
    password: "password"
    tfaToken: "123456"
  ) {
    id
  }
}

 

Share this post


Link to post
Share on other sites

Hi can you provide some sample code that will, return tips received data. In some form that I can then work with, in either Python, Javascript or PHP. 

I'm trying to get a collection (non specific use of word) of... 

Who tipped me
Date of tip
Coin Tipped
Amount of Tip

also including how to authenticate so I can receive this information for my account. 

Thanks for any help!

Share this post


Link to post
Share on other sites
11 hours ago, cryptonesiac said:

Thanks for the update!

How can I find the bet ID number (iid)?

Right now the only output (on dice) is something like "d2f7e317-9848-471b-b0d8-b4902b8a4c5b"

Bet (lookup bet) [Unrestricted]

{
  bet(betId: "d2f7e317-9848-471b-b0d8-b4902b8a4c5b") {
    id
    iid
    bet {
      ... on CasinoBet {
        game
        payout
        payoutMultiplier
        createdAt
        currency
        user {
          name
        }
      }
    }
  }
}

 

17 hours ago, Hoffguy said:

Hi can you provide some sample code that will, return tips received data. In some form that I can then work with, in either Python, Javascript or PHP. 

I'm trying to get a collection (non specific use of word) of... 

Who tipped me
Date of tip
Coin Tipped
Amount of Tip

also including how to authenticate so I can receive this information for my account. 

Thanks for any help!

Send Tip List (tips you have sent) [Authenticated]

{
  user {
    sendTipList {
      currency
      amount
      createdAt
      user {
        name
      }
    }
  }
}

Tip List (tips you have received) [Authenticated]

{
  user {
    tipList {
      currency
      amount
      createdAt
      user {
        name
      }
    }
  }
}

 

You can authenticate using the method stated above. You need to pass the x-access-token in the header as described in my original post.

Share this post


Link to post
Share on other sites
22 hours ago, JWo said:

Can you please provide API examples for HiLo Game related queries
Thank you

Any news about? I'm looking for the querys preparing the game, next card bet, cashout ..
Thank you for the answer

Share this post


Link to post
Share on other sites
22 hours ago, JWo said:

Can you please provide API examples for HiLo Game related queries
Thank you

Hilo Bet (initiate a bet on a new game of hilo) [Authenticated]

mutation hiloBet($amount: Float!, $currency: CurrencyEnum!, $startCard: HiloBetStartCardInput!) {
  hiloBet(amount: $amount, currency: $currency, startCard: $startCard) {
    ...BetFragment
    state {
      ...HiloStateFragment
    }
  }
}

Hilo Next (guess next condition) [Authenticated]

mutation hiloNext($guess: BetGameHiloGuessEnum!) {
  hiloNext(guess: $guess) {
    ...BetFragment
    state {
      ...HiloStateFragment
    }
  }
}

Hilo Cashout (cashout current active game) [Authenticated]

mutation hiloCashout {
  hiloCashout {
    ...BetFragment
    state {
      ...HiloStateFragment
    }
  }
}

Hilo Active Bet (query to find active hilo game) [Authenticated]

query hiloActiveBet {
  user {
    id
    activeBet(game: hilo) {
      ...BetFragment
      state {
        ...HiloStateFragment
      }
    }
  }
}

 

The following unique fragment is used in the above graphql examples:
HiloStateFragment

fragment HiloStateFragment on BetGameHilo {
  startCard {
    suit
    rank
  }
  rounds {
    card {
      suit
      rank
    }
    guess
    payoutMultiplier
  }
}

 

12 hours ago, IqueSouza said:

Can you please provide examples for queries, bet on roulette?
Thank you

Roulette Bet (make a roulette bet) [Authenticated]

mutation rouletteBet(
  $currency: CurrencyEnum!
  $colors: [RouletteBetColorsInput]
  $numbers: [RouletteBetNumbersInput]
  $parities: [RouletteBetParitiesInput]
  $ranges: [RouletteBetRangesInput]
  $rows: [RouletteBetRowsInput]
) {
  rouletteBet(
    currency: $currency
    colors: $colors
    numbers: $numbers
    parities: $parities
    ranges: $ranges
    rows: $rows
  ) {
    ...BetFragment
    state {
      ...RouletteStateFragment
    }
  }
}

The following unique fragment is used in the above mutation:

RouletteStateFragment

fragment RouletteStateFragment on BetGameRoulette {
  result
  colors {
    amount
    value
  }
  numbers {
    amount
    value
  }
  parities {
    amount
    value
  }
  ranges {
    amount
    value
  }
  rows {
    amount
    value
  }
}

 

Share this post


Link to post
Share on other sites
8 hours ago, Dan said:

{ bet(betId: "d2f7e317-9848-471b-b0d8-b4902b8a4c5b") { id iid bet { ... on CasinoBet { game payout payoutMultiplier createdAt currency user { name } } } } }

I'm still an API-noob... this code is giving an error ({u'isSafeError': True, u'message': u'unknown'}) , not sure what I'm doing wrong...

Trying to include the query in a Python script by the way...

data = '{ bet(betId: "d2f7e317-9848-471b-b0d8-b4902b8a4c5b") { id iid bet { ... on CasinoBet { game payout payoutMultiplier createdAt currency user { name } } } } } '

Too bad we don't have a sandbox to play around with anymore :(

Share this post


Link to post
Share on other sites
10 hours ago, cryptonesiac said:

I'm still an API-noob... this code is giving an error ({u'isSafeError': True, u'message': u'unknown'}) , not sure what I'm doing wrong...

Trying to include the query in a Python script by the way...


data = '{ bet(betId: "d2f7e317-9848-471b-b0d8-b4902b8a4c5b") { id iid bet { ... on CasinoBet { game payout payoutMultiplier createdAt currency user { name } } } } } '

Too bad we don't have a sandbox to play around with anymore :(

That error isn't within the scope of our API. I tested the following and it works fine:

{
  bet(betId: "") {
    id
    iid
    bet {
      ... on CasinoBet {
        game
        payout
        payoutMultiplier
        createdAt
        currency
        user {
          name
        }
      }
    }
  }
}

 

Here is an example of the query working using Insomnia (great tool to use for testing and developing with both REST and GraphqQL API's)

Screen Shot 2019-06-27 at 11.20.10 am.png

Share this post


Link to post
Share on other sites

Thanks Dan! I got it working more or less... now in Ruby, that was easier somehow :)

I shortened the query to

{
  bet(betId: "d2f7e317-9848-471b-b0d8-b4902b8a4c5b") {
    iid
  }
}

since I only wanted to know the normal bet ID (not the additional infos, yet)

Share this post


Link to post
Share on other sites
Posted (edited)

Hi Dan! Thank you for your engagement.!

Here is a part of me: To get information about last bets (in the case DiceBotCrash ;) the following query could be used

{
  user(name: "Gustav61") {
    houseBetList(limit: 50, offset: 0) {
      id
      iid
      bet {
        ... on CasinoBet {
          game
          payout
          amountMultiplier
          payoutMultiplier
          amount
          currency
          createdAt
          state {
            ... on CasinoGameDice { result  target  condition}
          }
        }
      }
    }
  }
}

See part in the "state"

Edited by Gustav61

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×