The Bitcoin Button Game @Binance

Daniele De Faveri
13 min readJan 8, 2024

--

How I created a Robot software to Win a Bitcoin

Versione italiana dell’articolo disponibile Qui; Italian Version available Here.

The page of The #BitcoinButtonGame
The page of The #BitcoinButtonGame

*This article has been initially published in June 2022.

TL;DR; is it possible to win a bitcoin at the Binance bitcoin button game by creating asoftware robot that plays for me?

This article tells how I tried to win a bitcoin at @binance’s The Bitcoin Button Game,which is a strategy game where the last player to push the button wins.

I built a software robot (written in R with Selenium libraries) that looks at the gamepage ready to participate at the right time and it is integrated with a telegram Bot forreal time alerting when he decides to play by pressing the button.

It doesn’t matter if I actually managed to win, but the idea and design of the robot isreally interesting.

Here are the details of the game, the model that forecast how long the game wouldlast and the robot code.

INDEX:

The #Bitcoinbuttongame by Binance

Binance’s Bitcoin Button Game is a strategy game in which the last person to pressthe button wins 1 Bitcoin; the game is linked to a timer with a countdown from60.00 seconds to 00.00, when the timer reaches zero the game ends, but every time aplayer presses the button the timer restarts the 60 second countdown.

To win in the game, therefore, it is sufficient that after one player has pressed thebutton no other player presses the button for 60 seconds.
Each player has only 1 attempt so they must choose the best time to play their winning chance.

What is the best tactic for trying to win bitcoin?
The only way is to be able to push the button when there is little activity in the gameand cross your fingers for 60 seconds, hoping that the little activity means that allthe other players have all already used their chance.

The only way, then, is to press the button when the timer is extremely close to 00.00,hoping this means that all the players who wanted to play have already done so andno one who still has the ability to push the button is present and will play in thefollowing 60 seconds.

But you can’t think of looking at the timer page for days on end by clicking when itgets close to 00.00 and also according to Hick’s law (wikipedia Hick’s Law) whichmodels the human-machine interaction describing the time it takes a user to makea decision based on the number of choices available, the minimum reaction time toa visual stimulus when the subject is focused, follows the law

that in the case of the bitcoin button game brings the minimum reaction time toapproximately 2 tenths of a second, so there is a high risk of trying to press thebutton when it is close to 0 and not reacting in time and therefore losing theopportunity to win making the previous player win.

Reaction time to the growth of choice possibilities
Reaction time to the growth of choice possibilities

We Need A Robot!
This is therefore a job more suitable for a machine and this is where I came up withthe idea of creating a software robot that would look at the page for me and stayready to click on the button at the most appropriate time.

I have already built programs that interact in a “human” way with web pages and Itherefore thought of reusing this experience in this area; I wrote it R (not muchwould have changed in other languages such as Python, but due to the confidenceand speed of development I have in R, I decided to implement it in this languageeven if it is not its specific scope of use ).

How long will the game last?
The first question I asked myself is: “Will I have enough time to build and test therobot? How long could the game last? “

I remember that the game ends when the timer reaches 00.00, so when no playerclicks the button for 60 seconds, or if the timer has not yet reached 0 after 90 daysfrom the start of the game.

So let’s make a first approximation of how much time we might have available tobuild our Robot; to play you must have a Binance account or a Twitter account thatis already active at the time of starting the game and that follows the Binance twitteraccount; Binance currently has approximately 28.5 million customers on itsplatform and 8 million followers on twitter.

The game started on March 15, 2022 I discovered the game on March 22, 2022 andthe number of players at this point was around 521K players, which means anaverage of 1.3 seconds per click; There is obviously some variance on this value, buteven in the early days of the game I never saw the timer go less than 56 seconds.

I honestly don’t understand why the players press the button like this, maybe theydon’t have clear the rules for winning or simply prefer to have the participation’sNFT immediately, who knows …

Whatever the reason that pushes players to press the button, assuming that overtime the players begin to be fewer and therefore gradually increase the timebetween one click and the next; we can hypothesize (without any pretense of formal modeling of the phenomenon) that the increase in the average time between oneclick and the other follows an exponential function such as:

where alpha = 1,3 Sec and beta = 0,1

Estimated Delta time between clicks as the days pass up to the 60 second threshold
Estimated Delta time between clicks as the days pass up to the 60 second threshold

Plotting the trend of time we can deduce that, according to this model, the timebetween one click and the other should reach the fateful 60 seconds around the 46thday from the start of the game with a total of about 1 million and 141 thousandplayers, equal to a 3.1% redemption of potential players.

Estimation of the number of players over the days based on the increase in the time delta between one clickand the next
Estimation of the number of players over the days based on the increase in the time delta between one clickand the next

Obviously these parameters are partially empirical on the early days of the game and partially a priori (type of growth curve and 10% growth), but having no longer time series to analyze is the best proxy we can make at the moment; we will see at the end of the game if they are realistic.

In any case, the thing that interests us for our purposes is that we have about 40 days to build and put our robot online and that the game will probably end before reaching the 90-day limit set by the regulation.

Let’s build our Robot!
Having established that there should be enough time to develop a software robot toparticipate in the game, we can now devise the main components that our softwaremust have.

Our Robot must be able to do the following things:

  • Open a browser and navigate to the Bitcoin Button Game page
  • Accept Privacy, cookies, regulations etc.
  • Log in to the platform
  • Listen until it’s time to click
  • Click the button at the appropriate time
  • Click again in case of error
  • Send a notification via Telegram
  • Monitor the 60 seconds after the click to see if the click was successful

To do this, as previously mentioned, we will use R as well as the R version of Selenium which is a project that includes a series of tools and libraries for browserautomation; here Selenium will be used to guide our browser and interact with itvia scripts for our purposes; We will also build a small Telegram Bot controlled bythe R program to send an alert to the mobile phone as soon as the click is made soas to be easily warned at any time.

Everything will be deployed on a cloud hosting service in order to keep it accessiblefor the entire time of the game.

We will use a Linux Debian environment, R 3.6.1 and Rstudio 2022.02.1–46 .

In the Debian installation we’ll also need the libraries ssl, curl, xml etc.

libssl1.0.2
libcurl4-openssl-dev
libxml2-dev

As well we’ll need the geckodrivers to allow Selenium to interact with the browser.

sudo wget
https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz
sudo sh -c ‘tar -x geckodriver -zf geckodriver-v0.30.0-linux64.tar.gz -O > /usr/bin/geckodriver’
sudo chmod +x /usr/bin/geckodriver

Creation of the telegram Bot for alerts
We create our Telegram Bot to use it as a communication channel; to create a Telegram Bot you need to contact @BotFather and send the messages \start and then \newbot

The BotFather will ask for a username and a name and will generate anauthentication token that we save in an R variable.

My Telegram Chat with my Telegram Bot
My Telegram Chat with my Telegram Bot

The Telegram bot is ready, we need to discover the chat id that we will use to sendmessages; we use the getUpdates() method to retrieve the chat id.

bot = Bot(token = bot_token)
# The first time, you will need the chat id (which is the chat where you will get the notifications)
updates = bot$getUpdates()
# Sending text
message_to_bot=sprintf(‘Hi Bro’)
bot$sendMessage(chat_id = Chat_Id_num , text = message_to_bot)
The telegram Bot is able to send messages
The telegram Bot is able to send me messages

The bot will not listen for messages from chats, passively will send informationthrough the robot that will play the bitcoin button.

Let’s build the Robot to play
At this point we will have to load (and install if not already present in the Renvironment) the R libraries for Selenium and Telegram

library(rvest)
library(xml2)
library(RSelenium)
library(dplyr)
library(rlist)
library(telegram.bot)

Let’s start now to open the browser and navigate to the page of the bitcoin buttongame

##++++++++++++++++++++++++++++ LOAD Selenium Drivers
rD <- rsDriver(browser = “firefox”, port = 6768L)
remDr <- rD[[“client”]]
## — — — — — — — — — — — — — — END LOAD Selenium Drivers
##++++++++++++++++++++++++++++ Navigate to URL
url <- "https://www.binance.com/en/activity/bitcoin-button-game"
remDr$navigate(url)
Sys.sleep(2)
## — — — — — — — — — — — — — — END Navigate to URL

We often use waits (sys.sleep) in the code that allow the browser to load, update andbe available for selenium to run

The Browser is now controlled by the robot
The Browser is now controlled by the robot

As the image shows, the browser is now controlled by our Robot. The robot icon inthe address bar makes us understand that it is interacting with the robot, butnothing would prevent it from interacting simultaneously with a human interaction.

To identify the various components of the page with which to interact we will usesome different methods for convenience and simplicity by identifying theindividual elements of the page, or through the xpath of the element that allows youto point to a single element through the html path of the element, either throughthe reference of the css class or through the id of the single element.

These methods are very powerful and allow you to interact with any element of thepage; to find the element, it will be necessary to analyze the html code of the pageand identify the codes and paths of interest on the page.

Once we have navigated to the page of interest, we must first accept the disclaimeron cookies, let the browser press the accept button:

##+++++++++++++++++++++++++++++++ ACCEPT COOKIE DISCLAIMER
webEle <-remDr$findElements(using = ‘xpath’, “//*[@id=\”onetrust-accept-btn-handler\”]”)
webEle[[1]]$clickElement()
Sys.sleep(1)
## — — — — — — — — — — — — — — — END ACCEPT COOKIE DISCLAIMER

Having identified the element, click on the button ( clickElement() ) and wait for themessage to disappear.

Login with twitter Account using the Robot
We now have a fundamental step, that is to log in to be able to play with ouraccount; the game provides the ability to use two types of accounts, Twitter orBinance; having dual factor authentication active on my Binance account whichrequires external interaction with the authenticator, I decided to use the social loginvia Twitter which only requires sending user and password via input form;However, Twitter checks whether there is a login from a new device or location, itwill therefore first be necessary to manually log in from the machine on which wewill deploy our robot and carry out the verification and authorization procedure viaemail; once our account has been verified, the next few times it will be sufficient tolog in with user and password, making our robot autonomous.

Login Button the Robot has to click
#click on login link
webEle <-remDr$findElements(using = “css”,value = “.btn-sign-in”)
webEle[[1]]$clickElement()
Sys.sleep(2)

We find ourselves on the page to choose the type of account to log in betweentwitter and Binance, click on twitter and also put the flag on the terms andconditions

#BitcoinButtonGame login page
# Accept term and conditions
webEle <-remDr$findElements(using = “css”,value = “.css-3kwgah”)
webEle[[1]]$clickElement()
# Click Sign In
webEle <-remDr$findElements(using = “css”,value = “.btn-sign-in-twitter > div:nth-child(4)”)
webEle[[1]]$clickElement()
Sys.sleep(2)

We then find ourselves in the twitter social login page, insert Username andPassword, previously saved in dedicated variables, in the form fields (with thesendKeysToElement function), and send the form to access.

Twitter Social Login Page
#send username
username <- remDr$findElement(using = “id”, value = “username_or_email”)
username$sendKeysToElement(list(twitter_user))
#send password and Enter
passwd <- remDr$findElement(using = “id”, value = “password”)
passwd$sendKeysToElement(list(twitter_pass, “\uE007”))
Sys.sleep(3)

Let’s put the robot listening, ready to push the Button
We then logged in, and we are ready to put the robot listening to wait for the rightmoment to click on the button.

First we have lightly analyze of how much is the minimum reaction time of ourrobot; so we simulate the operation of the click without really clicking to see howlong it passes from when the robot sees the right moment on the timer and howlong it takes to react and push the button; from the tests carried out (setting the 55seconds as if it were the reference zero) we see that the execution time of thevarious steps up to the click varies from 0 to 4 hundredths of a second; for safetyand to have a minimum margin, let’s set the Robot to click on the button when itsees 00 seconds, still having a few tenths of a second to complete the click.

The other point to consider is the click conflict; if two players press the button atthe same time, the game blocks them, inviting them to try again:

Warning when multiple users click the button at the same time

To manage this case we set a certain number of retries (without particular logic, therobot will try to click again if it sees 00 again) so as not to miss the case in which youhave clicked with another player, but be ready to click again on the next occasion.

Now we have to retrieve the pointers to the two fundamental objects of the page thatis the timer and the bitcoin button, then we point the two elements with the findelements method and we listen:

#Total Partecipants
partecipants <-remDr$findElements(using = ‘xpath’, “*//div[contains(@class,\”th68ec\”)]”)
print(paste(“Already Clicked at Start: “, partecipants[[2]]$getElementText()))
## Point to the Bitcoin Timer
BitcoinTimer <-remDr$findElements(using = ‘xpath’, “*//div[contains(@class,\”w39bvu\”)]”)
#Point To The Bitcoin Button
BitcoinButton <-remDr$findElements(using = “css”,value = “.bitcoin-btn-core > path:nth-child(5)”) #BITCOIN BUTTON
print(“Listening…”)

The Timer is a list of 4 objects, in which each object indicates a timer number that istens of seconds, seconds, tenths of a second, hundredths of a second.

To simulate a person who watches the timer continuously, we put ourselves in aninfinite loop, at each loop we read the timer value and wait for tens of seconds andseconds to be at 00, at which point we proceed with the click on the button.

while (Click_Try < max_Try){
Sec1 <- as.numeric(BitcoinTimer[[1]]$getElementText())
Sec2 <- as.numeric(BitcoinTimer[[2]]$getElementText())
Sec3 <- as.numeric(BitcoinTimer[[3]]$getElementText())
Sec4 <- as.numeric(BitcoinTimer[[4]]$getElementText())
if (Sec1==0 & Sec2 == 0) {
BitcoinButton[[1]]$clickElement()
print (“NOW Click!”)
print(paste(BitcoinTimer[[1]]$getElementText(),BitcoinTimer[[2]]$getElementText(),BitcoinTimer[[3]]$getElementText(),BitcoinTimer[[4]]$getElementText()))
print(paste(“partecipants at Click: “, partecipants[[2]]$getElementText()))
Click_Try <- Click_Try + 1
# ######### Screenshot log
remDr$screenshot(file = paste0(root_dir,’RSchreenshot/Screenshot_At_1_Click_try’,Click_Try,’.png’))
# ########### Send screenshot through telegram Botbot$sendPhoto(chat_id = Chat_Id_num, photo = paste0(root_dir,’RSchreenshot/Screenshot_At_1_Click_try’,Click_Try,’.png’))
Sys.sleep(4)
}
}

In the procedure we have therefore inserted logs of the number of participants atthe time of the click and a screenshot of the moment of the click.

The screenshot is then sent by our telegram bot on the chat we created.

We close the script by logging off and closing the browser.

Go Robot! Play and win!
So how did it go with our robot? Did it have any problems?

I started the robot on April 6 at the 22nd day of starting the game, with about 700Kplayers already clicking the button, according to our model we should be abouthalfway through the game with still about 24 days to wait, so we expect that the botwill contact us in about twenty days on our telegram.

On April 19th the first surprise, I wake up in the morning and find a message frommy bot on the chat, checking the screenshot I received I see that the bot had an error:

My Robot clicked the Button, but something went wrong, let’s try again

Something went wrong, I immediately checked the game online, and the counter isstill there counting down.

I immediately open my server fearing that the bot has clicked the button at thewrong time, but I notice that the browser has crashed, so no real click, but a “fake”click because probably the browser has had some problems and our bot saw a 0timer which was not true.

Ok, luckily we’re still in the game, let’s clean up the environment and restart our bot.

My robot no longer makes itself heard for days and days, we are approaching the46th day that the model envisaged as the completion of the game …

We also pass the 46th day without the bot making itself heard …

After a few days I received the notification of my click! This time without errors, my bot really clicked …

Will I have won?

The game ended on May 7, 2022, 7 days after the day the model predicted with1,142,779 players, very very close to the value predicted by the initial model.

Binance Tweet: #BitcoinButtonGame finished

Will my robot be the winner of the Bitcoin Button Game?

This is not the place to reveal it, but the game and the construction of the bot was alot of fun and constructive and who knows that it will not be useful in othercompetitions too!

--

--

Daniele De Faveri

Explorer of Web3's Transformative Realm, Data Strategist and Chartered Blockchain Analyst