Sell entries
Entry question
Competitions can require a buyer to answer a question correctly before they enter. Ask it in your own interface, then pass the proof of a correct answer to checkout.
It is a real test: each buyer gets two tries per competition. A wrong answer brings a different question, and a second wrong answer locks that buyer out of that competition.
Get a question
Name the competition and the buyer (by email or wallet address). The question fits that competition's prize (a watch question for a watch, an electronics question for a laptop), and comes with a ticket to send back with the answer.
curl https://www.bitraffle.io/api/v1/entry-question?competitionId=84&[email protected] \
-H "Authorization: Bearer $BITRAFFLE_SECRET_KEY"const res = await fetch("https://www.bitraffle.io/api/v1/entry-question?competitionId=84&[email protected]", {
headers: { Authorization: `Bearer ${process.env.BITRAFFLE_SECRET_KEY}` },
});
const { data } = await res.json();import os, requests
res = requests.get(
"https://www.bitraffle.io/api/v1/entry-question?competitionId=84&[email protected]",
headers={"Authorization": f"Bearer {os.environ['BITRAFFLE_SECRET_KEY']}"},
)
data = res.json()["data"]{
"data": {
"required": true,
"locked": false,
"attemptsLeft": 2,
"question": {
"id": 17,
"question": "On an analogue watch, how many degrees does the minute hand move in one minute?",
"options": [
"1",
"6",
"12",
"30"
],
"category": "watch",
"ticket": "eyJxIjoxNy…"
}
}
}If required is false, skip straight to checkout. If locked is true, the buyer has used both tries and cannot enter this competition.
Check the answer
Send the index of the option the buyer chose, with the question's ticket and the same buyer. A correct answer returns a pass.
curl -X POST https://www.bitraffle.io/api/v1/entry-question/verify \
-H "Authorization: Bearer $BITRAFFLE_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{ "competitionId": 84, "questionId": 17, "answerIndex": 1, "ticket": "eyJxIjoxNy…", "buyer": { "email": "[email protected]" } }'const res = await fetch("https://www.bitraffle.io/api/v1/entry-question/verify", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.BITRAFFLE_SECRET_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
competitionId: 84,
questionId: question.id,
answerIndex: 1,
ticket: question.ticket,
buyer: { email: "[email protected]" },
}),
});
const { data } = await res.json(); // { correct: true, pass: "…", attemptsLeft: 2 }import os, requests
res = requests.post(
"https://www.bitraffle.io/api/v1/entry-question/verify",
headers={"Authorization": f"Bearer {os.environ['BITRAFFLE_SECRET_KEY']}"},
json={
"competitionId": 84,
"questionId": question["id"],
"answerIndex": 1,
"ticket": question["ticket"],
"buyer": {"email": "[email protected]"},
},
)
data = res.json()["data"] # {"correct": True, "pass": "…", "attemptsLeft": 2}| Response | Next |
|---|---|
{ correct: true, pass } | Send pass as skillPass when you start the checkout session for the same buyer and competition. It works once, and expires after 15 minutes. |
{ correct: false, attemptsLeft: 1 } | Tell the buyer, then get a new question: it will be a different one. |
{ correct: false, locked: true } | The buyer has used both tries and cannot enter this competition. They can enter others. |