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
Release history Release notifications | RSS feed
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.2.tar.gz
(35.6 kB
view details)
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
pccontext-0.5.2-py3-none-any.whl
(58.6 kB
view details)
File details
Details for the file pccontext-0.5.2.tar.gz.
File metadata
- Download URL: pccontext-0.5.2.tar.gz
- Upload date:
- Size: 35.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.10.10 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
016b3416202c15963ee2f69858c2343793dbc7f966d4f6c2523cc54bbd914e18
|
|
| MD5 |
55cc5d959545ffcff8a2885dbf81abef
|
|
| BLAKE2b-256 |
0bc8485e3dd20e0bd909572f27a90fced7325cfcd7175b7b49ab2556683d24af
|
File details
Details for the file pccontext-0.5.2-py3-none-any.whl.
File metadata
- Download URL: pccontext-0.5.2-py3-none-any.whl
- Upload date:
- Size: 58.6 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff6e7cc87045e47bc33f667b14cdf1881f611cc786254a54e31c52939973fac2
|
|
| MD5 |
03d82d4b1c7cbcff0ad45bdddfedbf3d
|
|
| BLAKE2b-256 |
28e862e6e6e941996410f441a4b082c8604f56807c2312bc61b80c6c007d50e7
|