TypeScript SDK for buying, selling, and managing NFTs and tokens on OpenSea. Supports ethers and viem providers.
cd packages/sdk
pnpm run build
pnpm run test
pnpm run test:integration # needs a .env, see test/README-integration.md
pnpm run check-types
pnpm run lint- Provide
OpenSeaSDK(ethers) andOpenSeaViemSDK(viem) entry points. - Provide the Stream API client at the
@opensea/sdk/streamsubpath. - Camelize API responses and expose typed helpers for orders, fulfillment, assets, and wallet auth.
- Keep the
Chainenum in sync withChainIdentifierfrom@opensea/api-types.
- Never hand-roll API request/response types. Import from
@opensea/api-types(or re-export throughsrc/api/types.ts) using canonical schema names. - Chain enum sync is compile-time enforced. Adding a
ChainIdentifierwithout a matchingChainvalue or payment-token case failspnpm check-types. Updatescripts/chain-data.jsonat the monorepo root and runpnpm sync-chainswhen adding chains. - Dual provider support. Changes to
BaseOpenSeaSDKaffect both ethers and viem paths; update both provider adapters if provider-specific logic changes. - OAuth token contract.
OpenSeaOAuthrequestsoffline_access; refresh responses may omit rotation — keep the previous refresh token. The top-levelwalletJWT claim is wallet identity;subis an account id. - No secret leakage. API keys live in
OpenSeaAPIConfig.apiKey; never log them. - Auth scopes are coupled to the spec in both directions.
src/scopes.tsasserts at compile time thatOPENSEA_SCOPESmatchesAuthScopefrom@opensea/api-types, so a new scope has to land in the spec and in the constant in the same commit, and that commit cannot pass theMirror layoutgate until api-types publishes. Read Spec changes and release order before starting. - Stream client is subpath-only and dependency-free.
src/stream/is exported from./streamand never fromsrc/index.ts—EventType,Trait,TraitOfferEvent, andCollectionOfferEventexist in both surfaces with different shapes.src/stream/transport/stays internal so a non-Phoenix Stream v2 can replace it without a breaking release; client code usesStreamTransport, neverPhoenixChannelsTransport. The built entry resolves to six local files with zero external requires, so check the require graph before adding an import. Live tests are intest/integration/stream.spec.tsand need real network access, seetest/README-integration.md.
- CommonJS (
"type": "commonjs") for broad consumer support. - Node 22+ is the floor. The stream client relies on a global
WebSocket. viemis an optional peer dependency; main entry uses ethers.- Prefer
stringfor decimalAmountvalues.