Skip to main content

Python SDK for interacting with the AIBlock blockchain

Project description

AIBlock Python SDK

Python SDK for interacting with the AIBlock blockchain. This SDK provides a simple interface for wallet operations and blockchain queries.

Installation

pip install aiblock

Quick Start

Basic Blockchain Queries

from aiblock.blockchain import BlockchainClient

# Initialize blockchain client
client = BlockchainClient(
    storage_host='https://storage.aiblock.dev',
    mempool_host='https://mempool.aiblock.dev'
)

# Query blockchain
latest_block = client.get_latest_block()
if latest_block.is_ok:
    print(f"Latest block: {latest_block.get_ok()['content']['block_num']}")

# Get specific block by number
block = client.get_block_by_num(1)
if block.is_ok:
    print(f"Block 1: {block.get_ok()['content']}")

# Get blockchain entry by hash
entry = client.get_blockchain_entry('some_hash')

# Get transaction by hash
transaction = client.get_transaction_by_hash('tx_hash')

# Get multiple transactions
transactions = client.fetch_transactions(['hash1', 'hash2'])

# Get supply information (requires mempool host)
total_supply = client.get_total_supply()
issued_supply = client.get_issued_supply()

Wallet Operations

from aiblock.wallet import Wallet

# Create wallet
wallet = Wallet()

# Generate seed phrase
seed_phrase = wallet.generate_seed_phrase()
print(f"Seed phrase: {seed_phrase}")

# Initialize wallet from seed
config = {
    'passphrase': 'your-secure-passphrase',
    'mempoolHost': 'https://mempool.aiblock.dev',
    'storageHost': 'https://storage.aiblock.dev',
    'valenceHost': 'https://valence.aiblock.dev'
}

result = wallet.from_seed(seed_phrase, config)
if result.is_ok:
    print(f"Wallet address: {wallet.get_address()}")

Features

Blockchain Client

  • get_latest_block() - Get the latest block information
  • get_block_by_num(block_num) - Get a specific block by number
  • get_blockchain_entry(hash) - Get blockchain entry by hash
  • get_transaction_by_hash(tx_hash) - Get transaction details
  • fetch_transactions(tx_hashes) - Get multiple transactions
  • get_total_supply() - Get total token supply
  • get_issued_supply() - Get issued token supply

Wallet Operations

  • Generate and manage seed phrases
  • Create and manage keypairs
  • Create and sign transactions
  • Create item assets
  • Check balances
  • 2WayPayment protocol support

Configuration

The SDK uses environment variables for configuration. Create a .env file:

AIBLOCK_PASSPHRASE="your-secure-passphrase"
AIBLOCK_STORAGE_HOST="https://storage.aiblock.dev"
AIBLOCK_MEMPOOL_HOST="https://mempool.aiblock.dev"
AIBLOCK_VALENCE_HOST="https://valence.aiblock.dev"

Error Handling

All methods return IResult objects with proper error handling:

result = client.get_latest_block()
if result.is_ok:
    data = result.get_ok()
    print(f"Success: {data}")
else:
    print(f"Error: {result.error_message}")

Development

  1. Clone the repository
  2. Install dependencies: pip install -r requirements.txt
  3. Install test dependencies: pip install -r requirements-test.txt
  4. Run tests: pytest

All 68 tests pass, ensuring reliability and compatibility.

Documentation

Contributing

We welcome contributions! Please feel free to submit a Pull Request.

License

MIT License

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

aiblock-0.2.8.tar.gz (41.6 kB view details)

Uploaded Source

Built Distribution

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

aiblock-0.2.8-py3-none-any.whl (33.8 kB view details)

Uploaded Python 3

File details

Details for the file aiblock-0.2.8.tar.gz.

File metadata

  • Download URL: aiblock-0.2.8.tar.gz
  • Upload date:
  • Size: 41.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiblock-0.2.8.tar.gz
Algorithm Hash digest
SHA256 1e3b2f024b24b768499487e9c179ac3e87b843d843a3cddec833cf864ee9de23
MD5 6eac521f7f3a9aa239b4f741f21dcf60
BLAKE2b-256 caa536ba465f6334a289c814184e9bc8a6c9b8caf3863c3df8f7d146e5917296

See more details on using hashes here.

File details

Details for the file aiblock-0.2.8-py3-none-any.whl.

File metadata

  • Download URL: aiblock-0.2.8-py3-none-any.whl
  • Upload date:
  • Size: 33.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiblock-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 9ba60814579231f0be31c54f1829d32494ed5411f0f6efcaef4b05ef23d665dc
MD5 df6b02f32fc6722a6bb98dd3da6da999
BLAKE2b-256 44ada0cc3520eceabb44382336feb78fdb61492f882710a6a20a71b75b776e23

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