Skip to main content

Python SDK for the Rollhub Dice Agent API — provably fair dice betting for AI agents

Project description

🎲 rollhub-dice

PyPI version Python License: MIT

Python SDK for the Rollhub Dice Agent API — provably fair dice betting for AI agents.

Quick Start

pip install rollhub-dice
from rollhub_dice import DiceAgent

agent = DiceAgent(api_key="rh_sk_...")
result = agent.bet(target=0.5, direction="over", amount=100)
print(result)  # Bet #1: rolled 0.7234 → WIN (payout: 198)

Register a New Agent

agent = DiceAgent.register(wallet_address="0xYourWallet...")
print(agent.api_key)  # rh_sk_...

API Reference

DiceAgent(api_key, base_url="https://agent.rollhub.com/api/v1")

Create a client with an existing API key. Use base_url to point at staging:

agent = DiceAgent(api_key="rh_sk_...", base_url="https://agent.rollhub.com/api/v1")

DiceAgent.register(wallet_address, base_url) → DiceAgent

Register a new agent wallet and return an authenticated client.

agent.balance() → Balance

bal = agent.balance()
print(bal.balance_usd)   # "10.00"
print(bal.balance_cents)  # 1000

agent.bet(target, direction, amount, client_secret) → BetResult

Place a dice bet. Amount is in cents.

Param Default Description
target Threshold (0.0–1.0)
direction "over" "over" or "under"
amount 100 Wager in cents
client_secret auto Your secret for verification
result = agent.bet(target=0.5, direction="over", amount=200)
print(result.win, result.roll, result.payout)

agent.bets() → List[Bet]

Get your bet history.

agent.verify(bet_id) → VerifyResult

Verify any bet was provably fair:

v = agent.verify(bet_id=1)
print(v.verified)  # True

Provably Fair

Every bet is verifiable using SHA3-384 HMAC:

  1. Before you bet, Rollhub publishes server_seed_hash = SHA3-384(server_secret)
  2. You provide a client_secret (auto-generated if omitted)
  3. Roll = first 8 bytes of HMAC-SHA3-384(server_secret, client_secret:nonce)[0, 1)
  4. After the bet, the server_secret is revealed so you can recompute the roll

You can also verify locally:

from rollhub_dice import verify_bet

is_fair = verify_bet(
    server_secret="...",
    client_secret="...",
    nonce=1,
    server_seed_hash="...",
    expected_roll=0.7234,
)

Error Handling

from rollhub_dice import DiceAgent, AuthenticationError, InsufficientBalanceError

try:
    result = agent.bet(target=0.5, amount=100)
except AuthenticationError:
    print("Bad API key")
except InsufficientBalanceError:
    print("Need more funds")

All exceptions inherit from RollhubError and include status_code and response attributes.

Docs

Full documentation: rollhub.com/docs

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

rollhub_dice-0.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

rollhub_dice-0.1.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file rollhub_dice-0.1.0.tar.gz.

File metadata

  • Download URL: rollhub_dice-0.1.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for rollhub_dice-0.1.0.tar.gz
Algorithm Hash digest
SHA256 02001b0256ddb4d6b8ede48bebb30e26241581228cbcb5ec6bf14b4188fb9abc
MD5 13f90271b2d8d30735b3d792100ccf5a
BLAKE2b-256 3e32bc5839331e6bed7a0a86bb9a525dba925fa53edb4d1deee8cfa8a9117d29

See more details on using hashes here.

File details

Details for the file rollhub_dice-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rollhub_dice-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for rollhub_dice-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f839224bf5a891deca3830c7ae7ab6c2ad7ae6494c87a58336c069bbcd2a8a1d
MD5 7c981bcc3959c4fa80e775912bd755fb
BLAKE2b-256 a0c90167b9d3c1eb8566acd8890d10eefd5aa738fe99ffaf752290a6d71732fe

See more details on using hashes here.

Supported by

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