Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
core-sdk examples for collections (#265)
Browse files Browse the repository at this point in the history
* core-sdk examples for collections

* linting issue

* Linter fixes

---------

Co-authored-by: Praveen Suluvai <[email protected]>
Co-authored-by: coreyneal-immutable <[email protected]>
  • Loading branch information
3 people authored Feb 7, 2023
1 parent a3e492d commit 9666eb9
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 1 deletion.
22 changes: 22 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

31 changes: 31 additions & 0 deletions examples/listCollectionFilters.ts
Original file line number Diff line number Diff line change
@@ -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);
}
})();
34 changes: 34 additions & 0 deletions examples/listCollections.ts
Original file line number Diff line number Diff line change
@@ -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);
}
})();
5 changes: 4 additions & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
35 changes: 35 additions & 0 deletions examples/updateCollection.ts
Original file line number Diff line number Diff line change
@@ -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);
}
})();

0 comments on commit 9666eb9

Please sign in to comment.