Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ opensea accounts get 0x21130e908bba2d41b63fbca7caa131285b8724f8
[version-link]: https://github.com/ProjectOpenSea/opensea-cli/releases
[npm-badge]: https://img.shields.io/npm/v/opensea-cli?color=red
[npm-link]: https://www.npmjs.com/package/opensea-cli
[ci-badge]: https://github.com/ProjectOpenSea/opensea-cli/actions/workflows/npm-publish.yml/badge.svg
[ci-link]: https://github.com/ProjectOpenSea/opensea-cli/actions/workflows/npm-publish.yml
[ci-badge]: https://github.com/ProjectOpenSea/opensea-cli/actions/workflows/ci.yml/badge.svg
[ci-link]: https://github.com/ProjectOpenSea/opensea-cli/actions/workflows/ci.yml
[license-badge]: https://img.shields.io/github/license/ProjectOpenSea/opensea-cli
[license-link]: https://github.com/ProjectOpenSea/opensea-cli/blob/main/LICENSE
4 changes: 1 addition & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const program = new Command()
program
.name("opensea")
.description("OpenSea CLI - Query the OpenSea API from the command line")
.version("0.1.0")
.version(process.env.npm_package_version ?? "0.0.0")
.addHelpText("before", BANNER)
.option("--api-key <key>", "OpenSea API key (or set OPENSEA_API_KEY env var)")
.option("--chain <chain>", "Default chain", "ethereum")
Expand Down Expand Up @@ -72,8 +72,6 @@ program.addCommand(tokensCommand(getClient, getFormat))
program.addCommand(searchCommand(getClient, getFormat))
program.addCommand(swapsCommand(getClient, getFormat))

program.hook("postAction", () => {})

async function main() {
try {
await program.parseAsync(process.argv)
Expand Down
101 changes: 6 additions & 95 deletions src/commands/search.ts
Original file line number Diff line number Diff line change
@@ -1,108 +1,19 @@
import { Command } from "commander"
import type { OpenSeaClient } from "../client.js"
import { formatOutput } from "../output.js"
import {
SEARCH_ACCOUNTS_QUERY,
SEARCH_COLLECTIONS_QUERY,
SEARCH_NFTS_QUERY,
SEARCH_TOKENS_QUERY,
} from "../queries.js"
import type {
SearchAccountResult,
SearchCollectionResult,
SearchNFTResult,
SearchTokenResult,
} from "../types/index.js"

const SEARCH_COLLECTIONS_QUERY = `
query SearchCollections($query: String!, $limit: Int, $chains: [ChainIdentifier!]) {
collectionsByQuery(query: $query, limit: $limit, chains: $chains) {
slug
name
description
imageUrl
chain {
identifier
name
}
stats {
totalSupply
ownerCount
volume {
usd
}
sales
}
floorPrice {
pricePerItem {
usd
native {
unit
symbol
}
}
}
}
}`

const SEARCH_NFTS_QUERY = `
query SearchItems($query: String!, $collectionSlug: String, $limit: Int, $chains: [ChainIdentifier!]) {
itemsByQuery(query: $query, collectionSlug: $collectionSlug, limit: $limit, chains: $chains) {
tokenId
name
description
imageUrl
contractAddress
collection {
slug
name
}
chain {
identifier
name
}
bestListing {
pricePerItem {
usd
native {
unit
symbol
}
}
}
owner {
address
displayName
}
}
}`

const SEARCH_TOKENS_QUERY = `
query SearchCurrencies($query: String!, $limit: Int, $chain: ChainIdentifier) {
currenciesByQuery(query: $query, limit: $limit, chain: $chain, allowlistOnly: false) {
name
symbol
imageUrl
usdPrice
contractAddress
chain {
identifier
name
}
stats {
marketCapUsd
oneDay {
priceChange
volume
}
}
}
}`

const SEARCH_ACCOUNTS_QUERY = `
query SearchAccounts($query: String!, $limit: Int) {
accountsByQuery(query: $query, limit: $limit) {
address
username
imageUrl
isVerified
}
}`

export function searchCommand(
getClient: () => OpenSeaClient,
getFormat: () => "json" | "table",
Expand Down
94 changes: 94 additions & 0 deletions src/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
export const SEARCH_COLLECTIONS_QUERY = `
query SearchCollections($query: String!, $limit: Int, $chains: [ChainIdentifier!]) {
collectionsByQuery(query: $query, limit: $limit, chains: $chains) {
slug
name
description
imageUrl
chain {
identifier
name
}
stats {
totalSupply
ownerCount
volume {
usd
}
sales
}
floorPrice {
pricePerItem {
usd
native {
unit
symbol
}
}
}
}
}`

export const SEARCH_NFTS_QUERY = `
query SearchItems($query: String!, $collectionSlug: String, $limit: Int, $chains: [ChainIdentifier!]) {
itemsByQuery(query: $query, collectionSlug: $collectionSlug, limit: $limit, chains: $chains) {
tokenId
name
description
imageUrl
contractAddress
collection {
slug
name
}
chain {
identifier
name
}
bestListing {
pricePerItem {
usd
native {
unit
symbol
}
}
}
owner {
address
displayName
}
}
}`

export const SEARCH_TOKENS_QUERY = `
query SearchCurrencies($query: String!, $limit: Int, $chain: ChainIdentifier) {
currenciesByQuery(query: $query, limit: $limit, chain: $chain, allowlistOnly: false) {
name
symbol
imageUrl
usdPrice
contractAddress
chain {
identifier
name
}
stats {
marketCapUsd
oneDay {
priceChange
volume
}
}
}
}`

export const SEARCH_ACCOUNTS_QUERY = `
query SearchAccounts($query: String!, $limit: Int) {
accountsByQuery(query: $query, limit: $limit) {
address
username
imageUrl
isVerified
}
}`
72 changes: 26 additions & 46 deletions src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { OpenSeaClient } from "./client.js"
import {
SEARCH_ACCOUNTS_QUERY,
SEARCH_COLLECTIONS_QUERY,
SEARCH_NFTS_QUERY,
SEARCH_TOKENS_QUERY,
} from "./queries.js"
import type {
Account,
AssetEvent,
Expand Down Expand Up @@ -346,17 +352,11 @@ class SearchAPI {
): Promise<SearchCollectionResult[]> {
const result = await this.client.graphql<{
collectionsByQuery: SearchCollectionResult[]
}>(
`query SearchCollections($query: String!, $limit: Int, $chains: [ChainIdentifier!]) {
collectionsByQuery(query: $query, limit: $limit, chains: $chains) {
slug name description imageUrl
chain { identifier name }
stats { totalSupply ownerCount volume { usd } sales }
floorPrice { pricePerItem { usd native { unit symbol } } }
}
}`,
{ query, limit: options?.limit, chains: options?.chains },
)
}>(SEARCH_COLLECTIONS_QUERY, {
query,
limit: options?.limit,
chains: options?.chains,
})
return result.collectionsByQuery
}

Expand All @@ -366,23 +366,12 @@ class SearchAPI {
): Promise<SearchNFTResult[]> {
const result = await this.client.graphql<{
itemsByQuery: SearchNFTResult[]
}>(
`query SearchItems($query: String!, $collectionSlug: String, $limit: Int, $chains: [ChainIdentifier!]) {
itemsByQuery(query: $query, collectionSlug: $collectionSlug, limit: $limit, chains: $chains) {
tokenId name description imageUrl contractAddress
collection { slug name }
chain { identifier name }
bestListing { pricePerItem { usd native { unit symbol } } }
owner { address displayName }
}
}`,
{
query,
collectionSlug: options?.collection,
limit: options?.limit,
chains: options?.chains,
},
)
}>(SEARCH_NFTS_QUERY, {
query,
collectionSlug: options?.collection,
limit: options?.limit,
chains: options?.chains,
})
return result.itemsByQuery
}

Expand All @@ -392,16 +381,11 @@ class SearchAPI {
): Promise<SearchTokenResult[]> {
const result = await this.client.graphql<{
currenciesByQuery: SearchTokenResult[]
}>(
`query SearchCurrencies($query: String!, $limit: Int, $chain: ChainIdentifier) {
currenciesByQuery(query: $query, limit: $limit, chain: $chain, allowlistOnly: false) {
name symbol imageUrl usdPrice contractAddress
chain { identifier name }
stats { marketCapUsd oneDay { priceChange volume } }
}
}`,
{ query, limit: options?.limit, chain: options?.chain },
)
}>(SEARCH_TOKENS_QUERY, {
query,
limit: options?.limit,
chain: options?.chain,
})
return result.currenciesByQuery
}

Expand All @@ -411,14 +395,10 @@ class SearchAPI {
): Promise<SearchAccountResult[]> {
const result = await this.client.graphql<{
accountsByQuery: SearchAccountResult[]
}>(
`query SearchAccounts($query: String!, $limit: Int) {
accountsByQuery(query: $query, limit: $limit) {
address username imageUrl isVerified
}
}`,
{ query, limit: options?.limit },
)
}>(SEARCH_ACCOUNTS_QUERY, {
query,
limit: options?.limit,
})
return result.accountsByQuery
}
}
Expand Down