Skip to main content

Chain Contexts for PyCardano library

Project description

PyCardano Chain Contexts

This library contains the various Chain Contexts to use with the PyCardano library as well as a few helper functions for working with and building certain types of transactions.

Chain Context Usage

Blockfrost

from pccontext import BlockFrostChainContext, Network

chain_context = BlockFrostChainContext(
    project_id="your_project_id",
    network=Network.MAINNET,
)

Cardano-CLI

from pccontext import CardanoCliChainContext, Network
from pathlib import Path

chain_context = CardanoCliChainContext(
            binary=Path("cardano-cli"),
            socket=Path("node.socket"),
            config_file=Path("config.json"),
            network=Network.MAINNET,
)

Koios

from pccontext import KoiosChainContext

chain_context = KoiosChainContext(api_key="api_key")

Ogmios

from pccontext import OgmiosChainContext

chain_context = OgmiosChainContext(host="localhost", port=1337)

Kupo

from pccontext import OgmiosChainContext, KupoChainContextExtension

ogmios_chain_context = OgmiosChainContext(host="localhost", port=1337)
chain_context = KupoChainContextExtension(wrapped_backend=ogmios_chain_context)

Offline Transfer File

from pathlib import Path
from pccontext import OfflineTransferFileContext

chain_context = OfflineTransferFileContext(offline_transfer_file=Path("offline-transfer.json"))

Yaci Devkit

from pccontext import YaciDevkitChainContext

chain_context = YaciDevkitChainContext(api_url="http://localhost:8080")

Transactions Usage

from pycardano import (
    Address,
    StakeSigningKey,
    StakeVerificationKey,
    PaymentSigningKey,
    PaymentVerificationKey,
)

from pccontext.transactions import stake_address_registration
import os

from pccontext import BlockFrostChainContext, Network


network = Network.PREPROD
blockfrost_api_key = os.getenv("BLOCKFROST_API_KEY_PREPROD")
chain_context = BlockFrostChainContext(
    project_id=blockfrost_api_key, network=network
)

payment_signing_key = PaymentSigningKey.generate()
payment_verification_key = PaymentVerificationKey.from_signing_key(
    payment_signing_key
)

stake_signing_key = StakeSigningKey.generate()
stake_verification_key = StakeVerificationKey.from_signing_key(stake_signing_key)

address = Address(
    payment_part=payment_verification_key.hash(),
    staking_part=stake_verification_key.hash(),
    network=network.get_network(),
)

# Example Stake Address Registration Transaction
signed_stake_address_registration_tx = stake_address_registration(
    context=chain_context,
    stake_vkey=stake_verification_key,
    send_from_addr=address,
    signing_keys=[payment_signing_key, stake_signing_key],
)

print(f"Signed Transaction: {signed_stake_address_registration_tx}")

chain_context.submit_tx(signed_stake_address_registration_tx)

print(f"Transaction ID: {signed_stake_address_registration_tx.id}")

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

pccontext-0.5.0.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

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

pccontext-0.5.0-py3-none-any.whl (58.5 kB view details)

Uploaded Python 3

File details

Details for the file pccontext-0.5.0.tar.gz.

File metadata

  • Download URL: pccontext-0.5.0.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.10.10 Darwin/24.5.0

File hashes

Hashes for pccontext-0.5.0.tar.gz
Algorithm Hash digest
SHA256 7ab8bf2eff211718714f7f4cbd64ff9a92a903b5b2fb598d04a95b41d2afac85
MD5 e9189bf46d2842716703a90b2ffc1a73
BLAKE2b-256 819c8d03e1cce78ca2ba9c43257d814564a98a05910761c92984e1ed0743f759

See more details on using hashes here.

File details

Details for the file pccontext-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pccontext-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 58.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.10.10 Darwin/24.5.0

File hashes

Hashes for pccontext-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14da4c52fb4e83bca6653d403c640592b58f27052816f862e108add32d7ee2b7
MD5 a24ff1e0fb5101ea6eda5f11a5d89632
BLAKE2b-256 c32bfe7d3ffc076486b59b19567293b395532f2327531fbe97ef49ea38b32862

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