Abstract class for the Provider. This class provides an interface for interacting with the blockchain.

Hierarchy (view full)

Constructors

  • Parameters

    • __namedParameters: {
          network: NetworkName;
          projectId: string;
          withScriptRefCaching?: boolean;
      }
      • network: NetworkName
      • projectId: string
      • OptionalwithScriptRefCaching?: boolean

    Returns Blockfrost

Properties

network: NetworkId
networkName: NetworkName
url: string
withScriptRefCaching: boolean

Methods

  • This method awaits confirmation of the transaction given as argument. The response is parsed into a boolean, which is then returned. If tx is not confirmed at first and no value for timeout is provided, then false is returned. If tx is not confirmed at first and a value for timeout (in ms) is given, then subsequent checks will be performed at a 20 second interval until timeout is reached.

    Parameters

    • txId: TransactionId

      The hash of a transaction

    • Optionaltimeout: number

      An optional timeout for waiting for confirmation. This value should be greater than average block time of 20000 ms

    Returns Promise<boolean>

    A Promise that resolves to a boolean

  • This method evaluates how much execution units a transaction requires. Optionally, additional outputs can be provided. These are added to the evaluation without checking for their presence on-chain. This is useful when performing transaction chaining, where some outputs used as inputs to a transaction will have not yet been submitted to the network.

    Parameters

    • tx: Transaction

      The Transaction

    • OptionaladditionalUtxos: TransactionUnspentOutput[]

      Optional utxos to be added to the evaluation.

    Returns Promise<Redeemers>

    A Promise that resolves to a Redeemers type

  • This method fetches the protocol parameters from the Blockfrost API. It constructs the query URL, sends a GET request with the appropriate headers, and processes the response. The response is parsed into a ProtocolParameters object, which is then returned. If the response is not in the expected format, an error is thrown.

    Returns Promise<Core.ProtocolParameters>

    A Promise that resolves to a ProtocolParameters object.

  • Get the slot config, which describes how to translate between slots and unix timestamps TODO: this is brittle; in theory this should work with the era histories; also, networkName is awkward

    Returns Core.SlotConfig

  • This method fetches the UTxO that holds a particular NFT given as argument. The response is parsed into a TransactionUnspentOutput type, which is then returned. If the response is not in the expected format, an error is thrown.

    Parameters

    • nft: AssetId

      The AssetId for the NFT

    Returns Promise<TransactionUnspentOutput>

    A Promise that resolves to TransactionUnspentOutput.

  • This method fetches the UTxOs under a given address. The response is parsed into a TransactionUnspentOutput[] type, which is then returned. If the response is not in the expected format, an error is thrown.

    Parameters

    • address: Address | Credential

      The Address or Payment Credential

    • Optionalfilter: ((utxo: BlockfrostUTxO) => boolean)
        • (utxo): boolean
        • Parameters

          • utxo: BlockfrostUTxO

          Returns boolean

    Returns Promise<TransactionUnspentOutput[]>

    A Promise that resolves to TransactionUnspentOutput[].

  • This method fetches the UTxOs under a given address that hold a particular asset. The response is parsed into a TransactionUnspentOutput[] type, which is then returned. If the response is not in the expected format, an error is thrown.

    Parameters

    • address: Address | Credential

      Address or Payment Credential.

    • unit: AssetId

      The AssetId

    Returns Promise<TransactionUnspentOutput[]>

    A Promise that resolves to TransactionUnspentOutput[].

  • Returns {
        project_id: string;
    }

    • project_id: string
  • This method submits a transaction to the chain.

    Parameters

    • tx: Transaction

      The Transaction

    Returns Promise<TransactionId>

    A Promise that resolves to a TransactionId type

  • This method returns the datum for the datum hash given as argument. The response is parsed into a PlutusData type, which is then returned. If the response is not in the expected format, an error is thrown.

    Parameters

    • datumHash: Hash32ByteBase16

      The hash of a datum

    Returns Promise<PlutusData>

    A Promise that resolves to PlutusData

  • Resolves the script deployment by finding a UTxO containing the script reference.

    Parameters

    • script: Hash28ByteBase16 | Script

      The script or its hash to resolve.

    • Optionaladdress: Address

      The address to search for the script deployment. Defaults to a burn address.

    Returns Promise<TransactionUnspentOutput>

    • The UTxO containing the script reference, or undefined if not found.

    This is a default implementation that works but may not be optimal. Subclasses of Provider should implement their own version for better performance.

    The method searches for a UTxO at the given address (or a burn address by default) that contains a script reference matching the provided script or script hash.

    const scriptUtxo = await provider.resolveScriptRef(myScript);
    if (scriptUtxo) {
    console.log("Script found in UTxO:", scriptUtxo.input().toCore());
    } else {
    console.log("Script not found");
    }
  • This method resolves transaction outputs from a list of transaction inputs given as argument. The response is parsed into a TransactionUnspentOutput[] type, which is then returned. If the response is not in the expected format, an error is thrown.

    Parameters

    • txIns: TransactionInput[]

      A list of TransactionInput

    Returns Promise<TransactionUnspentOutput[]>

    A Promise that resolves to TransactionUnspentOutput[].

  • Translate a slot to a unix millisecond timestamp

    Parameters

    • slot: number | bigint | Slot

      The network slot

    Returns number

    The milliseconds since midnight, Jan 1 1970

  • Translate a unix millisecond timestamp to slot, according to the providers network

    Parameters

    • unix_millis: number | bigint

      Milliseconds since midnight, Jan 1 1970

    Returns Slot

    The slot in the relevant network