-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…2181) Co-authored-by: Hiep Doan <[email protected]>
- Loading branch information
1 parent
6fe5428
commit c94d48d
Showing
24 changed files
with
425 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# yarn v2 | ||
.yarn | ||
.pnp.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,23 @@ | ||
# Coming Soon™ | ||
# Blockchain Data API Examples | ||
|
||
These examples demonstrate ways of implementing the methods exposed by the blockchainData package of `@imtbl/sdk`, in order to interact with Immutable's [Blockchain Data APIs](https://docs.immutable.com/products/zkEVM/blockchain-data). | ||
|
||
Immutable's Blockchain Data APIs index on-chain state changes and off-chain metadata to allow developers to efficiently retrieve information from Immutable's rollups. | ||
|
||
## Getting Started | ||
|
||
Pre-requisites: | ||
|
||
- Node.js 20.0.0 or higher | ||
|
||
Install dependencies: | ||
|
||
```bash | ||
yarn install | ||
``` | ||
|
||
Test the examples: | ||
|
||
```bash | ||
yarn test | ||
``` |
19 changes: 19 additions & 0 deletions
19
examples/blockchain-data/api-examples-with-node/exported-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { blockchainData, config } from '@imtbl/sdk'; | ||
|
||
const configuration: blockchainData.BlockchainDataModuleConfiguration = { | ||
baseConfig: new config.ImmutableConfiguration({ | ||
environment: config.Environment.PRODUCTION, | ||
}), | ||
}; | ||
|
||
const client = new blockchainData.BlockchainData(configuration); | ||
|
||
export async function getChains( | ||
request: blockchainData.Types.ListChainsRequestParams, | ||
): Promise<blockchainData.Types.Chain> { | ||
const chains: blockchainData.Types.ListChainsResult = await client.listChains( | ||
request, | ||
); | ||
|
||
return chains.result[0]; // type inference, autocomplete works here for `Chain` object | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/blockchain-data/api-examples-with-node/get-collection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 getCollection( | ||
contractAddress: string, | ||
): Promise<blockchainData.Types.GetCollectionResult> { | ||
return await client.getCollection({ | ||
chainName: 'imtbl-zkevm-testnet', | ||
contractAddress, | ||
}); | ||
}; |
14 changes: 14 additions & 0 deletions
14
examples/blockchain-data/api-examples-with-node/get-metadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 getMetadata( | ||
chainName: string, | ||
contractAddress: string, | ||
metadataId: string | ||
): Promise<blockchainData.Types.GetMetadataResult> { | ||
return await client.getMetadata({ | ||
chainName, | ||
contractAddress, | ||
metadataId, | ||
}); | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/blockchain-data/api-examples-with-node/get-nft.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { blockchainData } from "@imtbl/sdk"; | ||
import { client } from "../lib"; | ||
|
||
export async function getNFT(chainName: string, contractAddress: string, tokenId: string): Promise<blockchainData.Types.GetNFTResult> { | ||
return await client.getNFT({ | ||
chainName: chainName, | ||
contractAddress: contractAddress, | ||
tokenId: tokenId, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { verifySuccessfulMints } from "./verify-successful-mints"; | ||
import { getChains } from "./exported-types"; | ||
import { getCollection } from "./get-collection"; | ||
import { getMetadata } from "./get-metadata"; | ||
import { getNFT } from "./get-nft"; | ||
import { listMetadata } from "./list-metadata"; | ||
import { listCollections } from "./list-collections"; | ||
import { listCollectionsByNFTOwner } from "./list-collections-by-owner"; | ||
import { listActivities } from "./list-activities"; | ||
import { listNFTsByAccountAddress } from "./list-nfts-by-account-address"; | ||
import { refreshNFTMetadata } from "./refresh-nft-metadata"; | ||
import { refreshStackedMetadata } from "./refresh-stacked-metadata"; | ||
|
||
export { | ||
verifySuccessfulMints, | ||
getChains, | ||
getCollection, | ||
getMetadata, | ||
getNFT, | ||
listMetadata, | ||
listCollections, | ||
listCollectionsByNFTOwner, | ||
listActivities, | ||
listNFTsByAccountAddress, | ||
refreshNFTMetadata, | ||
refreshStackedMetadata, | ||
}; |
14 changes: 14 additions & 0 deletions
14
examples/blockchain-data/api-examples-with-node/list-activities.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 listActivities( | ||
chainName: string, | ||
contractAddress: string, | ||
pageSize: number | ||
): Promise<blockchainData.Types.ListActivitiesResult> { | ||
return await client.listActivities({ | ||
chainName, | ||
contractAddress, | ||
pageSize, | ||
}); | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/blockchain-data/api-examples-with-node/list-collections-by-owner.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 listCollectionsByNFTOwner( | ||
chainName: string, | ||
accountAddress: string | ||
): Promise<blockchainData.Types.ListCollectionsResult> { | ||
return await client.listCollectionsByNFTOwner({ | ||
chainName, | ||
accountAddress, | ||
}); | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/blockchain-data/api-examples-with-node/list-collections.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { blockchainData } from "@imtbl/sdk"; | ||
import { client } from "../lib"; | ||
|
||
export async function listCollections( | ||
chainName: string | ||
): Promise<blockchainData.Types.ListCollectionsResult> { | ||
return await client.listCollections({ | ||
chainName, | ||
}); | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/blockchain-data/api-examples-with-node/list-metadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 listMetadata( | ||
chainName: string, | ||
contractAddress: string | ||
): Promise<blockchainData.Types.ListMetadataResult> { | ||
return await client.listNFTMetadataByContractAddress({ | ||
chainName, | ||
contractAddress, | ||
}); | ||
} |
14 changes: 14 additions & 0 deletions
14
examples/blockchain-data/api-examples-with-node/list-nfts-by-account-address.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 listNFTsByAccountAddress( | ||
chainName: string, | ||
contractAddress: string, | ||
accountAddress: string, | ||
): Promise<blockchainData.Types.ListNFTsResult> { | ||
return await client.listNFTsByAccountAddress({ | ||
chainName, | ||
contractAddress, | ||
accountAddress, | ||
}); | ||
}; |
34 changes: 34 additions & 0 deletions
34
examples/blockchain-data/api-examples-with-node/refresh-nft-metadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { blockchainData } from "@imtbl/sdk"; | ||
import { client } from "../lib"; | ||
|
||
export async function refreshNFTMetadata( | ||
chainName: string, | ||
contractAddress: string, | ||
newName: string | ||
): Promise<blockchainData.Types.MetadataRefreshRateLimitResult> { | ||
const nftMetadata: blockchainData.Types.RefreshMetadataByTokenID[] = [ | ||
{ | ||
name: newName, | ||
animation_url: null, | ||
image: null, | ||
external_url: null, | ||
youtube_url: null, | ||
description: null, | ||
attributes: [ | ||
{ | ||
trait_type: 'Power', | ||
value: 'Happy', | ||
}, | ||
], | ||
token_id: '1', | ||
}, | ||
]; | ||
|
||
return await client.refreshNFTMetadata({ | ||
chainName, | ||
contractAddress, | ||
refreshNFTMetadataByTokenIDRequest: { | ||
nft_metadata: nftMetadata, | ||
}, | ||
}); | ||
}; |
27 changes: 27 additions & 0 deletions
27
examples/blockchain-data/api-examples-with-node/refresh-stacked-metadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { blockchainData } from '@imtbl/sdk'; | ||
import { client } from '../lib'; | ||
|
||
export async function refreshStackedMetadata( | ||
chainName: string, | ||
contractAddress: string, | ||
newName: string | ||
): Promise<blockchainData.Types.MetadataRefreshRateLimitResult> { | ||
return await client.refreshStackedMetadata({ | ||
chainName, | ||
contractAddress, | ||
refreshMetadataByIDRequest: { | ||
metadata: [ | ||
{ | ||
name: newName, | ||
animation_url: null, | ||
image: null, | ||
external_url: null, | ||
youtube_url: null, | ||
description: null, | ||
attributes: [], | ||
metadata_id: '1', | ||
}, | ||
], | ||
}, | ||
}); | ||
}; |
12 changes: 12 additions & 0 deletions
12
examples/blockchain-data/api-examples-with-node/setup-with-api-key.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { config, blockchainData } from '@imtbl/sdk'; | ||
|
||
const API_KEY = 'YOUR_API_KEY'; | ||
const PUBLISHABLE_KEY = 'YOUR_PUBLISHABLE_KEY'; | ||
|
||
const client = new blockchainData.BlockchainData({ | ||
baseConfig: { | ||
environment: config.Environment.PRODUCTION, | ||
apiKey: API_KEY, | ||
publishableKey: PUBLISHABLE_KEY, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { config, blockchainData } from '@imtbl/sdk'; | ||
|
||
const PUBLISHABLE_KEY = 'YOUR_PUBLISHABLE_KEY'; // Replace with your Publishable Key from the Immutable Hub | ||
|
||
const client = new blockchainData.BlockchainData({ | ||
baseConfig: { | ||
environment: config.Environment.PRODUCTION, | ||
publishableKey: PUBLISHABLE_KEY, | ||
}, | ||
}); |
12 changes: 12 additions & 0 deletions
12
examples/blockchain-data/api-examples-with-node/verify-successful-mints.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 verifySuccessfulMints( | ||
contractAddress: string, | ||
): Promise<blockchainData.Types.ListActivitiesResult> { | ||
return await client.listActivities({ | ||
chainName: 'imtbl-zkevm-testnet', | ||
contractAddress, | ||
activityType: blockchainData.Types.ActivityType.Mint, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} **/ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+.tsx?$': ['ts-jest', {}], | ||
}, | ||
setupFiles: ['dotenv/config'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { config as immutableConfig, blockchainData } from '@imtbl/sdk'; | ||
|
||
export const config: blockchainData.BlockchainDataModuleConfiguration = { | ||
baseConfig: { | ||
environment: immutableConfig.Environment.SANDBOX, | ||
apiKey: process.env.API_KEY, | ||
publishableKey: process.env.PUBLISHABLE_KEY, | ||
}, | ||
}; | ||
|
||
export const client = new blockchainData.BlockchainData(config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { client } from './client'; | ||
|
||
export { client }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "blockchain-data-api-examples", | ||
"version": "1.0.0", | ||
"description": "Code examples for interacting with the Blockchain Data API package of @imtbl/sdk", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@imtbl/sdk": "latest" | ||
}, | ||
"devDependencies": { | ||
"@jest/globals": "^29.7.0", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.2.5", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5" | ||
} | ||
} |
Oops, something went wrong.