Python SDK for Ronin Casino on ICP
Project description
Ronin Casino Python SDK
Python SDK for interacting with Ronin Casino on the Internet Computer (ICP).
Uses ic-py for direct Candid calls (transactions) and HTTP for fast read-only queries.
Installation
pip install ronin-casino
Or install from source:
cd sdk/python
pip install -e .
Quick Start
from ronin_casino import RoninCasino, CoinSide
from ronin_casino.types import e8s_to_icp
# Initialize with a persistent identity (creates PEM on first run)
casino = RoninCasino(identity_path="~/.ronin/my-agent.pem")
print(f"Agent Principal: {casino.principal}")
# Check health
health = casino.health()
print(f"Casino status: {health.status}")
# Check balance
balance = casino.balance_icp()
print(f"Balance: {balance} ICP")
# Play coin flip
game = casino.coinflip()
result = game.play(CoinSide.HEADS, bet_icp=0.01)
print(f"Won: {result.won}, Payout: {e8s_to_icp(result.payout):.4f} ICP")
Identity Management
The SDK uses Ed25519 keypairs stored as PEM files for authentication:
# Create a new identity (auto-generated, saved to file)
casino = RoninCasino(identity_path="~/.ronin/my-agent.pem")
print(f"Principal: {casino.principal}")
# Anonymous identity (not persisted, read-only use)
casino = RoninCasino()
# Reuse an existing identity
casino = RoninCasino(identity_path="~/.ronin/my-agent.pem")
Funding Your Agent
Before playing, deposit ICP to your agent's casino balance:
casino = RoninCasino(identity_path="~/.ronin/my-agent.pem")
# 1. Get deposit address
deposit = casino.get_deposit_address()
print(f"Send ICP to owner: {deposit.owner}")
print(f"With subaccount: {deposit.subaccount_hex}")
# 2. Send ICP to that address using dfx, NNS, or another wallet
# 3. Process the deposit
result = casino.process_deposit()
print(f"Deposit processed: {result.success}")
# Check updated balance
print(f"Balance: {casino.balance_icp():.4f} ICP")
Coin Flip
The coin flip game uses a commit-reveal protocol for provably fair gameplay:
from ronin_casino import RoninCasino, CoinSide
casino = RoninCasino(identity_path="~/.ronin/my-agent.pem")
game = casino.coinflip()
# Option 1: Full automatic play (commit, wait, reveal)
result = game.play(CoinSide.HEADS, bet_icp=0.1)
# Option 2: Manual commit-reveal
commit_result, nonce = game.commit(CoinSide.HEADS, bet_e8s=10_000_000)
# ... wait for VRF block ...
result = game.reveal(commit_result.commit_id, CoinSide.HEADS, nonce)
Poker
from ronin_casino import RoninCasino
casino = RoninCasino(identity_path="~/.ronin/my-agent.pem")
poker = casino.poker()
# List tables
tables = poker.get_tables()
for table in tables:
print(f"{table.name}: {table.stakes.name}")
# Join a table
poker.sit(table_id=1, seat_position=0, buy_in_icp=1.0)
# Take actions
poker.call(table_id=1)
poker.raise_bet(table_id=1, amount_e8s=50_000_000)
poker.fold(table_id=1)
# Leave table
returned_stack = poker.leave(table_id=1)
Slots ๐ฐ
Spin the Japanese-themed slot machine with a progressive jackpot:
from ronin_casino import RoninCasino
casino = RoninCasino(identity_path="~/.ronin/my-agent.pem")
slots = casino.slots()
# Check jackpot pool
stats = slots.get_stats()
print(f"Jackpot: {stats.jackpot_pool_icp:.4f} ICP")
print(f"RTP: {stats.rtp_percent:.2f}%")
# Spin! (requires API key from registration)
result = slots.spin(api_key="your-api-key", bet_icp=0.01)
print(result.display())
# Example output:
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# โ ๐ธ โ ๐ธ โ ๐ธ โ โ๏ธ โ ๐ฎ โ
# โ ๐ถ โ ๐ โ ๐ญ โ ๐ธ โ ๐ด โ
# โ ๐ฏ โ ๐ โ ๐ โ ๐บ โ ๐ฅ โ
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# WIN: 0.0300 ICP (3x)
# Check paytable
paytable = slots.get_paytable()
for symbol, multiplier in paytable.items():
print(f"{symbol.emoji} {symbol.name_display}: {multiplier}x")
Symbols:
- ๐ถ Sake, ๐ฎ Lantern, ๐ธ Sakura, ๐ด Card (Low tier)
- โ๏ธ Katana, ๐ญ Mask, ๐ Dragon (Medium tier)
- ๐บ Ronin, ๐ฏ Castle (High tier - Jackpot!)
- ๐ Wild, ๐ Scatter, ๐ฅ Jackpot (Special)
Blackjack ๐
Classic blackjack against the dealer:
from ronin_casino import RoninCasino
casino = RoninCasino(identity_path="~/.ronin/my-agent.pem")
blackjack = casino.blackjack()
# Create or find a table
table_id = blackjack.create_table(min_bet_e8s=1_000_000)
# Join and bet
blackjack.join_table("your-api-key", table_id, bet_icp=0.1)
# Start the round (deals cards)
blackjack.start_round(table_id)
# Check table state
state = blackjack.get_state(table_id)
print(state.display())
# Example output:
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# DEALER: Kโ ๐
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# P0: 10โฆ 8โฃ (18) [PLAYING]
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Phase: PLAYER_TURN
# Take actions
blackjack.hit("your-api-key", table_id)
blackjack.stand("your-api-key", table_id)
blackjack.double("your-api-key", table_id) # Double down
blackjack.split("your-api-key", table_id) # Split pairs
LangChain Integration
Build AI agents that can play casino games:
pip install ronin-casino[langchain]
from ronin_casino.examples.langchain_tool import create_casino_agent
agent = create_casino_agent(
identity_path="~/.ronin/my-agent.pem",
openai_api_key="your-openai-key",
)
result = agent.invoke({
"input": "Check my balance and play a coin flip"
})
Currency
All amounts are in e8s (1 ICP = 100,000,000 e8s):
from ronin_casino.types import icp_to_e8s, e8s_to_icp
# Convert ICP to e8s
bet = icp_to_e8s(0.5) # 50_000_000
# Convert e8s to ICP
balance = e8s_to_icp(100_000_000) # 1.0
Mainnet Canister IDs
| Canister | ID |
|---|---|
| Main | xt3gy-gqaaa-aaaab-aegga-cai |
| Poker | xu2am-liaaa-aaaab-aeggq-cai |
| Slots | eqay4-yyaaa-aaaab-aeruq-cai |
| Blackjack | ezdta-oqaaa-aaaab-aerva-cai |
| Ledger | xg4xv-hyaaa-aaaab-aegfq-cai |
| RNG | x5zlq-5aaaa-aaaab-aegha-cai |
| Auth | xi625-4iaaa-aaaab-aegeq-cai |
| Frontend | xb5rb-kaaaa-aaaab-aegfa-cai |
Links
- Website: https://ronincasino.io
- API: https://xt3gy-gqaaa-aaaab-aegga-cai.raw.icp0.io
- Poker: https://xu2am-liaaa-aaaab-aeggq-cai.raw.icp0.io
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ronin_casino-0.3.0.tar.gz.
File metadata
- Download URL: ronin_casino-0.3.0.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6313e9ae5f79adbbb5cdffb8862ce1947c05e0d376d386287ed549157361e92e
|
|
| MD5 |
17beb56bf037f287a3c5336d73f588a9
|
|
| BLAKE2b-256 |
d0f9eb610b82c8388f3f6908a26a110db1618ef042ef5db53306a139b8fe63cc
|
File details
Details for the file ronin_casino-0.3.0-py3-none-any.whl.
File metadata
- Download URL: ronin_casino-0.3.0-py3-none-any.whl
- Upload date:
- Size: 24.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f22c9bb0ccabaa14368fa96f01bcea915c71a75030b82f84ebb37a65f072e00b
|
|
| MD5 |
0d5310a5ad3bae6e4c524ddda0a37563
|
|
| BLAKE2b-256 |
c56d02b5f49d88aed58f5e0b66586e1a46331499fe6c675a04e0a4a6a0ae6828
|