Skip to content

Commit d7d0e72

Browse files
committed
feat(nft-collections): Implement getOwnedNFTs method in ReservoirService
1 parent 29b5151 commit d7d0e72

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

packages/plugin-nft-collections/src/services/reservoir.ts

+49-1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,54 @@ export class ReservoirService {
310310
attributes?: Record<string, string>;
311311
}>
312312
> {
313-
return Promise.resolve([]);
313+
try {
314+
const endpoint = "/users/tokens/v1";
315+
const params = {
316+
users: owner,
317+
limit: 100, // Configurable limit
318+
includeAttributes: true,
319+
};
320+
321+
const response = await this.makeRequest<{
322+
tokens: Array<{
323+
token: {
324+
tokenId: string;
325+
collection: {
326+
id: string;
327+
name: string;
328+
};
329+
image: string;
330+
attributes?: Array<{
331+
key: string;
332+
value: string;
333+
}>;
334+
};
335+
}>;
336+
}>(endpoint, params, 1, {} as IAgentRuntime);
337+
338+
return response.tokens.map((token) => ({
339+
tokenId: token.token.tokenId,
340+
collectionAddress: token.token.collection.id,
341+
name: token.token.collection.name,
342+
imageUrl: token.token.image,
343+
attributes: token.token.attributes
344+
? Object.fromEntries(
345+
token.token.attributes.map((attr) => [
346+
attr.key,
347+
attr.value,
348+
])
349+
)
350+
: undefined,
351+
}));
352+
} catch (error) {
353+
const nftError = NFTErrorFactory.create(
354+
ErrorType.API,
355+
ErrorCode.API_ERROR,
356+
`Failed to fetch owned NFTs for owner ${owner}`,
357+
{ owner }
358+
);
359+
this.errorHandler.handleError(nftError);
360+
return [];
361+
}
314362
}
315363
}

0 commit comments

Comments
 (0)