BlockfrostProvider
- class cometa.providers.blockfrost_provider.BlockfrostProvider(network, project_id, base_url=None)[source]
Bases:
objectProvider implementation for the Blockfrost API.
BlockfrostProvider enables interaction with the Cardano blockchain through the Blockfrost API service. It implements all provider methods for: - Fetching protocol parameters - Querying UTXOs - Resolving datums - Submitting and confirming transactions - Evaluating Plutus scripts
- Parameters:
network (NetworkMagic)
project_id (str)
base_url (Optional[str])
- __init__(network, project_id, base_url=None)[source]
Initialize the Blockfrost provider.
- Parameters:
network (NetworkMagic) – The Cardano network to connect to.
project_id (str) – Your Blockfrost project ID for authentication.
base_url (str | None) – Optional custom base URL (overrides network-based URL).
- get_name()[source]
Get the provider name.
- Returns:
The string “Blockfrost”.
- Return type:
str
Note
This method implements the provider protocol interface.
- get_network_magic()[source]
Get the network magic number.
- Returns:
The network magic value as an integer.
- Return type:
int
- get_parameters()[source]
Retrieve the current protocol parameters from Blockfrost.
- Returns:
The current ProtocolParameters.
- Raises:
CardanoError – If the request fails.
- Return type:
- get_unspent_outputs(address)[source]
Get all unspent transaction outputs for an address.
- Parameters:
address (Union['Address', str]) – The payment address to query.
- Returns:
A list of Utxo objects.
- Return type:
List[‘Utxo’]
- get_rewards_balance(reward_account)[source]
Get the staking rewards balance for a reward account.
- Parameters:
reward_account (Union['RewardAddress', str]) – The reward address to query.
- Returns:
The rewards balance in lovelace.
- Return type:
int
- get_unspent_outputs_with_asset(address, asset_id)[source]
Get UTXOs for an address that contain a specific asset.
- Parameters:
address (Union['Address', str]) – The payment address to query.
asset_id (Union['AssetId', str]) – The asset identifier to filter by.
- Returns:
A list of Utxo objects containing the asset.
- Return type:
List[‘Utxo’]
- get_unspent_output_by_nft(asset_id)[source]
Get the UTXO containing a specific NFT.
- Parameters:
asset_id (Union['AssetId', str]) – The NFT asset identifier.
- Returns:
The Utxo containing the NFT.
- Raises:
CardanoError – If the NFT is not found or held by multiple addresses/UTXOs.
- Return type:
- resolve_unspent_outputs(tx_ins)[source]
Resolve transaction inputs to their corresponding UTXOs.
- Parameters:
tx_ins (Union['TransactionInputSet', List['TransactionInput']]) – The transaction inputs to resolve.
- Returns:
A list of resolved Utxo objects.
- Return type:
List[‘Utxo’]
- resolve_datum(datum_hash)[source]
Resolve a datum by its hash.
- Parameters:
datum_hash (Union['Blake2bHash', str]) – The hash of the datum to resolve.
- Returns:
The CBOR-encoded datum as a hex string.
- Return type:
str
- confirm_transaction(tx_id, timeout_ms=None)[source]
Wait for a transaction to be confirmed on-chain.
- Parameters:
tx_id (str) – The transaction ID (hex string).
timeout_ms (int | None) – Optional timeout in milliseconds.
- Returns:
True if confirmed, False if timeout reached.
- Return type:
bool
- submit_transaction(tx_cbor_hex)[source]
Submit a signed transaction to the blockchain.
- Parameters:
tx_cbor_hex (str) – The CBOR-encoded transaction as a hex string.
- Returns:
The transaction ID (hex string) of the submitted transaction.
- Return type:
str
- evaluate_transaction(tx_cbor_hex, additional_utxos=None)[source]
Evaluate a transaction to get execution units for Plutus scripts.
- Parameters:
tx_cbor_hex (str) – The CBOR-encoded transaction as a hex string.
additional_utxos (Union['UtxoList', List['Utxo'], None]) – Optional additional UTXOs for evaluation.
- Returns:
A list of Redeemer objects with computed execution units.
- Return type:
List[‘Redeemer’]