Options
All
  • Public
  • Public/Protected
  • All
Menu

Class OpenSeaAPI

Example setup:

import * as Web3 from 'web3' import { OpenSeaPort, Network } from 'opensea-js' const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io') const client = new OpenSeaPort(provider, { networkName: Network.Main })

Hierarchy

  • OpenSeaAPI

Index

Constructors

constructor

  • new OpenSeaAPI(config: OpenSeaAPIConfig, logger?: (arg: string) => void): OpenSeaAPI
  • Create an instance of the OpenSea API

    Parameters

    • config: OpenSeaAPIConfig

      OpenSeaAPIConfig for setting up the API, including an optional API key, network name, and base URL

    • Optional logger: (arg: string) => void

      Optional function for logging debug strings before and after requests are made

        • (arg: string): void
        • Parameters

          • arg: string

          Returns void

    Returns OpenSeaAPI

Properties

Readonly apiBaseUrl

apiBaseUrl: string

Base url for the API

Private apiKey

apiKey: undefined | string

logger

logger: (arg: string) => void

Type declaration

    • (arg: string): void
    • Logger function to use when debugging

      Parameters

      • arg: string

      Returns void

Private networkName

networkName: Network

pageSize

pageSize: number = 20

Page size to use for fetching orders

Private retryDelay

retryDelay: number = 3000

Methods

Private _fetch

  • _fetch(apiPath: string, opts?: RequestInit): Promise<Response>
  • Get from an API Endpoint, sending auth token in headers

    Parameters

    • apiPath: string

      Path to URL endpoint under API

    • opts: RequestInit = {}

      RequestInit opts, similar to Fetch API

    Returns Promise<Response>

Private _handleApiResponse

  • _handleApiResponse(response: Response): Promise<Response>
  • Parameters

    • response: Response

    Returns Promise<Response>

get

  • get<T>(apiPath: string, query?: object): Promise<T>
  • Get JSON data from API, sending auth token in headers

    Type parameters

    • T

    Parameters

    • apiPath: string

      Path to URL endpoint under API

    • query: object = {}

      Data to send. Will be stringified using QueryString

    Returns Promise<T>

getAsset

  • getAsset(__namedParameters: { tokenAddress: string; tokenId: null | string | number }, retries?: number): Promise<OpenSeaAsset>
  • Fetch an asset from the API, throwing if none is found

    Parameters

    • __namedParameters: { tokenAddress: string; tokenId: null | string | number }
      • tokenAddress: string
      • tokenId: null | string | number
    • retries: number = 1

      Number of times to retry if the service is unavailable for any reason

    Returns Promise<OpenSeaAsset>

getAssets

  • getAssets(query?: OpenSeaAssetQuery): Promise<{ assets: OpenSeaAsset[]; estimatedCount: number; next: undefined | string; previous: undefined | string }>
  • Fetch list of assets from the API, returning the page of assets and the count of total assets

    Parameters

    • query: OpenSeaAssetQuery = {}

      Query to use for getting orders. A subset of parameters on the OpenSeaAssetJSON type is supported

    Returns Promise<{ assets: OpenSeaAsset[]; estimatedCount: number; next: undefined | string; previous: undefined | string }>

getBundle

  • getBundle(slug: { slug: string }): Promise<null | OpenSeaAssetBundle>
  • Fetch a bundle from the API, return null if it isn't found

    Parameters

    • slug: { slug: string }

      The bundle's identifier

      • slug: string

    Returns Promise<null | OpenSeaAssetBundle>

getBundles

  • getBundles(query?: OpenSeaAssetBundleQuery, page?: number): Promise<{ bundles: OpenSeaAssetBundle[]; estimatedCount: number }>
  • Fetch list of bundles from the API, returning the page of bundles and the count of total bundles

    Parameters

    • query: OpenSeaAssetBundleQuery = {}

      Query to use for getting orders. A subset of parameters on the OpenSeaAssetBundleJSON type is supported

    • page: number = 1

      Page number, defaults to 1. Can be overridden by limit and offset attributes from OpenSeaAssetBundleQuery

    Returns Promise<{ bundles: OpenSeaAssetBundle[]; estimatedCount: number }>

getOrder

  • getOrder(__namedParameters: Omit<OrdersQueryOptions, "limit">): Promise<OrderV2>
  • Gets an order from API based on query options. Throws when no order is found.

    Parameters

    • __namedParameters: Omit<OrdersQueryOptions, "limit">

    Returns Promise<OrderV2>

getOrderCreateWyvernExchangeAddress

  • getOrderCreateWyvernExchangeAddress(): Promise<null | string>
  • Get which version of Wyvern exchange to use to create orders Simply return null in case API doesn't give us a good response

    Returns Promise<null | string>

getOrders

  • getOrders(__namedParameters: Omit<OrdersQueryOptions, "limit">): Promise<QueryCursors & { orders: OrderV2[] }>
  • Gets a list of orders from API based on query options and returns orders with next and previous cursors.

    Parameters

    • __namedParameters: Omit<OrdersQueryOptions, "limit">

    Returns Promise<QueryCursors & { orders: OrderV2[] }>

getPaymentTokens

  • getPaymentTokens(query?: OpenSeaFungibleTokenQuery, page?: number, retries?: number): Promise<{ tokens: OpenSeaFungibleToken[] }>
  • Fetch list of fungible tokens from the API matching parameters

    Parameters

    • query: OpenSeaFungibleTokenQuery = {}

      Query to use for getting orders. A subset of parameters on the OpenSeaAssetJSON type is supported

    • page: number = 1

      Page number, defaults to 1. Can be overridden by limit and offset attributes from OpenSeaFungibleTokenQuery

    • retries: number = 1

      Number of times to retry if the service is unavailable for any reason

    Returns Promise<{ tokens: OpenSeaFungibleToken[] }>

post

  • post<T>(apiPath: string, body?: object, opts?: RequestInit): Promise<T>
  • POST JSON data to API, sending auth token in headers

    Type parameters

    • T

    Parameters

    • apiPath: string

      Path to URL endpoint under API

    • Optional body: object

      Data to send. Will be JSON.stringified

    • opts: RequestInit = {}

      RequestInit opts, similar to Fetch API. If it contains a body, it won't be stringified.

    Returns Promise<T>

postAssetWhitelist

  • postAssetWhitelist(tokenAddress: string, tokenId: string | number, email: string): Promise<boolean>
  • Create a whitelist entry for an asset to prevent others from buying. Buyers will have to have verified at least one of the emails on an asset in order to buy. This will throw a 403 if the given API key isn't allowed to create whitelist entries for this contract or asset.

    Parameters

    • tokenAddress: string

      Address of the asset's contract

    • tokenId: string | number

      The asset's token ID

    • email: string

      The email allowed to buy.

    Returns Promise<boolean>

postOrder

  • postOrder(order: OrderWithCounter, apiOptions: OrderAPIOptions, __namedParameters?: { retries?: number }): Promise<OrderV2>
  • Send an order to be posted. Throws when the order is invalid.

    Parameters

    • order: OrderWithCounter
    • apiOptions: OrderAPIOptions
    • __namedParameters: { retries?: number } = {}
      • Optional retries?: number

    Returns Promise<OrderV2>

put

  • put(apiPath: string, body: object, opts?: RequestInit): Promise<unknown>
  • PUT JSON data to API, sending auth token in headers

    Parameters

    • apiPath: string

      Path to URL endpoint under API

    • body: object

      Data to send

    • opts: RequestInit = {}

      RequestInit opts, similar to Fetch API. If it contains a body, it won't be stringified.

    Returns Promise<unknown>

Generated using TypeDoc