Skip to main content

Marketplace

The Marketplace class represents the main interaction point with the Marketplace smart contract. It provides methods to create, update, and manage offers and deals, as well as to interact with provider information and marketplace initialization.

Class: Marketplace

The Marketplace class allows developers to interact with the Marketplace contract on the blockchain, offering methods to perform various operations such as creating offers, managing deals, and retrieving provider metadata.

Constructor

The constructor initializes an instance of the Marketplace class.

Parameters

  • sdkInstance: Sdk An instance of the SDK containing configuration details for interacting with the blockchain.

Throws

  • An error if the Marketplace address is not found for the current network ID.

Usage

const marketplace = new Marketplace(sdkInstance);

Attributes

config: SdkConfig

Contains the configuration for the SDK, including walletClient and publicClient.

Methods

view

Calls a read-only function on the Marketplace contract.

  • Parameters:

  • functionName: string The name of the contract function to call.

  • args: any[] The arguments to pass to the contract function.

  • Returns: Promise<any> The result of the contract function.

  • Throws: Will throw an error if the contract read operation fails.

execute

Executes a state-changing function on the Marketplace contract.

  • Parameters:

  • functionName: string The name of the contract function to execute.

  • args: any[] The arguments to pass to the contract function.

  • Returns: Promise<any> The transaction receipt.

  • Throws: Will throw an error if the contract execution fails.

createOffer

Creates a new offer on the marketplace.

  • Parameters:

  • params: CreateOfferParams The parameters required to create an offer.

  • Returns: Promise<any> The transaction receipt.

updateOffer

Updates an existing offer on the marketplace.

  • Parameters:

  • params: UpdateOfferParams The parameters required to update an offer.

  • Returns: Promise<any> The transaction receipt.

deleteOffer

Deletes an offer from the marketplace.

  • Parameters:

  • params: DeleteOfferParams The parameters required to delete an offer.

  • Returns: Promise<any> The transaction receipt.

createDeal

Creates a new deal on the marketplace.

  • Parameters:

  • params: CreateDealParams The parameters required to create a deal.

  • Returns: Promise<any> The transaction receipt.

createDeals

Creates multiple deals on the marketplace.

  • Parameters:

  • params: CreateDealsParams The parameters required to create multiple deals.

  • Returns: Promise<any> The transaction receipt.

acceptDeal

Accepts a deal on the marketplace.

  • Parameters:

  • params: DealOperationParams The parameters required to accept a deal.

  • Returns: Promise<any> The transaction receipt.

rejectDeal

Rejects a deal on the marketplace.

  • Parameters:

  • params: DealOperationParams The parameters required to reject a deal.

  • Returns: Promise<any> The transaction receipt.

cancelDeal

Cancels a deal on the marketplace.

  • Parameters:

  • params: DealOperationParams The parameters required to cancel a deal.

  • Returns: Promise<any> The transaction receipt.

cancelAllDeals

Cancels all deals for a given resource on the marketplace.

  • Parameters:

  • params: CancelDealsParams The parameters required to cancel all deals.

  • Returns: Promise<any> The transaction receipt.

getDealById

Retrieves a deal by its ID from the marketplace.

  • Parameters:

  • params: DealOperationParams The parameters required to get a deal.

  • Returns: Promise<Deal | null> The deal information or null if not found.

getOfferById

Retrieves an offer by its ID from the marketplace.

  • Parameters:

  • params: OfferOperationParams The parameters required to get an offer.

  • Returns: Promise<Offer | null> The offer information.

getProvider

Retrieves provider metadata from the marketplace.

  • Parameters:

  • params: ProviderOperationParams The parameters required to get the provider.

  • Returns: Promise<ProviderMetadata> The provider metadata.

getDealDetails

Static method to calculate deal details based on the provided deal data.

  • Parameters:

  • deal: any The deal object containing necessary deal data.

  • Returns: An object containing the calculated details of the deal, such as elapsed time, total time, remaining time, remaining balance, pending payment, calculated end, and a formatted end date.