Backend

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

class pycardano.backend.base.GenesisParameters(active_slots_coefficient: fractions.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: fractions.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: fractions.Fraction, monetary_expansion: fractions.Fraction, treasury_expansion: fractions.Fraction, decentralization_param: fractions.Fraction, extra_entropy: str, protocol_major_version: int, protocol_minor_version: int, min_utxo: int, min_pool_cost: int, price_mem: fractions.Fraction, price_step: fractions.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]])

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: fractions.Fraction
monetary_expansion: fractions.Fraction
treasury_expansion: fractions.Fraction
decentralization_param: fractions.Fraction
extra_entropy: str
protocol_major_version: int
protocol_minor_version: int
min_utxo: int
min_pool_cost: int
price_mem: fractions.Fraction
price_step: fractions.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.

class pycardano.backend.base.ChainContext

Bases: object

Interfaces through which the library interacts with Cardano blockchain.

property protocol_param: pycardano.backend.base.ProtocolParameters

Get current protocol parameters

property genesis_param: pycardano.backend.base.GenesisParameters

Get chain genesis parameters

property network: pycardano.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, pycardano.address.Address]) List[pycardano.transaction.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(tx: Union[pycardano.transaction.Transaction, bytes, str])

Submit a transaction to the blockchain.

Parameters

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

Raises
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: pycardano.transaction.Transaction) Dict[str, pycardano.plutus.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, pycardano.plutus.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[pycardano.network.Network] = None, base_url: Optional[str] = None)

Bases: pycardano.backend.base.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: blockfrost.api.BlockFrostApi
property network: pycardano.network.Network

Cet current network

property epoch: int

Current epoch number

property last_block_slot: int

Slot number of last block

property genesis_param: pycardano.backend.base.GenesisParameters

Get chain genesis parameters

property protocol_param: pycardano.backend.base.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, pycardano.plutus.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.