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

Commit 6147be2

Browse files
Assets examples (#266)
* Assets examples * linting * linting
1 parent 0122385 commit 6147be2

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

examples/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,20 @@ Update [listTransfers.ts](./listTransfers.ts#L10) the desired fields and then ru
305305
```sh
306306
yarn list-transfers
307307
```
308+
## Get asset
309+
Update [getAsset.ts](./getAsset.ts#L10) the token address and token id and then run
310+
311+
```sh
312+
yarn get-asset
313+
```
314+
315+
## List assets
316+
Update [listAssets.ts](./listAssets.ts#L10) the desired fields and then run
317+
318+
```sh
319+
yarn list-assets
320+
```
321+
308322
## Get user
309323

310324
Update [getUser.ts](./getUser.ts#L10) with the wallet address and then run

examples/getAsset.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ImmutableX, Config, AssetsApiGetAssetRequest } from '@imtbl/core-sdk';
2+
3+
(async () => {
4+
const imxClient = new ImmutableX(Config.SANDBOX);
5+
6+
const assetParams: AssetsApiGetAssetRequest = {
7+
tokenAddress: '', //Address of the ERC721 contract
8+
tokenId: '', //Either ERC721 token ID or internal IMX ID
9+
includeFees: false, //Set flag to include fees associated with the asset
10+
};
11+
12+
try {
13+
const assetResponse = await imxClient.getAsset(assetParams);
14+
15+
console.log('assetResponse', assetResponse);
16+
} catch (error) {
17+
console.error(error);
18+
process.exit(1);
19+
}
20+
})();

examples/listAssets.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {
2+
ImmutableX,
3+
Config,
4+
AssetsApiListAssetsRequest,
5+
} from '@imtbl/core-sdk';
6+
7+
(async () => {
8+
const imxClient = new ImmutableX(Config.SANDBOX);
9+
10+
const assetParams: AssetsApiListAssetsRequest = {
11+
collection: '', // Collection contract address,
12+
name: '', // Name of the asset to search
13+
user: '', // Ethereum address of the user who owns these assets
14+
pageSize: 200, // Page size of the result
15+
auxiliaryFeePercentages: '', // Comma separated string of fee percentages that are to be paired with auxiliary_fee_recipients
16+
auxiliaryFeeRecipients: '', // Comma separated string of fee recipients that are to be paired with auxiliary_fee_percentages
17+
buyOrders: false, //Set flag to true to fetch an array of buy order details with accepted status associated with the asset
18+
cursor: '', // Cursor for pagination
19+
direction: '', // Direction to sort (asc/desc)
20+
includeFees: false, // Set flag to include fees associated with the asset
21+
metadata: '', // URL JSON-encoded metadata filters for these assets. Javascript example: encodeURI(JSON.stringify({'proto':['1147'],'quality':['Meteorite']}))
22+
orderBy: 'name', // Property to sort by | Allowed values: updated_at, name
23+
sellOrders: false, // Set flag to true to fetch an array of sell order details with accepted status associated with the asset
24+
status: 'imx', // Status of these assets | Allowed values: eth, imx, preparing_withdrawal, withdrawable, burned
25+
updatedMaxTimestamp: '', // Maximum timestamp for when these assets were last updated, in ISO 8601 UTC format. Example: '2022-05-27T00:10:22Z'
26+
updatedMinTimestamp: '', // Minimum timestamp for when these assets were last updated, in ISO 8601 UTC format. Example: '2022-05-27T00:10:22Z'
27+
};
28+
29+
try {
30+
const assetResponse = await imxClient.listAssets(assetParams);
31+
32+
console.log('assetResponse', assetResponse);
33+
} catch (error) {
34+
console.error(error);
35+
process.exit(1);
36+
}
37+
})();

examples/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"mint": "ts-node -r dotenv/config mint.ts",
2424
"list-mints": "ts-node -r dotenv/config listMints.ts",
2525
"get-mint": "ts-node -r dotenv/config getMint.ts",
26+
"get-asset": "ts-node -r dotenv/config getAsset.ts",
27+
"list-assets": "ts-node -r dotenv/config listAssets.ts",
2628
"transfer-nfts": "ts-node -r dotenv/config transferNfts.ts",
2729
"transfer-eth": "ts-node -r dotenv/config transferEth.ts",
2830
"transfer-erc20": "ts-node -r dotenv/config transferErc20.ts",

0 commit comments

Comments
 (0)