Skip to main content

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

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ronin_casino-0.3.0.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ronin_casino-0.3.0-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

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

Hashes for ronin_casino-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6313e9ae5f79adbbb5cdffb8862ce1947c05e0d376d386287ed549157361e92e
MD5 17beb56bf037f287a3c5336d73f588a9
BLAKE2b-256 d0f9eb610b82c8388f3f6908a26a110db1618ef042ef5db53306a139b8fe63cc

See more details on using hashes here.

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

Hashes for ronin_casino-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f22c9bb0ccabaa14368fa96f01bcea915c71a75030b82f84ebb37a65f072e00b
MD5 0d5310a5ad3bae6e4c524ddda0a37563
BLAKE2b-256 c56d02b5f49d88aed58f5e0b66586e1a46331499fe6c675a04e0a4a6a0ae6828

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page