Skip to content

Commit 2548514

Browse files
committed
Sync from opensea-devtools
1 parent 4343e6b commit 2548514

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/sdk.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import type {
44
Account,
55
AccountResolveResponse,
66
AssetEvent,
7+
AssetMetadataResponse,
78
Chain,
89
ChainListResponse,
910
Collection,
11+
CollectionDetailedResponse,
1012
CollectionOrderBy,
1113
CollectionPaginatedResponse,
1214
CollectionStats,
@@ -284,6 +286,24 @@ class NFTsAPI {
284286
params,
285287
)
286288
}
289+
290+
async getCollection(
291+
chain: Chain,
292+
address: string,
293+
identifier: string,
294+
): Promise<CollectionDetailedResponse> {
295+
return this.client.get(
296+
`/api/v2/chain/${chain}/contract/${address}/nfts/${identifier}/collection`,
297+
)
298+
}
299+
300+
async getMetadata(
301+
chain: Chain,
302+
address: string,
303+
tokenId: string,
304+
): Promise<AssetMetadataResponse> {
305+
return this.client.get(`/api/v2/metadata/${chain}/${address}/${tokenId}`)
306+
}
287307
}
288308

289309
class ListingsAPI {

src/types/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export type DropPaginatedResponse = Schemas["DropPaginatedResponse"]
6666
export type DropMintRequest = Schemas["DropMintRequest"]
6767
export type DropMintResponse = Schemas["DropMintResponse"]
6868
export type AccountResolveResponse = Schemas["AccountResolveResponse"]
69+
export type AssetMetadataResponse = Schemas["AssetMetadataResponse"]
6970

7071
// ── CLI-specific types (not from API spec) ──────────────────────────
7172

test/sdk.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,25 @@ describe("OpenSeaCLI", () => {
216216
"/api/v2/chain/ethereum/contract/0xabc",
217217
)
218218
})
219+
220+
it("getCollection calls correct endpoint", async () => {
221+
mockGet.mockResolvedValue({
222+
name: "Art Blocks",
223+
collection: "art-blocks",
224+
})
225+
const result = await sdk.nfts.getCollection("ethereum", "0xabc", "42")
226+
expect(mockGet).toHaveBeenCalledWith(
227+
"/api/v2/chain/ethereum/contract/0xabc/nfts/42/collection",
228+
)
229+
expect(result.name).toBe("Art Blocks")
230+
})
231+
232+
it("getMetadata calls correct endpoint", async () => {
233+
mockGet.mockResolvedValue({ name: "Cool NFT", traits: [] })
234+
const result = await sdk.nfts.getMetadata("ethereum", "0xabc", "1")
235+
expect(mockGet).toHaveBeenCalledWith("/api/v2/metadata/ethereum/0xabc/1")
236+
expect(result.name).toBe("Cool NFT")
237+
})
219238
})
220239

221240
describe("listings", () => {

0 commit comments

Comments
 (0)