Skip to content

Add more providers #102

Open
Open
@alessandrokonrad

Description

@alessandrokonrad

Lucid has the following Provider interface:

lucid/src/types/types.ts

Lines 25 to 36 in 04bf616

export type Slot = number;
export interface Provider {
getProtocolParameters(): Promise<ProtocolParameters>;
getUtxos(address: Address): Promise<UTxO[]>;
getUtxosWithUnit(address: Address, unit: Unit): Promise<UTxO[]>;
getUtxosByOutRef(outRefs: Array<OutRef>): Promise<UTxO[]>;
getDelegation(rewardAddress: RewardAddress): Promise<Delegation>;
getDatum(datumHash: DatumHash): Promise<Datum>;
awaitTx(txHash: TxHash): Promise<boolean>;
submitTx(tx: Transaction): Promise<TxHash>;
}

Ideally all providers implement the entire interface. Most importantly are the functions getProtocolParameters, getUtxos, getDatum and submitTx. With this minimal implementation you can do most of the things in Lucid already.

Some special functions explained:

  • getUtxosWithUnit: I assume this function only exists in the blockfrost provider natively. Basically what it does it returns UTxOs at a specific address filtered by a specific asset. If you provider doesn't have such an endpoint, just query all UTxOs and filter by the asset in the getUtxosWithUnit function in Lucid itself.
  • awaitTx: In the blockfrost provider you query a tx by tx hash. As long as no result is found you "wait". As soon as there is a result the function is done. Maybe it can be done differently when having access to the mempool API.

Querying UTxOs in general should not ony fetch the UTxOs at a particular address, but all the ones from the payment credential.

To add a new provider go to ./src/provider and create a new file <provider_name>.ts.
You can take a look at the blockfrost.ts file, where the Blockfrost provider is implemented.

All types are described here: https://github.com/spacebudz/lucid/blob/main/src/types/types.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions