---
updatedAt: 2026-11-03T05:00:14.000Z
agentTools:
  projectIndex: https://docs.opensea.io/llms.txt
---

# Search and discovery

Build search and browse experiences using the OpenSea API and SDK.

The OpenSea API provides search and browse endpoints for finding collections, tokens, NFTs, and accounts across all supported chains. Build search experiences, explore pages, and discovery features with the tools below.

### Prerequisites

* Node.js >= 20.0.0
* OpenSea API key ([get one here](https://docs.opensea.io/reference/api-keys), or use the [instant API key endpoint](https://docs.opensea.io/reference/create_instant_api_key))

> **Security Warning:** Do not use the SDK in client-side code, since your API key would be exposed. Use it on a backend server and return transaction data to your frontend.

### Setup

```bash
npm install @opensea/sdk viem
```

```typescript
import { createPublicClient, createWalletClient, http } from "viem";
import { mainnet } from "viem/chains";
import { OpenSeaSDK, Chain } from "@opensea/sdk/viem";

const publicClient = createPublicClient({ chain: mainnet, transport: http("https://your-rpc-url") });
const walletClient = createWalletClient({ chain: mainnet, transport: http("https://your-rpc-url"), account: "0x..." });

const sdk = new OpenSeaSDK(
  { publicClient, walletClient },
  { chain: Chain.Mainnet, apiKey: "YOUR_API_KEY" },
);
```

> The examples below use viem. The SDK also supports ethers.js (v6+); see [Buy and sell NFTs](https://docs.opensea.io/docs/buy-and-sell-nfts) for the ethers setup. All SDK methods work the same with either library.

## Universal search

Search across collections, tokens, NFTs, and accounts in a single query. Each result has a `type` that says which of its `collection`, `nft`, `token`, or `account` fields is set.

#### SDK

```typescript
const results = await sdk.api.search({
  query: "cool cats",
  chains: ["ethereum"],
  assetTypes: ["collection", "nft"],
  limit: 10,
});

for (const result of results.results) {
  switch (result.type) {
    case "collection":
      console.log("Collection:", result.collection?.name);
      break;
    case "nft":
      console.log("NFT:", result.nft?.name);
      break;
    case "token":
      console.log("Token:", result.token?.name);
      break;
    case "account":
      console.log("Account:", result.account?.address);
      break;
  }
}
```

#### curl

```bash
curl -X GET "https://api.opensea.io/api/v2/search?query=cool+cats&chains=ethereum&asset_types=collection&asset_types=nft&limit=10" \
  -H "X-API-KEY: YOUR_API_KEY"
```

**Parameters:**

| Parameter     | Description                                                |
| ------------- | ---------------------------------------------------------- |
| `query`       | Search query (required)                                    |
| `chains`      | Filter by chain(s) (e.g., `ethereum`, `base`, `solana`)    |
| `asset_types` | Filter by type(s): `collection`, `nft`, `token`, `account` |
| `limit`       | Max results (1 to 50, default 20)                          |

## Browse collections

List collections with optional filters for chain, creator, and ordering.

#### SDK

```typescript
import { CollectionOrderByOption } from "@opensea/sdk/viem";

// Arguments are positional: orderBy, chain, creatorUsername, includeHidden, limit, next
const collections = await sdk.api.collections.getCollections(
  CollectionOrderByOption.CREATED_DATE,
  Chain.Mainnet,
  undefined,
  false,
  20,
);

for (const collection of collections.collections) {
  console.log(collection.name, collection.collection);
}
```

#### curl

```bash
curl -X GET "https://api.opensea.io/api/v2/collections?chain=ethereum&limit=20" \
  -H "X-API-KEY: YOUR_API_KEY"
```

## Fetch NFTs

### By collection

```typescript
const nfts = await sdk.api.nfts.getNFTsByCollection("boredapeyachtclub", 10);
```

```bash
curl -X GET "https://api.opensea.io/api/v2/collection/boredapeyachtclub/nfts?limit=10" \
  -H "X-API-KEY: YOUR_API_KEY"
```

### By contract

```typescript
const nfts = await sdk.api.nfts.getNFTsByContract(
  "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
  10,
);
```

```bash
curl -X GET "https://api.opensea.io/api/v2/chain/ethereum/contract/0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D/nfts?limit=10" \
  -H "X-API-KEY: YOUR_API_KEY"
```

### By account (owned NFTs)

```typescript
const owned = await sdk.api.nfts.getNFTsByAccount("0xWALLET_ADDRESS", 20);
```

```bash
curl -X GET "https://api.opensea.io/api/v2/chain/ethereum/account/0xWALLET_ADDRESS/nfts?limit=20" \
  -H "X-API-KEY: YOUR_API_KEY"
```

## Trait-based filtering

Retrieve the available traits for a collection, then use them to filter NFTs.

### Get available traits

```typescript
const traits = await sdk.api.collections.getTraits("boredapeyachtclub");
console.log(traits);
// { categories: { Background: "string", ... }, counts: { Background: { Gold: 46, ... }, ... } }
```

```bash
curl -X GET "https://api.opensea.io/api/v2/traits/boredapeyachtclub" \
  -H "X-API-KEY: YOUR_API_KEY"
```

### Filter by trait

The best listings, collection NFTs, collection events, and trait offers endpoints take a `traits` parameter: a JSON array of `{"traitType", "value"}` objects, all of which an item must match. For example, find the cheapest active listings for "Gold" background Bored Apes:

```bash
curl -G "https://api.opensea.io/api/v2/listings/collection/boredapeyachtclub/best" \
  -H "X-API-KEY: YOUR_API_KEY" \
  --data-urlencode 'traits=[{"traitType":"Background","value":"Gold"}]'
```

## Account lookup

### Get account details

```typescript
const account = await sdk.api.accounts.getAccount("0xWALLET_ADDRESS");
console.log(account.username, account.address);
```

```bash
curl -X GET "https://api.opensea.io/api/v2/accounts/0xWALLET_ADDRESS" \
  -H "X-API-KEY: YOUR_API_KEY"
```

### Resolve ENS or username

```typescript
const resolved = await sdk.api.accounts.resolveAccount("vitalik.eth");
console.log(resolved.address);
```

## Chain discovery

List all supported chains:

#### SDK

```typescript
const chains = await sdk.api.chains.getChains();
for (const chain of chains.chains) {
  console.log(chain.chain, chain.name);
}
```

#### curl

```bash
curl -X GET "https://api.opensea.io/api/v2/chains" \
  -H "X-API-KEY: YOUR_API_KEY"
```

## CLI

The <Anchor label="OpenSea CLI" target="_blank" href="https://github.com/ProjectOpenSea/opensea-cli">OpenSea CLI</Anchor> supports search and discovery:

```bash
# Universal search
opensea search "cool cats"

# Collection details
opensea collections get boredapeyachtclub

# NFTs in a collection
opensea nfts list-by-collection boredapeyachtclub --limit 5

# Account lookup
opensea accounts get 0xWALLET_ADDRESS
```

## Next steps

* [Search trading cards](https://docs.opensea.io/docs/search-trading-cards): search tokenized trading cards across issuers by franchise, grader, and grade
* [Query analytics and events](https://docs.opensea.io/docs/query-analytics-and-events): collection stats, trending data, and events
* [Buy and sell NFTs](https://docs.opensea.io/docs/buy-and-sell-nfts): create listings and offers for discovered NFTs
* [Swap tokens](https://docs.opensea.io/docs/swap-tokens): swap tokens discovered via search
* <Anchor label="Search API reference" target="_blank" href="https://docs.opensea.io/reference/search">Search API reference</Anchor>
* <Anchor label="OpenSea SDK" target="_blank" href="https://github.com/ProjectOpenSea/opensea-sdk">@opensea/sdk on GitHub</Anchor>