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

Commit 9666eb9

Browse files
cdrabner95suluvaicoreyneal-immutable
authored
core-sdk examples for collections (#265)
* core-sdk examples for collections * linting issue * Linter fixes --------- Co-authored-by: Praveen Suluvai <[email protected]> Co-authored-by: coreyneal-immutable <[email protected]>
1 parent a3e492d commit 9666eb9

File tree

5 files changed

+126
-1
lines changed

5 files changed

+126
-1
lines changed

examples/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,25 @@ Update [completeErc20Withdrawal.ts](./completeErc20Withdrawal.ts#L10) with the t
368368
```sh
369369
yarn complete-erc20-withdrawal
370370
```
371+
## List collections
372+
373+
Update [listCollections.ts](./listCollections.ts#L10) with the wanted filters and run
374+
375+
```sh
376+
yarn list-collections
377+
```
378+
## List collection filters
379+
380+
Update [listCollectionFilters.ts](./listCollectionFilters.ts#L10) with the wanted filters and run
381+
382+
```sh
383+
yarn list-collection-filters
384+
```
385+
## Update collection
386+
387+
Update [updateCollection.ts](./updateCollection.ts#L10) with the all values filled in and run
388+
389+
```sh
390+
yarn update-collection
391+
```
392+

examples/listCollectionFilters.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {
2+
Config,
3+
ImmutableX,
4+
CollectionsApiListCollectionFiltersRequest,
5+
} from '@imtbl/core-sdk';
6+
7+
(async () => {
8+
try {
9+
// IMX class client
10+
const client = new ImmutableX(Config.PRODUCTION);
11+
12+
const collectionListFiltersRequest: CollectionsApiListCollectionFiltersRequest =
13+
{
14+
pageSize: 200, // max size 200
15+
address: '', // collection address
16+
nextPageToken: '', // cursor
17+
};
18+
19+
const collectionListFiltersResponse = await client.listCollectionFilters(
20+
collectionListFiltersRequest,
21+
);
22+
23+
console.log(
24+
'collectionListFiltersResponse',
25+
JSON.stringify(collectionListFiltersResponse, null, 4),
26+
);
27+
} catch (err) {
28+
console.error(err);
29+
process.exit(1);
30+
}
31+
})();

examples/listCollections.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {
2+
Config,
3+
ImmutableX,
4+
CollectionsApiListCollectionsRequest,
5+
} from '@imtbl/core-sdk';
6+
7+
(async () => {
8+
try {
9+
// IMX class client
10+
const client = new ImmutableX(Config.SANDBOX);
11+
12+
const collectionListRequest: CollectionsApiListCollectionsRequest = {
13+
pageSize: 200,
14+
orderBy: 'name', //'name' | 'address' | 'project_id' | 'created_at' | 'updated_at'
15+
direction: 'asc', // asc | desc
16+
blacklist: '', // list of collections to be excluded seperated by comma
17+
whitelist: '', // list of collections to be included seperated by comma
18+
keyword: '', // word to search for in description and collection name
19+
cursor: '', // cursor
20+
};
21+
22+
const collectionListResponse = await client.listCollections(
23+
collectionListRequest,
24+
);
25+
26+
console.log(
27+
'collectionListResponse',
28+
JSON.stringify(collectionListResponse, null, 4),
29+
);
30+
} catch (err) {
31+
console.error(err);
32+
process.exit(1);
33+
}
34+
})();

examples/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@
4848
"create-nft-withdrawal": "ts-node -r dotenv/config createNftWithdrawal.ts",
4949
"complete-nft-withdrawal": "ts-node -r dotenv/config completeNftWithdrawal.ts",
5050
"complete-erc20-withdrawal": "ts-node -r dotenv/config completeErc20Withdrawal.ts",
51-
"create-erc20-withdrawal": "ts-node -r dotenv/config completeErc20Withdrawal.ts"
51+
"create-erc20-withdrawal": "ts-node -r dotenv/config completeErc20Withdrawal.ts",
52+
"list-collections": "ts-node -r dotenv/config listCollections.ts",
53+
"list-collection-filters": "ts-node -r dotenv/config listCollectionFilters.ts",
54+
"update-collection": "ts-node -r dotenv/config updateCollection.ts"
5255
},
5356
"dependencies": {
5457
"@ethersproject/providers": "^5.7.2",

examples/updateCollection.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Config, ImmutableX, UpdateCollectionRequest } from '@imtbl/core-sdk';
2+
import { generateWalletConnection } from './libs/walletConnection';
3+
4+
(async () => {
5+
try {
6+
// IMX class client
7+
const client = new ImmutableX(Config.SANDBOX);
8+
9+
const walletConnection = await generateWalletConnection('goerli');
10+
11+
const collectionAddress = ''; // collection address
12+
13+
const collectionUpdateRequest: UpdateCollectionRequest = {
14+
collection_image_url: '', // must be valid url or request will fail
15+
description: '', // string
16+
icon_url: '', // must be valid url or request will fail
17+
metadata_api_url: '', // must be valid url or request will fail
18+
name: '', // string
19+
};
20+
21+
const collectionUpdateResponse = await client.updateCollection(
22+
walletConnection.ethSigner,
23+
collectionAddress,
24+
collectionUpdateRequest,
25+
);
26+
27+
console.log(
28+
'collectionUpdateResponse',
29+
JSON.stringify(collectionUpdateResponse, null, 4),
30+
);
31+
} catch (err) {
32+
console.error(err);
33+
process.exit(1);
34+
}
35+
})();

0 commit comments

Comments
 (0)