Class OpenSeaSDK

The OpenSea SDK main class.

Constructors

  • Create a new instance of OpenSeaSDK.

    Parameters

    • signerOrProvider: JsonRpcProvider | Signer

      Signer or provider to use for transactions. For example: new ethers.providers.JsonRpcProvider('https://mainnet.infura.io') or new ethers.Wallet(privKey, provider)

    • apiConfig: OpenSeaAPIConfig = {}

      configuration options, including chain

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

      optional function for logging debug strings. defaults to no logging

        • (arg): void
        • Parameters

          • arg: string

          Returns void

    Returns OpenSeaSDK

Properties

api: OpenSeaAPI

API instance

chain: Chain

The configured chain

logger: ((arg) => void)

Logger function to use when debugging

Type declaration

    • (arg): void
    • Parameters

      • arg: string

      Returns void

provider: JsonRpcProvider

Provider to use for transactions.

seaport_v1_5: Seaport

Seaport v1.5 client

seaport_v1_6: Seaport

Seaport v1.6 client

Methods

  • Add a listener for events emitted by the SDK.

    Parameters

    • event: EventType

      The EventType to listen to.

    • listener: ((data) => void)

      A callback that will accept an object with EventData\

        • (data): void
        • Parameters

          Returns void

    • once: boolean = false

      Whether the listener should only be called once, or continue listening until removed.

    Returns void

  • Instead of signing an off-chain order, this methods allows you to approve an order with on on-chain transaction.

    Parameters

    • order: OrderV2

      Order to approve

    • Optional domain: string

      An optional domain to be hashed and included at the end of fulfillment calldata. This can be used for on-chain order attribution to assist with analytics.

    Returns Promise<string>

    Transaction hash of the approval transaction

    Throws

    Error if the accountAddress is not available through wallet or provider.

    Throws

    Error if the order's protocol address is not supported by OpenSea. See isValidProtocol.

  • Cancel an order on-chain, preventing it from ever being fulfilled.

    Parameters

    • options: {
          accountAddress: string;
          domain?: string;
          order: OrderV2;
      }
      • accountAddress: string

        The account address that will be cancelling the order.

      • Optional domain?: string

        An optional domain to be hashed and included at the end of fulfillment calldata. This can be used for on-chain order attribution to assist with analytics.

      • order: OrderV2

        The order to cancel

    Returns Promise<void>

    Throws

    Error if the accountAddress is not available through wallet or provider.

    Throws

    Error if the order's protocol address is not supported by OpenSea. See isValidProtocol.

  • Create and submit a collection offer.

    Parameters

    • options: {
          accountAddress: string;
          amount: BigNumberish;
          collectionSlug: string;
          domain?: string;
          excludeOptionalCreatorFees?: boolean;
          expirationTime?: string | number;
          offerProtectionEnabled?: boolean;
          paymentTokenAddress: string;
          quantity: number;
          salt?: BigNumberish;
          traitType?: string;
          traitValue?: string;
      }
      • accountAddress: string

        Address of the wallet making the offer.

      • amount: BigNumberish

        Value of the offer in units, not base units e.g. not wei, of the payment token (or WETH if no payment token address specified).

      • collectionSlug: string

        Identifier for the collection.

      • Optional domain?: string

        An optional domain to be hashed and included in the first four bytes of the random salt. This can be used for on-chain order attribution to assist with analytics.

      • Optional excludeOptionalCreatorFees?: boolean

        If true, optional creator fees will be excluded from the offer. Default: false.

      • Optional expirationTime?: string | number

        Expiration time for the order, in UTC seconds.

      • Optional offerProtectionEnabled?: boolean

        Build the offer on OpenSea's signed zone to provide offer protections from receiving an item which is disabled from trading.

      • paymentTokenAddress: string

        ERC20 address for the payment token in the order. If unspecified, defaults to WETH.

      • quantity: number

        The number of assets to bid for (if fungible or semi-fungible).

      • Optional salt?: BigNumberish

        Arbitrary salt. If not passed in, a random salt will be generated with the first four bytes being the domain hash or empty.

      • Optional traitType?: string

        If defined, the trait name to create the collection offer for.

      • Optional traitValue?: string

        If defined, the trait value to create the collection offer for.

    Returns Promise<null | CollectionOffer>

    The CollectionOffer that was created.

  • Create and submit a listing for an asset.

    Parameters

    • options: {
          accountAddress: string;
          asset: AssetWithTokenId;
          buyerAddress?: string;
          domain?: string;
          endAmount?: BigNumberish;
          englishAuction?: boolean;
          excludeOptionalCreatorFees?: boolean;
          expirationTime?: number;
          listingTime?: number;
          paymentTokenAddress?: string;
          quantity?: BigNumberish;
          salt?: BigNumberish;
          startAmount: BigNumberish;
      }
      • accountAddress: string

        Address of the wallet making the listing

      • asset: AssetWithTokenId

        The asset to trade. tokenAddress and tokenId must be defined.

      • Optional buyerAddress?: string

        Optional address that's allowed to purchase this item. If specified, no other address will be able to take the order, unless its value is the null address.

      • Optional domain?: string

        An optional domain to be hashed and included in the first four bytes of the random salt. This can be used for on-chain order attribution to assist with analytics.

      • Optional endAmount?: BigNumberish

        Value of the listing at the end of the auction. If specified, price will change linearly between startAmount and endAmount as time progresses.

      • Optional englishAuction?: boolean

        If true, the order will be listed as an English auction.

      • Optional excludeOptionalCreatorFees?: boolean

        If true, optional creator fees will be excluded from the listing. Default: false.

      • Optional expirationTime?: number

        Expiration time for the order, in UTC seconds.

      • Optional listingTime?: number

        Optional time when the order will become fulfillable, in UTC seconds. Undefined means it will start now.

      • Optional paymentTokenAddress?: string

        ERC20 address for the payment token in the order. If unspecified, defaults to ETH

      • Optional quantity?: BigNumberish

        The number of assets to list (if fungible or semi-fungible). Defaults to 1.

      • Optional salt?: BigNumberish

        Arbitrary salt. If not passed in, a random salt will be generated with the first four bytes being the domain hash or empty.

      • startAmount: BigNumberish

        Value of the listing at the start of the auction in units, not base units e.g. not wei, of the payment token (or WETH if no payment token address specified)

    Returns Promise<OrderV2>

    The OrderV2 that was created.

    Throws

    Error if the asset does not contain a token id.

    Throws

    Error if the accountAddress is not available through wallet or provider.

    Throws

    Error if the startAmount is not greater than 0.

    Throws

    Error if paymentTokenAddress is not WETH on anything other than Ethereum mainnet.

  • Create and submit an offer on an asset.

    Parameters

    • options: {
          accountAddress: string;
          asset: AssetWithTokenId;
          domain?: string;
          excludeOptionalCreatorFees?: boolean;
          expirationTime?: BigNumberish;
          paymentTokenAddress?: string;
          quantity?: BigNumberish;
          salt?: BigNumberish;
          startAmount: BigNumberish;
      }
      • accountAddress: string

        Address of the wallet making the offer.

      • asset: AssetWithTokenId

        The asset to trade. tokenAddress and tokenId must be defined.

      • Optional domain?: string

        An optional domain to be hashed and included in the first four bytes of the random salt.

      • Optional excludeOptionalCreatorFees?: boolean

        If true, optional creator fees will be excluded from the offer. Default: false.

      • Optional expirationTime?: BigNumberish

        Expiration time for the order, in UTC seconds

      • Optional paymentTokenAddress?: string

        ERC20 address for the payment token in the order. If unspecified, defaults to WETH

      • Optional quantity?: BigNumberish

        The number of assets to bid for (if fungible or semi-fungible). Defaults to 1.

      • Optional salt?: BigNumberish

        Arbitrary salt. If not passed in, a random salt will be generated with the first four bytes being the domain hash or empty.

      • startAmount: BigNumberish

        Value of the offer in units, not base units e.g. not wei, of the payment token (or WETH if no payment token address specified)

    Returns Promise<OrderV2>

    The OrderV2 that was created.

    Throws

    Error if the asset does not contain a token id.

    Throws

    Error if the accountAddress is not available through wallet or provider.

    Throws

    Error if the startAmount is not greater than 0.

    Throws

    Error if paymentTokenAddress is not WETH on anything other than Ethereum mainnet.

  • Fulfill an order for an asset. The order can be either a listing or an offer.

    Parameters

    • options: {
          accountAddress: string;
          domain?: string;
          order: OrderV2 | Order;
          overrides?: Overrides;
          recipientAddress?: string;
      }
      • accountAddress: string

        Address of the wallet taking the offer.

      • Optional domain?: string

        An optional domain to be hashed and included at the end of fulfillment calldata. This can be used for on-chain order attribution to assist with analytics.

      • order: OrderV2 | Order

        The order to fulfill, a.k.a. "take"

      • Optional overrides?: Overrides

        Transaction overrides, ignored if not set.

      • Optional recipientAddress?: string

        The optional address to receive the order's item(s) or currencies. If not specified, defaults to accountAddress.

    Returns Promise<string>

    Transaction hash of the order.

    Throws

    Error if the accountAddress is not available through wallet or provider.

    Throws

    Error if the order's protocol address is not supported by OpenSea. See isValidProtocol.

    Throws

    Error if attempting to fulfill the order with a recipient address which does not match a private listing.

  • Get an account's balance of any Asset. This asset can be an ERC20, ERC1155, or ERC721.

    Parameters

    Returns Promise<bigint>

    The balance of the asset for the account.

    Throws

    Error if the token standard does not support balanceOf.

  • Returns whether an order is fulfillable. An order may not be fulfillable if a target item's transfer function is locked for some reason, e.g. an item is being rented within a game or trading has been locked for an item type.

    Parameters

    • options: {
          accountAddress: string;
          order: OrderV2;
      }
      • accountAddress: string

        The account address that will be fulfilling the order

      • order: OrderV2

        Order to check

    Returns Promise<boolean>

    True if the order is fulfillable, else False.

    Throws

    Error if the order's protocol address is not supported by OpenSea. See isValidProtocol.

  • Remove all event listeners. This should be called when you're unmounting a component that listens to events to make UI updates.

    Parameters

    • Optional event: EventType

      Optional EventType to remove listeners for

    Returns void

  • Remove an event listener by calling .removeListener() on an event and listener.

    Parameters

    • event: EventType

      The EventType to remove a listener for\

    • listener: ((data) => void)

      The listener to remove

        • (data): void
        • Parameters

          Returns void

    Returns void

  • Transfer an asset. This asset can be an ERC20, ERC1155, or ERC721.

    Parameters

    • options: {
          amount?: BigNumberish;
          asset: AssetWithTokenStandard;
          fromAddress: string;
          overrides?: Overrides;
          toAddress: string;
      }
      • Optional amount?: BigNumberish

        Amount of asset to transfer. Not used for ERC721.

      • asset: AssetWithTokenStandard

        The Asset to transfer. tokenStandard must be set.

      • fromAddress: string

        The address to transfer from

      • Optional overrides?: Overrides

        Transaction overrides, ignored if not set.

      • toAddress: string

        The address to transfer to

    Returns Promise<void>

  • Unwrap WETH into ETH. Emits the UnwrapWeth event when the transaction is prompted.

    Parameters

    • options: {
          accountAddress: string;
          amountInEth: BigNumberish;
      }
      • accountAddress: string

        Address of the user's wallet containing the WETH

      • amountInEth: BigNumberish

        How much WETH to unwrap

    Returns Promise<void>

  • Wrap ETH into WETH. W-ETH is needed for making offers.

    Parameters

    • options: {
          accountAddress: string;
          amountInEth: BigNumberish;
      }
      • accountAddress: string

        Address of the user's wallet containing the ether

      • amountInEth: BigNumberish

        Amount of ether to wrap

    Returns Promise<void>