opensea-js - v8.0.20
    Preparing search index...

    Class OpenSeaSDK

    The OpenSea SDK main class.

    Index

    Constructors

    • Create a new instance of OpenSeaSDK.

      Parameters

      • signerOrProvider: Signer | JsonRpcProvider

        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

      • Optionallogger: (arg: string) => void

        optional function for logging debug strings. defaults to no logging

      Returns OpenSeaSDK

    Properties

    api: OpenSeaAPI

    API instance

    chain: Chain

    The configured chain

    logger: (arg: string) => void

    Logger function to use when debugging

    provider: JsonRpcProvider

    Provider to use for transactions.

    seaport: Seaport

    Seaport client

    Methods

    • Add a listener for events emitted by the SDK.

      Parameters

      • event: EventType

        The EventType to listen to.

      • listener: (data: EventData) => void

        A callback that will accept an object with EventData\

      • 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 method allows you to approve an order with an on-chain transaction.

      Parameters

      • order: OrderV2

        Order to approve

      • Optionaldomain: 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

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

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

    • Batch approve multiple assets for transfer to the OpenSea conduit. This method checks which assets need approval and batches them efficiently:

      • 0 approvals needed: Returns early
      • 1 approval needed: Sends single transaction
      • 2+ approvals needed: Uses Multicall3 to batch all approvals in one transaction

      Parameters

      • options: {
            assets: { amount?: BigNumberish; asset: AssetWithTokenStandard }[];
            fromAddress: string;
            overrides?: Overrides;
        }
        • assets: { amount?: BigNumberish; asset: AssetWithTokenStandard }[]

          Array of assets to approve for transfer

        • fromAddress: string

          The address that owns the assets

        • Optionaloverrides?: Overrides

          Transaction overrides, ignored if not set.

      Returns Promise<string | undefined>

      Transaction hash of the approval transaction, or undefined if no approvals needed

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

    • Bulk transfer multiple assets using OpenSea's TransferHelper contract. This method is more gas-efficient than calling transfer() multiple times. Note: All assets must be approved for transfer to the OpenSea conduit before calling this method.

      Parameters

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

          Array of assets to transfer. Each asset must have tokenStandard set.

        • fromAddress: string

          The address to transfer from

        • Optionaloverrides?: Overrides

          Transaction overrides, ignored if not set.

      Returns Promise<string>

      Transaction hash of the bulk transfer

      Error if any asset is missing required fields (tokenId for NFTs, amount for ERC20/ERC1155).

      Error if any asset is not approved for transfer to the OpenSea conduit.

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

    • Cancel an order onchain, preventing it from ever being fulfilled. This method accepts either a full OrderV2 object or an order hash with protocol address.

      Parameters

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

          The account address that will be cancelling the order.

        • Optionaldomain?: string

          Optional domain for on-chain attribution. Hashed and included in calldata.

        • Optionalorder?: OrderV2

          The order to cancel (OrderV2 object)

        • OptionalorderHash?: string

          Optional order hash to cancel. Must provide protocolAddress if using this.

        • OptionalprotocolAddress?: string

          Required when using orderHash. The Seaport protocol address for the order.

      Returns Promise<void>

      Error if neither order nor orderHash is provided.

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

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

      // Cancel using OrderV2 object
      await sdk.cancelOrder({
      order: orderV2Object,
      accountAddress: "0x..."
      });
      // Cancel using order hash
      await sdk.cancelOrder({
      orderHash: "0x123...",
      protocolAddress: "0xabc...",
      accountAddress: "0x..."
      });
    • Cancel multiple orders onchain, preventing them from being fulfilled. This method accepts either full OrderV2 objects, OrderComponents, or order hashes with protocol address.

      Event Behavior: For backwards compatibility with the singular cancelOrder method, this method dispatches a CancelOrder event for the first order only, and only when an OrderV2 object is available (either provided directly or fetched via orderHashes). No event is dispatched when using OrderComponents directly, as they lack the full order data.

      Parameters

      • options: {
            accountAddress: string;
            domain?: string;
            orderHashes?: string[];
            orders?: (OrderV2 | OrderComponents)[];
            overrides?: Overrides;
            protocolAddress?: string;
        }
        • accountAddress: string

          The account address cancelling the orders.

        • Optionaldomain?: string

          Optional domain for on-chain attribution. Hashed and included in calldata.

        • OptionalorderHashes?: string[]

          Optional array of order hashes to cancel. Must provide protocolAddress if using this.

        • Optionalorders?: (OrderV2 | OrderComponents)[]

          Array of orders to cancel. Can be OrderV2 objects or OrderComponents.

        • Optionaloverrides?: Overrides

          Transaction overrides, ignored if not set.

        • OptionalprotocolAddress?: string

          Required when using orderHashes. The Seaport protocol address for the orders.

      Returns Promise<string>

      Transaction hash of the cancellation.

      Error if orderHashes is provided without protocolAddress.

      Error if neither orders nor orderHashes is provided.

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

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

    • Create and submit multiple listings using Seaport's bulk order creation. This method uses a single signature for all listings and submits them individually to the OpenSea API with rate limit handling. All listings must be from the same account address.

      Note: If only one listing is provided, this method will use a normal order signature instead of a bulk signature, as bulk signatures are more expensive to decode on-chain due to the merkle proof verification.

      Parameters

      • options: {
            accountAddress: string;
            continueOnError?: boolean;
            listings: {
                amount: BigNumberish;
                asset: AssetWithTokenId;
                buyerAddress?: string;
                domain?: string;
                expirationTime?: number;
                includeOptionalCreatorFees?: boolean;
                listingTime?: number;
                quantity?: BigNumberish;
                salt?: BigNumberish;
                zone?: string;
            }[];
            onProgress?: (completed: number, total: number) => void;
        }
        • accountAddress: string

          Address of the wallet making the listings

        • OptionalcontinueOnError?: boolean

          If true, continue submitting remaining listings even if some fail. Default: false (throw on first error).

        • listings: {
              amount: BigNumberish;
              asset: AssetWithTokenId;
              buyerAddress?: string;
              domain?: string;
              expirationTime?: number;
              includeOptionalCreatorFees?: boolean;
              listingTime?: number;
              quantity?: BigNumberish;
              salt?: BigNumberish;
              zone?: string;
          }[]

          Array of listing parameters. Each listing requires asset, amount, and optionally other listing parameters.

        • OptionalonProgress?: (completed: number, total: number) => void

          Optional callback for progress updates. Called after each listing is submitted (successfully or not).

      Returns Promise<BulkOrderResult>

      BulkOrderResult containing successful orders and any failures.

      Error if listings array is empty

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

      Error if any asset does not contain a token id.

      Error if continueOnError is false and any submission fails.

    • Create and submit multiple offers using Seaport's bulk order creation. This method uses a single signature for all offers and submits them individually to the OpenSea API with rate limit handling. All offers must be from the same account address.

      Note: If only one offer is provided, this method will use a normal order signature instead of a bulk signature, as bulk signatures are more expensive to decode on-chain due to the merkle proof verification.

      Parameters

      • options: {
            accountAddress: string;
            continueOnError?: boolean;
            offers: {
                amount: BigNumberish;
                asset: AssetWithTokenId;
                domain?: string;
                expirationTime?: BigNumberish;
                quantity?: BigNumberish;
                salt?: BigNumberish;
                zone?: string;
            }[];
            onProgress?: (completed: number, total: number) => void;
        }
        • accountAddress: string

          Address of the wallet making the offers

        • OptionalcontinueOnError?: boolean

          If true, continue submitting remaining offers even if some fail. Default: false (throw on first error).

        • offers: {
              amount: BigNumberish;
              asset: AssetWithTokenId;
              domain?: string;
              expirationTime?: BigNumberish;
              quantity?: BigNumberish;
              salt?: BigNumberish;
              zone?: string;
          }[]

          Array of offer parameters. Each offer requires asset, amount, and optionally other offer parameters.

        • OptionalonProgress?: (completed: number, total: number) => void

          Optional callback for progress updates. Called after each offer is submitted (successfully or not).

      Returns Promise<BulkOrderResult>

      BulkOrderResult containing successful orders and any failures.

      Error if offers array is empty

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

      Error if any asset does not contain a token id.

      Error if continueOnError is false and any submission fails.

    • Create and submit a collection offer.

      Parameters

      • options: {
            accountAddress: string;
            amount: BigNumberish;
            collectionSlug: string;
            domain?: string;
            expirationTime?: string | number;
            numericTraits?: { max?: number; min?: number; type: string }[];
            offerProtectionEnabled?: boolean;
            quantity: number;
            salt?: BigNumberish;
            traits?: { type: string; value: string }[];
            traitType?: string;
            traitValue?: string;
        }
        • accountAddress: string

          Address of the wallet making the offer.

        • amount: BigNumberish

          Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.

        • collectionSlug: string

          Identifier for the collection.

        • Optionaldomain?: string

          Optional domain for on-chain attribution. Hashed and included in salt.

        • OptionalexpirationTime?: string | number

          Expiration time (UTC seconds).

        • OptionalnumericTraits?: { max?: number; min?: number; type: string }[]

          If defined, an array of numeric trait criteria with min/max ranges.

        • OptionalofferProtectionEnabled?: boolean

          Use signed zone for protection against disabled items. Default: true.

        • quantity: number

          Number of assets to bid for.

        • Optionalsalt?: BigNumberish

          Arbitrary salt. Auto-generated if not provided.

        • Optionaltraits?: { type: string; value: string }[]

          If defined, an array of traits to create the multi-trait collection offer for.

        • OptionaltraitType?: string

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

        • OptionaltraitValue?: string

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

      Returns Promise<CollectionOffer | null>

      The CollectionOffer that was created.

    • Create and submit a listing for an asset.

      Parameters

      • options: {
            accountAddress: string;
            amount: BigNumberish;
            asset: AssetWithTokenId;
            buyerAddress?: string;
            domain?: string;
            expirationTime?: number;
            includeOptionalCreatorFees?: boolean;
            listingTime?: number;
            quantity?: BigNumberish;
            salt?: BigNumberish;
            zone?: string;
        }
        • accountAddress: string

          Address of the wallet making the listing

        • amount: BigNumberish

          Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.

        • asset: AssetWithTokenId

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

        • OptionalbuyerAddress?: 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.

        • Optionaldomain?: string

          Optional domain for on-chain attribution. Hashed and included in salt.

        • OptionalexpirationTime?: number

          Expiration time for the order, in UTC seconds.

        • OptionalincludeOptionalCreatorFees?: boolean

          If true, optional creator fees will be included in the listing. Default: false.

        • OptionallistingTime?: number

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

        • Optionalquantity?: BigNumberish

          Number of assets to list. Defaults to 1.

        • Optionalsalt?: BigNumberish

          Arbitrary salt. Auto-generated if not provided.

        • Optionalzone?: string

          Zone for order protection. Defaults to no zone.

      Returns Promise<OrderV2>

      The OrderV2 that was created.

      Error if the asset does not contain a token id.

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

      Error if the amount is not greater than 0.

    • Create and validate a listing onchain. Combines order building with onchain validation. Validation costs gas upfront but makes fulfillment cheaper (no signature verification needed).

      Parameters

      • options: {
            accountAddress: string;
            amount: BigNumberish;
            asset: AssetWithTokenId;
            buyerAddress?: string;
            domain?: string;
            expirationTime?: number;
            includeOptionalCreatorFees?: boolean;
            listingTime?: number;
            quantity?: BigNumberish;
            salt?: BigNumberish;
            zone?: string;
        }
        • accountAddress: string

          Address of the wallet making the listing

        • amount: BigNumberish

          Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.

        • asset: AssetWithTokenId

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

        • OptionalbuyerAddress?: string

          Optional buyer restriction. Only this address can purchase.

        • Optionaldomain?: string

          Optional domain for on-chain attribution. Hashed and included in salt.

        • OptionalexpirationTime?: number

          Expiration time (UTC seconds).

        • OptionalincludeOptionalCreatorFees?: boolean

          Include optional creator fees. Default: false.

        • OptionallistingTime?: number

          When order becomes fulfillable (UTC seconds). Defaults to now.

        • Optionalquantity?: BigNumberish

          Number of assets to list. Defaults to 1.

        • Optionalsalt?: BigNumberish

          Arbitrary salt. Auto-generated if not provided.

        • Optionalzone?: string

          Zone for order protection. Defaults to no zone.

      Returns Promise<string>

      Transaction hash

      Error if asset missing token id or accountAddress unavailable.

    • Create and submit an offer on an asset.

      Parameters

      • options: {
            accountAddress: string;
            amount: BigNumberish;
            asset: AssetWithTokenId;
            domain?: string;
            expirationTime?: BigNumberish;
            quantity?: BigNumberish;
            salt?: BigNumberish;
            zone?: string;
        }
        • accountAddress: string

          Address of the wallet making the offer.

        • amount: BigNumberish

          Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.

        • asset: AssetWithTokenId

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

        • Optionaldomain?: string

          Optional domain for on-chain attribution. Hashed and included in salt.

        • OptionalexpirationTime?: BigNumberish

          Expiration time for the order, in UTC seconds

        • Optionalquantity?: BigNumberish

          Number of assets to bid for. Defaults to 1.

        • Optionalsalt?: BigNumberish

          Arbitrary salt. Auto-generated if not provided.

        • Optionalzone?: string

          Zone for order protection. Defaults to chain's signed zone.

      Returns Promise<OrderV2>

      The OrderV2 that was created.

      Error if the asset does not contain a token id.

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

      Error if the amount is not greater than 0.

    • Create and validate an offer onchain. Combines order building with onchain validation. Validation costs gas upfront but makes fulfillment cheaper (no signature verification needed).

      Parameters

      • options: {
            accountAddress: string;
            amount: BigNumberish;
            asset: AssetWithTokenId;
            domain?: string;
            expirationTime?: BigNumberish;
            quantity?: BigNumberish;
            salt?: BigNumberish;
            zone?: string;
        }
        • accountAddress: string

          Address of the wallet making the offer.

        • amount: BigNumberish

          Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.

        • asset: AssetWithTokenId

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

        • Optionaldomain?: string

          Optional domain for on-chain attribution. Hashed and included in salt.

        • OptionalexpirationTime?: BigNumberish

          Expiration time (UTC seconds).

        • Optionalquantity?: BigNumberish

          Number of assets to bid for. Defaults to 1.

        • Optionalsalt?: BigNumberish

          Arbitrary salt. Auto-generated if not provided.

        • Optionalzone?: string

          Zone for order protection. Defaults to chain's signed zone.

      Returns Promise<string>

      Transaction hash

      Error if asset missing token id or accountAddress unavailable.

    • Fulfill an order for an asset. The order can be either a listing or an offer. Uses the OpenSea API to generate fulfillment transaction data and executes it directly.

      Parameters

      • options: {
            accountAddress: string;
            assetContractAddress?: string;
            includeOptionalCreatorFees?: boolean;
            order: OrderV2 | Order | Offer | Listing;
            overrides?: Overrides;
            recipientAddress?: string;
            tokenId?: string;
            unitsToFill?: BigNumberish;
        }
        • accountAddress: string

          Address of the wallet taking the offer.

        • OptionalassetContractAddress?: string

          Optional address of the NFT contract for criteria offers (e.g., collection offers). Required when fulfilling collection offers.

        • OptionalincludeOptionalCreatorFees?: boolean

          Whether to include optional creator fees in the fulfillment. If creator fees are already required, this is a no-op. Defaults to false.

        • order: OrderV2 | Order | Offer | Listing

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

        • Optionaloverrides?: Overrides

          Transaction overrides, ignored if not set.

        • OptionalrecipientAddress?: string

          Optional recipient address for the NFT when fulfilling a listing. Not applicable for offers.

        • OptionaltokenId?: string

          Optional token ID for criteria offers (e.g., collection offers). Required when fulfilling collection offers.

        • OptionalunitsToFill?: BigNumberish

          Optional number of units to fill. Defaults to 1 for both listings and offers.

      Returns Promise<string>

      Transaction hash of the order.

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

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

      Error if a signer is not provided (read-only providers cannot fulfill orders).

      Error if the order hash is not available.

    • 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.

      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.

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

    • Offchain cancel an order, offer or listing, by its order hash when protected by the SignedZone. Protocol and Chain are required to prevent hash collisions. Please note cancellation is only assured if a fulfillment signature was not vended prior to cancellation.

      Parameters

      • protocolAddress: string

        The Seaport address for the order.

      • orderHash: string

        The order hash, or external identifier, of the order.

      • chain: Chain = ...

        The chain where the order is located.

      • OptionaloffererSignature: string

        An EIP-712 signature from the offerer of the order. If this is not provided, the API key used to initialize the SDK must belong to the order's offerer. The signature must be a EIP-712 signature consisting of the order's Seaport contract's name, version, address, and chain. The struct to sign is OrderHash containing a single bytes32 field.

      • OptionaluseSignerToDeriveOffererSignature: boolean

        Derive the offererSignature from the Ethers signer passed into this sdk.

      Returns Promise<CancelOrderResponse>

      The response from the API.

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

      Parameters

      • Optionalevent: EventType

        Optional EventType to remove listeners for

      Returns void

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

      Parameters

      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;
        }
        • Optionalamount?: 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

        • Optionaloverrides?: Overrides

          Transaction overrides, ignored if not set.

        • toAddress: string

          The address to transfer to

      Returns Promise<void>

    • Unwrap wrapped native asset into native asset (e.g. WETH into ETH, WPOL into POL). 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 wrapped native asset

        • amountInEth: BigNumberish

          How much wrapped native asset to unwrap

      Returns Promise<void>

    • Validates an order onchain using Seaport's validate() method. This submits the order onchain and pre-validates the order using Seaport, which makes it cheaper to fulfill since a signature is not needed to be verified during fulfillment for the order, but is not strictly required and the alternative is orders can be submitted to the API for free instead of sent onchain.

      Parameters

      • orderComponents: OrderComponents

        Order components to validate onchain

      • accountAddress: string

        Address of the wallet that will pay the gas to validate the order

      Returns Promise<string>

      Transaction hash of the validation transaction

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

    • Wrap native asset into wrapped native asset (e.g. ETH into WETH, POL into WPOL). Wrapped native assets are needed for making offers.

      Parameters

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

          Address of the user's wallet containing the native asset

        • amountInEth: BigNumberish

          Amount of native asset to wrap

      Returns Promise<void>