Bustabit Scripts

This repository provides documentation for Bustabit’s autobetting and scripting system on bustabit.com.


1. How to Write a Script

Bits vs Satoshis

Important: The communication between the client and the server occurs in satoshis, even though the user interface displays values in bits.

Conversion formulas:

  • bits → satoshis: Math.round(bits * 100)
  • bits → bitcoins: bits / 1e6
  • satoshis → bits: satoshis / 100
  • satoshis → bitcoins: satoshis / 1e8
  • bitcoins → bits: Math.round(bitcoins * 1e8) / 1e6
  • bitcoins → satoshis: Math.round(bitcoins * 1e8)

2. The UI Config

A key feature of Bustabit’s scripting system is the ability to define a custom user interface for input before starting the script. This makes it user-friendly and allows scripts to interact with user-defined variables.

Example of defining a simple UI config:

var config = {
name: { value: '', type: 'text', label: 'What is your name?' },
maxBet: { value: 1e8, type: 'balance', label: 'Max Bet' },
colors: {
value: 'red', type: 'radio', label: 'Pick a color',
options: {
red: { value: 'red', type: 'noop', label: 'Red' },
blue: { value: 'blue', type: 'noop', label: 'Blue' },
}
}
};

log('hello', config.name.value, 'you chose the color', config.colors.value);

3. Input Objects

The UI Config defines Input Objects, which correspond to form fields in the UI. Here are the different types of input:

  • text: <input type="text"> field. var config = { name: { value: '', type: 'text', label: 'What is your name?' } };
  • noop: A non-interactive placeholder used within other components like radio buttons. var config = { noopExample: { type: 'noop', label: 'Demonstrating noop' } };
  • radio: Maps to HTML radio buttons. var config = { colors: { value: 'red', type: 'radio', label: 'Pick a color', options: { red: { value: 'red', type: 'noop', label: 'Red' }, blue: { value: 'blue', type: 'noop', label: 'Blue' }, } } };
  • checkbox: Maps to HTML checkboxes. var config = { red: { type: 'checkbox', label: 'Red', value: true }, yellow: { type: 'checkbox', label: 'Yellow', value: false }, blue: { type: 'checkbox', label: 'Blue', value: true } };
  • balance: A number input field for values in bits, exposed as satoshis to the script. var config = { baseBet: { value: 100, type: 'balance', label: 'Base Bet' } };
  • multiplier: Accepts a payout multiplier (e.g., 2.0). var config = { basePayout: { value: 2, type: 'multiplier', label: 'Payout' } };
  • combobox: Maps to HTML <select> dropdowns. var config = { colors: { value: 'red', type: 'combobox', label: 'Pick a color', options: { red: { label: 'Red' }, blue: { label: 'Blue' }, } } };

4. Required vs Optional Inputs

By default, all inputs are required. To make an input optional, set optional: true.

Example:
name: { value: '', type: 'text', label: 'What is your name?' },
colors: {
optional: true,
type: 'radio', label: 'Pick a color',
options: {
red: { value: 'red', type: 'noop', label: 'Red' },
blue: { value: 'blue', type: 'noop', label: 'Blue' },
}
}
};

log('hello', config.name.value);

if (config.colors.value) {
log('you chose the color', config.colors.value);
} else {
log('you did not choose a color');
}


5. Interacting with the Game

Once the script configuration is set, the rest of the script interacts with the game when the user clicks “Run Script.”

The Engine API

The engine object provides methods for interacting with the game. It supports the following events and methods:

  • Events:
    • "GAME_STARTING": Triggered 5 seconds before a game starts.
    • "GAME_STARTED": Bets are no longer accepted.
    • "GAME_ENDED"
    • "BET_PLACED": When a player places a bet.
    • "PLAYERS_CHANGED": When a player makes a bet or cashes out.
    • "CASHED_OUT": When a player cashes out.
  • Methods:
    • engine.bet(satoshis, payout): Place a bet with a specified payout multiplier.
    • engine.getState(): Returns the current state of the engine.
    • engine.getCurrentBet(): Returns the current bet or false if no bet is placed.
    • engine.isBetQueued(): Checks if a bet is queued for the next game.
    • engine.cancelQueuedBet(): Cancels the queued bet.
    • engine.cashOut(): Attempts to cash out the current bet.
  • Properties:
    • engine.history: Stores game history.
    • engine.history.first(): The latest game in progress.
    • engine.history.last(): The oldest game in the history.
    • engine.history.toArray(): Returns the history as an array.

6. A Game Object

The game object stores information about individual games in engine.history. Key properties include:

  • game.id: The game ID.
  • game.hash: The game hash.
  • game.bust: The multiplier at which the game crashed (null if the game is in progress).
  • game.cashedAt: The multiplier at which the player cashed out (null if the player did not cash out or the game crashed before cashing out).
  • game.wager: The player’s wager (in satoshis).

7. The UserInfo Store

The userInfo object provides details about the current logged-in user. Key properties include:

  • userInfo.balance: User’s balance in satoshis.
  • userInfo.bets: Total bets made by the user.
  • userInfo.wagered: Total wagered amount by the user.
  • userInfo.profit: User’s profit.

8. The Chat Store

The chat object provides access to public chat channels. Key events and properties include:

  • Events: "FRIENDS_CHANGED": When friends are added or removed.
  • Properties: chat.channels: A Map of channels with their message history.

9. Displaying Output

You can use log() to print messages in the script’s log window for debugging or user feedback:

log('Script is running');

10. Notifications

To send browser notifications from your script, use notify(message). This is helpful when you want to be notified of important events even if you’re working in another tab. Ensure that browser notifications are enabled for bustabit.com.


11. Stopping the Script

To stop the script, use stop(reason). The reason will be displayed in the script’s log. Example:

if (userInfo.balance < config.wager.value) {
  stop('Insufficient balance to place the bet');
}

12. Verifying Game Results

To verify game results, the following functions are available:

  • gameResultFromSignature(hash, id): Returns the game result for a specific hash and game ID.
  • gameResultFromHash(hash): Returns the game result for a given hash.
  • SHA256FromHex(value): Returns the SHA256 hash of a hexadecimal value.
  • SHA256(value): Returns the SHA256 hash of a string value.

Example:

gameResultFromSignature('e1d3966787cb0ce17e9690a1f518fa58bd61a14fb556c55621fd6f061d430172', 10004381).then(log);

This version streamlines the explanations and provides examples to clarify the concepts and actions related to Bustabit’s scripting system.