Backend

Defines interfaces for client codes to interact (read/write) with the blockchain.

class pycardano.backend.base.GenesisParameters(active_slots_coefficient: Fraction, update_quorum: int, max_lovelace_supply: int, network_magic: int, epoch_length: int, system_start: int, slots_per_kes_period: int, slot_length: int, max_kes_evolutions: int, security_param: int)

Bases: object

Cardano genesis parameters

active_slots_coefficient: Fraction
update_quorum: int
max_lovelace_supply: int
network_magic: int
epoch_length: int
system_start: int
slots_per_kes_period: int
slot_length: int
max_kes_evolutions: int
security_param: int
class pycardano.backend.base.ProtocolParameters(min_fee_constant: int, min_fee_coefficient: int, max_block_size: int, max_tx_size: int, max_block_header_size: int, key_deposit: int, pool_deposit: int, pool_influence: Fraction, monetary_expansion: Fraction, treasury_expansion: Fraction, decentralization_param: Fraction, extra_entropy: str, protocol_major_version: int, protocol_minor_version: int, min_utxo: int, min_pool_cost: int, price_mem: Fraction, price_step: Fraction, max_tx_ex_mem: int, max_tx_ex_steps: int, max_block_ex_mem: int, max_block_ex_steps: int, max_val_size: int, collateral_percent: int, max_collateral_inputs: int, coins_per_utxo_word: int, coins_per_utxo_byte: int, cost_models: Dict[str, Dict[str, int]], maximum_reference_scripts_size: Optional[Dict[str, int]] = None, min_fee_reference_scripts: Optional[Dict[str, float]] = None)

Bases: object

Cardano protocol parameters

min_fee_constant: int
min_fee_coefficient: int
max_block_size: int
max_tx_size: int
max_block_header_size: int
key_deposit: int
pool_deposit: int
pool_influence: Fraction
monetary_expansion: Fraction
treasury_expansion: Fraction
decentralization_param: Fraction
extra_entropy: str
protocol_major_version: int
protocol_minor_version: int
min_utxo: int
min_pool_cost: int
price_mem: Fraction
price_step: Fraction
max_tx_ex_mem: int
max_tx_ex_steps: int
max_block_ex_mem: int
max_block_ex_steps: int
max_val_size: int
collateral_percent: int
max_collateral_inputs: int
coins_per_utxo_word: int
coins_per_utxo_byte: int
cost_models: Dict[str, Dict[str, int]]

A dict contains cost models for Plutus. The key will be “PlutusV1”, “PlutusV2”, etc. The value will be a dict of cost model parameters.

maximum_reference_scripts_size: Optional[Dict[str, int]] = None
min_fee_reference_scripts: Optional[Dict[str, float]] = None
class pycardano.backend.base.ChainContext

Bases: object

Interfaces through which the library interacts with Cardano blockchain.

property protocol_param: ProtocolParameters

Get current protocol parameters

property genesis_param: GenesisParameters

Get chain genesis parameters

property network: Network

Cet current network

property epoch: int

Current epoch number

property last_block_slot: int

Slot number of last block

utxos(address: Union[str, Address]) List[UTxO]

Get all UTxOs associated with an address.

Parameters:

address (Union[str, Address]) – An address, potentially bech32 encoded

Returns:

A list of UTxOs.

Return type:

List[UTxO]

submit_tx(*args, **kwargs)
submit_tx_cbor(cbor: Union[bytes, str])

Submit a transaction to the blockchain.

Parameters:

cbor (Union[bytes, str]) – The serialized transaction to be submitted.

Raises:
evaluate_tx(tx: Transaction) Dict[str, ExecutionUnits]

Evaluate execution units of a transaction.

Parameters:

transaction (Transaction) – The transaction to be evaluated.

Returns:

A list of execution units calculated for each of the transaction’s redeemers

Return type:

List[ExecutionUnits]

evaluate_tx_cbor(cbor: Union[bytes, str]) Dict[str, ExecutionUnits]

Evaluate execution units of a transaction.

Parameters:

cbor (Union[bytes, str]) – The serialized transaction to be evaluated.

Returns:

A list of execution units calculated for each of the transaction’s redeemers

Return type:

List[ExecutionUnits]

class pycardano.backend.blockfrost.BlockFrostChainContext(project_id: str, network: Optional[Network] = None, base_url: Optional[str] = None)

Bases: ChainContext

A BlockFrost API wrapper for the client code to interact with.

Parameters:
  • project_id (str) – A BlockFrost project ID obtained from https://blockfrost.io.

  • network (Network) – Network to use.

  • base_url (str) – Base URL for the BlockFrost API. Defaults to the preprod url.

api: BlockFrostApi
property network: Network

Cet current network

property epoch: int

Current epoch number

property last_block_slot: int

Slot number of last block

property genesis_param: GenesisParameters

Get chain genesis parameters

property protocol_param: ProtocolParameters

Get current protocol parameters

submit_tx_cbor(cbor: Union[bytes, str]) str

Submit a transaction.

Parameters:

cbor (Union[bytes, str]) – The serialized transaction to be submitted.

Returns:

The transaction hash.

Return type:

str

Raises:

TransactionFailedException – When fails to submit the transaction.

evaluate_tx_cbor(cbor: Union[bytes, str]) Dict[str, ExecutionUnits]

Evaluate execution units of a transaction.

Parameters:

cbor (Union[bytes, str]) – The serialized transaction to be evaluated.

Returns:

A list of execution units calculated for each of the transaction’s redeemers

Return type:

Dict[str, ExecutionUnits]

Raises:

TransactionFailedException – When fails to evaluate the transaction.

class pycardano.backend.ogmios_v6.OgmiosV6ChainContext(host: str = 'localhost', port: int = 1337, secure: bool = False, refetch_chain_tip_interval: Optional[float] = None, utxo_cache_size: int = 10000, datum_cache_size: int = 10000, network: Network = Network.TESTNET)

Bases: ChainContext

Ogmios chain context for use with PyCardano

property protocol_param: ProtocolParameters

Get current protocol parameters

property genesis_param: GenesisParameters

Get chain genesis parameters

property network: Network

Cet current network

property epoch: int

Current epoch number

property last_block_slot: int

Slot number of last block

utxo_by_tx_id(tx_id: str, index: int) Optional[UTxO]
submit_tx_cbor(cbor: Union[bytes, str])

Submit a transaction to the blockchain.

Parameters:

cbor (Union[bytes, str]) – The serialized transaction to be submitted.

Raises:
evaluate_tx_cbor(cbor: Union[bytes, str]) Dict[str, ExecutionUnits]

Evaluate execution units of a transaction.

Parameters:

cbor (Union[bytes, str]) – The serialized transaction to be evaluated.

Returns:

A list of execution units calculated for each of the transaction’s redeemers

Return type:

List[ExecutionUnits]

class pycardano.backend.ogmios_v6.OgmiosChainContext(host: str = 'localhost', port: int = 1337, secure: bool = False, refetch_chain_tip_interval: Optional[float] = None, utxo_cache_size: int = 10000, datum_cache_size: int = 10000, network: Network = Network.TESTNET)

Bases: OgmiosV6ChainContext

An alias of OgmiosV6ChainContext for backwards compatibility.

pycardano.backend.ogmios_v6.KupoOgmiosV6ChainContext(host: str, port: int, secure: bool, refetch_chain_tip_interval: Optional[float] = None, utxo_cache_size: int = 10000, datum_cache_size: int = 10000, network: Network = Network.TESTNET, kupo_url: Optional[str] = None) KupoChainContextExtension
class pycardano.backend.ogmios_v5.OgmiosV5ChainContext(ws_url: str, network: Network, compact_result=True, refetch_chain_tip_interval: Optional[float] = None, utxo_cache_size: int = 10000, datum_cache_size: int = 10000)

Bases: ChainContext

Legacy Ogmios Chain Context for Ogmios v5

property protocol_param: ProtocolParameters

Get current protocol parameters

property genesis_param: GenesisParameters

Get chain genesis parameters

property network: Network

Get current network

property epoch: int

Current epoch number

property last_block_slot: int

Slot number of last block

utxo_by_tx_id(tx_id: str, index: int) Optional[UTxO]

Get a UTxO associated with a tx_id and index.

Parameters:
  • tx_id (str) – The transaction id.

  • index (int) – The index for the UTxO at the specified transaction.

Returns:

Return a UTxO if exists at the tx_id and index.

Return type:

Optional[UTxO]

submit_tx_cbor(cbor: Union[bytes, str])

Submit a transaction to the blockchain.

Parameters:

cbor (Union[bytes, str]) – The transaction to be submitted.

Raises:
evaluate_tx_cbor(cbor: Union[bytes, str]) Dict[str, ExecutionUnits]

Evaluate execution units of a transaction.

Parameters:

cbor (Union[bytes, str]) – The serialized transaction to be evaluated.

Returns:

A list of execution units calculated for each of the transaction’s redeemers

Return type:

Dict[str, ExecutionUnits]

Raises:

TransactionFailedException – When fails to evaluate the transaction.

pycardano.backend.ogmios_v5.KupoOgmiosV5ChainContext(ws_url: str, network: Network, compact_result=True, refetch_chain_tip_interval: Optional[float] = None, utxo_cache_size: int = 10000, datum_cache_size: int = 10000, kupo_url: Optional[str] = None) KupoChainContextExtension