DEV Community

Cover image for How I Automated a Bitcoin-Based Betting Platform Using JavaScript
Rick Humade
Rick Humade

Posted on

How I Automated a Bitcoin-Based Betting Platform Using JavaScript

Why I Built This
I’ve been experimenting with browser automation using JavaScript to interact with real-time interfaces — mainly as a way to learn about DOM manipulation and user scripting.

One of my test environments involved automating actions on a Bitcoin-based betting platform that uses a simple interface with predictable interactions.

The challenge:
Can you write a script that adjusts your betting amount dynamically, depending on whether you win or lose?

Answer: Yes — using only a few lines of JavaScript.

The Concept

  • Base bet starts at a fixed amount
  • If you lose, the bet increases (Martingale strategy)
  • If you win, the bet resets
  • The script tracks your results in the console
// Bot Made By SpheXian you can change the basebet based on you balance // Bot Made By SpheXian var baseBet = 10; // In sats var baseMultiplier = 1.10; // Bot Made By SpheXian var variableBase = false; // Bot Made By SpheXian var streakSecurity = 15; // Number of loss-streak you wanna be safe for. Increasing this massively reduces the variableBase calculated. (1-loss = 20%, 2-loss = 5%, 3-loss = 1.25% of your maximum balance). Recommended: 8+ var maximumBet = 99999999; // Bot Made By SpheXian // Bot Made By SpheXian // Variables - Do not touch! var baseSatoshi = baseBet * 100; // Calculated var currentBet = baseSatoshi;// Bot Made By SpheXian var currentMultiplier = baseMultiplier;// Bot Made By SpheXian var currentGameID = -1;// Bot Made By SpheXian var firstGame = true;// Bot Made By SpheXian var lossStreak = 0;// Bot Made By SpheXian var coolingDown = false;// Bot Made By SpheXian // Bot Made By SpheXian // Initialization console.log('====== HustleBot ======');// Bot Made By SpheXian console.log('My username is: ' + engine.getUsername());// Bot Made By SpheXian console.log('Starting balance: ' + (engine.getBalance() / 100).toFixed(2) + ' sats');// Bot Made By SpheXian var startingBalance = engine.getBalance();// Bot Made By SpheXian // Bot Made By SpheXian if (variableBase) { console.warn('[WARN] Variable mode is enabled and not fully tested. Bot is resillient to ' + streakSecurity + '-loss streaks.'); }// Bot Made By SpheXian // Bot Made By SpheXian // On a game starting, place the bet. engine.on('game_starting', function(info) {console.log('====== New Game ======'); console.log('[Bot] Game #' + info.game_id); currentGameID = info.game_id; if (coolingDown) { if (lossStreak == 0) { coolingDown = false; } else { lossStreak--; console.log('[Bot] Cooling down! Games remaining: ' + lossStreak); return; } } if (!firstGame) { // Display data only after first game played. console.log('[Stats] Session profit: ' + ((engine.getBalance() - startingBalance) / 100).toFixed(2) + ' sats'); // Bot Made By SpheXian console.log('[Stats] Profit percentage: ' + (((engine.getBalance() / startingBalance) - 1) * 100).toFixed(2) + '%'); // Bot Made By SpheXian } // Bot Made By SpheXian if (engine.lastGamePlay() == 'LOST' && !firstGame) { // Bot Made By SpheXian lossStreak++; // Bot Made By SpheXian var totalLosses = 0; // Total satoshi lost. var lastLoss = currentBet; // Store our last bet. while (lastLoss >= baseSatoshi) { // Until we get down to base bet, add the previous losses. totalLosses += lastLoss;// Bot Made By SpheXian lastLoss /= 4;// Bot Made By SpheXian } // Bot Made By SpheXian if (lossStreak > streakSecurity) { // If we're on a loss streak, wait a few games! coolingDown = true;// Bot Made By SpheXian return;// Bot Made By SpheXian } // Bot Made By SpheXian currentBet *= 7; // Then multiply base bet by 7! currentMultiplier = 1.00 + (totalLosses / currentBet); } else { // Otherwise if win or first game: lossStreak = 0; // If it was a win, we reset the lossStreak. if (variableBase) { // If variable bet enabled. // Variable mode resists (currently) 1 loss, by making sure you have enough to cover the base and the 4x base bet. var divider = 100;// Bot Made By SpheXian for (i = 0; i < streakSecurity; i++) { divider += (100 * Math.pow(4, (i + 1)));// Bot Made By SpheXian } newBaseBet = Math.min(Math.max(1, Math.floor(engine.getBalance() / divider)), maximumBet * 100); // In sats newBaseSatoshi = newBaseBet * 100;// Bot Made By SpheXian if ((newBaseBet != baseBet) || (newBaseBet == 1)) { console.log('[Bot] Variable mode has changed base bet to: ' + newBaseBet + ' sats'); baseBet = newBaseBet;// Bot Made By SpheXian baseSatoshi = newBaseSatoshi;// Bot Made By SpheXian } } // Update bet. currentBet = baseSatoshi; // in Satoshi currentMultiplier = baseMultiplier;// Bot Made By SpheXian } // Message and set first game to false to be sure. console.log('[Bot] Betting ' + (currentBet / 100) + ' sats, cashing out at ' + currentMultiplier + 'x'); firstGame = false;// Bot Made By SpheXian if (currentBet <= engine.getBalance()) { // Ensure we have enough to bet if (currentBet > (maximumBet * 100)) { // Ensure you only bet the maximum. console.warn('[Warn] Bet size exceeds maximum bet, lowering bet to ' + (maximumBet * 100) + ' sats'); currentBet = maximumBet;// Bot Made By SpheXian } engine.placeBet(currentBet, Math.round(currentMultiplier * 100), false); } else { // Otherwise insufficent funds... if (engine.getBalance() < 100) { console.error('[Bot] Insufficent funds to do anything... stopping'); engine.stop(); } else { console.warn('[Bot] Insufficent funds to bet ' + (currentBet / 100) + ' sats.'); console.warn('[Bot] Resetting to 1 sats basebet'); baseBet = 1; baseSatoshi = 100;// Bot Made By SpheXian } } });// Bot Made By SpheXian // Bot Made By SpheXian engine.on('game_started', function(data) {// Bot Made By SpheXian if (!firstGame) { console.log('[Bot] Game #' + currentGameID + ' has started!'); } });// Bot Made By SpheXian // Bot Made By SpheXian engine.on('cashed_out', function(data) { if (data.username == engine.getUsername()) { console.log('[Bot] Successfully cashed out at ' + (data.stopped_at / 100) + 'x'); } });// Bot Made By SpheXian // Bot Made By SpheXian engine.on('game_crash', function(data) { if (!firstGame) { console.log('[Bot] Game crashed at ' + (data.game_crash / 100) + 'x'); } });// Bot Made By SpheXian // Bot Made By SpheXian // Bot Made By SpheXian 
Enter fullscreen mode Exit fullscreen mode

The Platform
This was tested on a Bitcoin-based browser platform with a live interface and real crypto wagering.

If you're curious, you can check out the site here:
HustleBTC

Final Thoughts
JavaScript browser scripting is a great way to learn automation by directly interacting with the DOM. Whether you're building real tools or just learning how interfaces work under the hood, these experiments can take your skills further.

Let me know what you'd automate next

Top comments (0)