Skip to content

Commit

Permalink
docs: Add code examples for Marketplace API endpoints (#2392)
Browse files Browse the repository at this point in the history
  • Loading branch information
allan-almeida-imtbl authored Nov 14, 2024
1 parent 4ee9859 commit b605781
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 7 deletions.
12 changes: 12 additions & 0 deletions examples/blockchain-data/api-examples-with-node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import { listNFTOwnersByTokenId } from './list-nft-owners-by-token-id';
import { listTokens } from './list-tokens';
import { refreshNFTMetadata } from './refresh-nft-metadata';
import { refreshStackedMetadata } from './refresh-stacked-metadata';
import { listFilters } from './list-filters';
import { searchNFTs } from './search-nfts';
import { searchStacks } from './search-stacks';
import { quotesForNFTs } from './quotes-for-nfts';
import { quotesForStacks } from './quotes-for-stacks';
import { listStacks } from './list-stacks';

export {
verifySuccessfulMints,
Expand All @@ -42,4 +48,10 @@ export {
listTokens,
refreshNFTMetadata,
refreshStackedMetadata,
listFilters,
searchNFTs,
searchStacks,
quotesForNFTs,
quotesForStacks,
listStacks,
};
12 changes: 12 additions & 0 deletions examples/blockchain-data/api-examples-with-node/list-filters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { blockchainData } from '@imtbl/sdk';
import { client } from '../lib';

export async function listFilters(
chainName: string,
contractAddress: string,
): Promise<blockchainData.Types.ListFiltersResult> {
return await client.listFilters({
chainName,
contractAddress,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export async function listNFTsByAccountAddress(
chainName: string,
contractAddress: string,
accountAddress: string,
): Promise<blockchainData.Types.ListNFTsResult> {
): Promise<blockchainData.Types.ListNFTsByOwnerResult> {
return await client.listNFTsByAccountAddress({
chainName,
contractAddress,
accountAddress,
});
};
}
12 changes: 12 additions & 0 deletions examples/blockchain-data/api-examples-with-node/list-stacks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { blockchainData } from '@imtbl/sdk';
import { client } from '../lib';

export async function listStacks(
chainName: string,
stackId: string[],
): Promise<blockchainData.Types.StackBundle[]> {
return await client.listStacks({
chainName,
stackId,
});
}
14 changes: 14 additions & 0 deletions examples/blockchain-data/api-examples-with-node/quotes-for-nfts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { blockchainData } from '@imtbl/sdk';
import { client } from '../lib';

export async function quotesForNFTs(
chainName: string,
contractAddress: string,
tokenId: string[],
): Promise<blockchainData.Types.QuotesForNFTsResult> {
return await client.quotesForNFTs({
chainName,
contractAddress,
tokenId,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { blockchainData } from '@imtbl/sdk';
import { client } from '../lib';

export async function quotesForStacks(
chainName: string,
contractAddress: string,
stackId: string[],
): Promise<blockchainData.Types.QuotesForStacksResult> {
return await client.quotesForStacks({
chainName,
contractAddress,
stackId,
});
}
12 changes: 12 additions & 0 deletions examples/blockchain-data/api-examples-with-node/search-nfts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { blockchainData } from '@imtbl/sdk';
import { client } from '../lib';

export async function searchNFTs(
chainName: string,
contractAddress: string[],
): Promise<blockchainData.Types.SearchNFTsResult> {
return await client.searchNFTs({
chainName,
contractAddress,
});
}
12 changes: 12 additions & 0 deletions examples/blockchain-data/api-examples-with-node/search-stacks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { blockchainData } from '@imtbl/sdk';
import { client } from '../lib';

export async function searchStacks(
chainName: string,
contractAddress: string[],
): Promise<blockchainData.Types.SearchStacksResult> {
return await client.searchStacks({
chainName,
contractAddress,
});
}
2 changes: 1 addition & 1 deletion examples/blockchain-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@imtbl/sdk": "latest"
"@imtbl/sdk": "1.70.0"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
Expand Down
58 changes: 58 additions & 0 deletions examples/blockchain-data/test/blockchain-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ import {
listNFTOwnersByTokenId,
listNFTOwnersByContractAddress,
listTokens,
listFilters,
searchNFTs,
searchStacks,
quotesForNFTs,
quotesForStacks,
listStacks,
} from '../api-examples-with-node';

const CHAIN_NAME = 'imtbl-zkevm-testnet';
const CONTRACT_ADDRESS = '0x21F0D60cfE554B6d5b7f9E799BDeBD97C5d64274';
const NFT_OWNER = '0x9C1634bebC88653D2Aebf4c14a3031f62092b1D9';
const TOKEN_ADDRESS = '0x007a4bdf308ca0074d7b95628e72a62f12b2c58f';
const MARKETPLACE_API_COLLECTION_ADDRESS =
'0x908aab24939160aca78c4267ddc291c5891b952d';
const MARKETPLACE_API_STACK_ID = '018c623c-da05-1104-88b1-71a536f0f8fb';

describe('Chains', () => {
describe('listChains', () => {
Expand Down Expand Up @@ -194,3 +203,52 @@ describe('Setup', () => {
});
});
});

describe('Marketplace API endpoints', () => {
describe('listFilters', () => {
test('returns successfully', async () => {
const result = await listFilters(CHAIN_NAME, CONTRACT_ADDRESS);
expect(result).not.toBe(null);
expect(result.result.filters.length).toBeGreaterThan(0);
});
});
describe('searchNFTs', () => {
test('returns successfully', async () => {
const result = await searchNFTs(CHAIN_NAME, [CONTRACT_ADDRESS]);
expect(result).not.toBe(null);
expect(result.result.length).toBeGreaterThan(0);
});
});
describe('searchStacks', () => {
test('returns successfully', async () => {
const result = await searchStacks(CHAIN_NAME, [CONTRACT_ADDRESS]);
expect(result).not.toBe(null);
expect(result.result.length).toBeGreaterThan(0);
});
});
describe('quotesForNFTs', () => {
test('returns successfully', async () => {
const result = await quotesForNFTs(CHAIN_NAME, CONTRACT_ADDRESS, ['1']);
expect(result).not.toBe(null);
expect(result.result.length).toBeGreaterThan(0);
});
});
describe('quotesForStacks', () => {
test('returns successfully', async () => {
const result = await quotesForStacks(
CHAIN_NAME,
MARKETPLACE_API_COLLECTION_ADDRESS,
[MARKETPLACE_API_STACK_ID],
);
expect(result).not.toBe(null);
expect(result.result.length).toBeGreaterThan(0);
});
});
describe('listStacks', () => {
test('returns successfully', async () => {
const result = await listStacks(CHAIN_NAME, [MARKETPLACE_API_STACK_ID]);
expect(result).not.toBe(null);
expect(result.length).toBeGreaterThan(0);
});
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"examples/passport/**",
"examples/orderbook/**",
"examples/checkout/**",
"examples/blockchain-data/**",
"examples/blockchain-data",
"examples/contracts/**"
],
"nohoist": [
Expand Down
Loading

0 comments on commit b605781

Please sign in to comment.