escrow-program is a smart contract built on Solana that facilitates a simple gambling game between two users. The game revolves around betting on the ETH/USDC price movement, where players bet whether the price will increase or decrease by 5%. The contract holds the entry fees in escrow and sends the funds to the winner once a price change condition is met.
The goal of this contract is to facilitate a game where two users compete by betting on the ETH/USDC price. Users can bet on either an increase or decrease of the ETH price by 5%. Once one of these thresholds is reached, the winning player can call the closeGame function, and the escrow contract will verify the win and send the entry fees to the winner.
-
Entry into game for Player 1:
- $1000 USDC entrance fee.
- Player selects either an increase or decrease of the ETH price.
-
Entry into game for Player 2:
- $1000 USDC entrance fee.
- Must choose the opposite of Player 1’s choice.
- Entry allowed only if the price has not fluctuated by more than 1% since Player 1 entered.
-
Withdrawing of entry:
- Only allowed for Player 1 if Player 2 has not entered the game yet.
- Once Player 2 enters, no withdrawals are permitted.
-
Closing the game:
- The winner, once determined by a 5% price movement in their favor, calls the
closeGamefunction to receive the entry fees.
- The winner, once determined by a 5% price movement in their favor, calls the
git clone https://github.com/dariusjvc/solana-escrow-gambling.git
cd solana-escrow-gamblingAfter cloning the repository, install the necessary dependencies:
npm installThe program uses the default Solana wallet located at:
$HOME/.config/solana/id.json
This file represents both the payer and the account of the player1. It should have enough SOL for transaction fees. Additionally, two more wallets are used by the program:
/wallets/
├── escrow.json # Escrow account for holding entry fees
├── player2.json # Player 2's wallet
These accounts, along with the token accounts to receive USDC winnings, are automatically generated when you run the initialization script:
./init_accounts.shEnsure all wallets have enough SOL for transaction fees and the required USDC balances for testing.
Run:
./init_accounts.sh./cicd.shAfter deployment:
- The
DEPLOYED_PROGRAM_ADDRESSand the rest of the variables will be automatically written to your.envfile.
Once .env is updated:
npm run test- Create Game –
entry_price = 0fetches price from Pyth Oracle. - Oracle Price Test – No parameters.
- Join Game –
last_price = 0fetches price from Pyth Oracle. - Withdraw Game – No parameters.
- Settle Game –
last_price = 0fetches price from Pyth Oracle. - Close Game – No parameters.
- Node Version: v18.20.4 or higher.
- Solana CLI Version: 2.3.7 (needed for updated account metas order in SPL token program).
- Always run
init_accounts.shbeforecicd.shin a fresh setup. - The
id.jsonwallet replaces the oldpayer.jsonand is used as the main payer for transactions.
This program demonstrates a simple escrow-based gambling game on Solana, integrating with the Pyth Oracle for real-time price data. It is a fully tested, ready-to-deploy base for more advanced escrow or betting applications.