From 9666eb91d36f97c76134c5bbc0cf8d54fa1b1cb5 Mon Sep 17 00:00:00 2001 From: cdrabner95 <114622650+cdrabner95@users.noreply.github.com> Date: Tue, 7 Feb 2023 15:49:48 -0500 Subject: [PATCH] core-sdk examples for collections (#265) * core-sdk examples for collections * linting issue * Linter fixes --------- Co-authored-by: Praveen Suluvai Co-authored-by: coreyneal-immutable --- examples/README.md | 22 +++++++++++++++++++ examples/listCollectionFilters.ts | 31 +++++++++++++++++++++++++++ examples/listCollections.ts | 34 ++++++++++++++++++++++++++++++ examples/package.json | 5 ++++- examples/updateCollection.ts | 35 +++++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 examples/listCollectionFilters.ts create mode 100644 examples/listCollections.ts create mode 100644 examples/updateCollection.ts diff --git a/examples/README.md b/examples/README.md index 66483a8a..c3b1cda1 100644 --- a/examples/README.md +++ b/examples/README.md @@ -368,3 +368,25 @@ Update [completeErc20Withdrawal.ts](./completeErc20Withdrawal.ts#L10) with the t ```sh yarn complete-erc20-withdrawal ``` +## List collections + +Update [listCollections.ts](./listCollections.ts#L10) with the wanted filters and run + +```sh +yarn list-collections +``` +## List collection filters + +Update [listCollectionFilters.ts](./listCollectionFilters.ts#L10) with the wanted filters and run + +```sh +yarn list-collection-filters +``` +## Update collection + +Update [updateCollection.ts](./updateCollection.ts#L10) with the all values filled in and run + +```sh +yarn update-collection +``` + diff --git a/examples/listCollectionFilters.ts b/examples/listCollectionFilters.ts new file mode 100644 index 00000000..1a3df620 --- /dev/null +++ b/examples/listCollectionFilters.ts @@ -0,0 +1,31 @@ +import { + Config, + ImmutableX, + CollectionsApiListCollectionFiltersRequest, +} from '@imtbl/core-sdk'; + +(async () => { + try { + // IMX class client + const client = new ImmutableX(Config.PRODUCTION); + + const collectionListFiltersRequest: CollectionsApiListCollectionFiltersRequest = + { + pageSize: 200, // max size 200 + address: '', // collection address + nextPageToken: '', // cursor + }; + + const collectionListFiltersResponse = await client.listCollectionFilters( + collectionListFiltersRequest, + ); + + console.log( + 'collectionListFiltersResponse', + JSON.stringify(collectionListFiltersResponse, null, 4), + ); + } catch (err) { + console.error(err); + process.exit(1); + } +})(); diff --git a/examples/listCollections.ts b/examples/listCollections.ts new file mode 100644 index 00000000..18daa03f --- /dev/null +++ b/examples/listCollections.ts @@ -0,0 +1,34 @@ +import { + Config, + ImmutableX, + CollectionsApiListCollectionsRequest, +} from '@imtbl/core-sdk'; + +(async () => { + try { + // IMX class client + const client = new ImmutableX(Config.SANDBOX); + + const collectionListRequest: CollectionsApiListCollectionsRequest = { + pageSize: 200, + orderBy: 'name', //'name' | 'address' | 'project_id' | 'created_at' | 'updated_at' + direction: 'asc', // asc | desc + blacklist: '', // list of collections to be excluded seperated by comma + whitelist: '', // list of collections to be included seperated by comma + keyword: '', // word to search for in description and collection name + cursor: '', // cursor + }; + + const collectionListResponse = await client.listCollections( + collectionListRequest, + ); + + console.log( + 'collectionListResponse', + JSON.stringify(collectionListResponse, null, 4), + ); + } catch (err) { + console.error(err); + process.exit(1); + } +})(); diff --git a/examples/package.json b/examples/package.json index d90ac738..2b4420ea 100644 --- a/examples/package.json +++ b/examples/package.json @@ -48,7 +48,10 @@ "create-nft-withdrawal": "ts-node -r dotenv/config createNftWithdrawal.ts", "complete-nft-withdrawal": "ts-node -r dotenv/config completeNftWithdrawal.ts", "complete-erc20-withdrawal": "ts-node -r dotenv/config completeErc20Withdrawal.ts", - "create-erc20-withdrawal": "ts-node -r dotenv/config completeErc20Withdrawal.ts" + "create-erc20-withdrawal": "ts-node -r dotenv/config completeErc20Withdrawal.ts", + "list-collections": "ts-node -r dotenv/config listCollections.ts", + "list-collection-filters": "ts-node -r dotenv/config listCollectionFilters.ts", + "update-collection": "ts-node -r dotenv/config updateCollection.ts" }, "dependencies": { "@ethersproject/providers": "^5.7.2", diff --git a/examples/updateCollection.ts b/examples/updateCollection.ts new file mode 100644 index 00000000..ef77a60a --- /dev/null +++ b/examples/updateCollection.ts @@ -0,0 +1,35 @@ +import { Config, ImmutableX, UpdateCollectionRequest } from '@imtbl/core-sdk'; +import { generateWalletConnection } from './libs/walletConnection'; + +(async () => { + try { + // IMX class client + const client = new ImmutableX(Config.SANDBOX); + + const walletConnection = await generateWalletConnection('goerli'); + + const collectionAddress = ''; // collection address + + const collectionUpdateRequest: UpdateCollectionRequest = { + collection_image_url: '', // must be valid url or request will fail + description: '', // string + icon_url: '', // must be valid url or request will fail + metadata_api_url: '', // must be valid url or request will fail + name: '', // string + }; + + const collectionUpdateResponse = await client.updateCollection( + walletConnection.ethSigner, + collectionAddress, + collectionUpdateRequest, + ); + + console.log( + 'collectionUpdateResponse', + JSON.stringify(collectionUpdateResponse, null, 4), + ); + } catch (err) { + console.error(err); + process.exit(1); + } +})();