From 8c1221645d12aea0d48d2e1980e09b265ef0d525 Mon Sep 17 00:00:00 2001 From: Mohammed Date: Mon, 10 Apr 2023 16:54:41 +0100 Subject: [PATCH 1/5] chore: prepare library for npm publish --- index.ts | 29 ----------------------------- package-lock.json | 2 +- package.json | 6 ++++-- src/index.ts | 26 ++++++++++++++++++++++++++ test.ts | 2 +- tsconfig.json | 14 ++++++++------ 6 files changed, 40 insertions(+), 39 deletions(-) delete mode 100644 index.ts create mode 100644 src/index.ts diff --git a/index.ts b/index.ts deleted file mode 100644 index d804ec4..0000000 --- a/index.ts +++ /dev/null @@ -1,29 +0,0 @@ -import * as eth from './src/eth' -import { type NFTOptions, } from './src/models' -import { setIpfsHostnames, setArweaveHostnames } from './src/services' - -async function getERC721(NFTOptions: NFTOptions) { - const NFTs = await eth.getERC721(NFTOptions,); - const result = NFTs.map((nft) => nft.toDict()); - return result; -} - -async function getERC1155(NFTOptions: NFTOptions) { - const NFTs = await eth.getERC1155(NFTOptions,); - const result = NFTs.map((nft) => nft.toDict()); - return result; -} - -async function getEthNFTs(NFTOptions: NFTOptions) { - const NFTs = await eth.getNFTs(NFTOptions,); - const result = NFTs.map((nft) => nft.toDict()); - return result; -} - - -module.exports.setArweaveHostnames = async (hostnames: string[]) => { setArweaveHostnames(hostnames,); } -module.exports.setIpfsHostnames = async (hostnames: string[]) => { setIpfsHostnames(hostnames,); } -module.exports.setEthProvider = async (provider: string) => { eth.setProvider(provider,); } -module.exports.getERC721 = async (options: NFTOptions) => await getERC721(options); -module.exports.getERC1155 = async (options: NFTOptions) => await getERC1155(options); -module.exports.getEthNFTs = async (options: NFTOptions) => await getEthNFTs(options); diff --git a/package-lock.json b/package-lock.json index 57001ae..3c9b9df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "on-chain-nft", + "name": "on-chain-nfts", "version": "1.0.0", "lockfileVersion": 1, "requires": true, diff --git a/package.json b/package.json index 07f30fb..ae955b5 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,11 @@ "name": "on-chain-nfts", "version": "1.0.0", "description": "Get on-chain NFT mints/transfers/burns including their metadata", - "main": "index.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "scripts": { - "test": "ts-node test.ts && exit 1" + "test": "ts-node test.ts && exit 1", + "build": "tsc" }, "repository": { "type": "git", diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..d5c5d7c --- /dev/null +++ b/src/index.ts @@ -0,0 +1,26 @@ +import * as eth from './eth' +import { type NFTOptions, } from './models' +import { setIpfsHostnames, setArweaveHostnames } from './services' + +async function getERC721(NFTOptions: NFTOptions) { + const NFTs = await eth.getERC721(NFTOptions,); + const result = NFTs.map((nft) => nft.toDict()); + return result; +} + +async function getERC1155(NFTOptions: NFTOptions) { + const NFTs = await eth.getERC1155(NFTOptions,); + const result = NFTs.map((nft) => nft.toDict()); + return result; +} + +async function getEthNFTs(NFTOptions: NFTOptions) { + const NFTs = await eth.getNFTs(NFTOptions,); + const result = NFTs.map((nft) => nft.toDict()); + return result; +} + +async function setEthProvider (provider : string){ + eth.setProvider(provider) +} +export { setArweaveHostnames, setIpfsHostnames, setEthProvider, getERC721, getERC1155, getEthNFTs } \ No newline at end of file diff --git a/test.ts b/test.ts index 1d96558..ad89383 100644 --- a/test.ts +++ b/test.ts @@ -1,4 +1,4 @@ -const onChainNFT = require('./index') +const onChainNFT = require('./src/') async function test() { onChainNFT.setEthProvider(process.env.PROVIDER_URL); diff --git a/tsconfig.json b/tsconfig.json index 9499a12..2810e22 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,8 +11,8 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - "lib": ["es6"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + "target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + //"lib": ["es6"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ @@ -25,7 +25,7 @@ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - //"module": "commonjs", /* Specify what module code is generated. */ + "module": "commonjs", /* Specify what module code is generated. */ "rootDir": "src", /* Specify the root folder within your source files. */ "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ @@ -44,12 +44,12 @@ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ /* Emit */ - // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ // "declarationMap": true, /* Create sourcemaps for d.ts files. */ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - "outDir": "build", /* Specify an output folder for all emitted files. */ + "outDir": "dist", /* Specify an output folder for all emitted files. */ // "removeComments": true, /* Disable emitting comments. */ // "noEmit": true, /* Disable emitting files from a compilation. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ @@ -99,5 +99,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + }, + "include": ["src"], + "exclude": ["node_modules", "**/__tests__/*"] } From 7bfeed2ea4e33cd630e90c3f41221c9d025f91bd Mon Sep 17 00:00:00 2001 From: Mohammed Date: Mon, 1 May 2023 15:27:06 +0100 Subject: [PATCH 2/5] chore: add npm only files --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index ae955b5..2d45461 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,9 @@ "description": "Get on-chain NFT mints/transfers/burns including their metadata", "main": "dist/index.js", "types": "dist/index.d.ts", + "files": [ + "dist/**/*" + ], "scripts": { "test": "ts-node test.ts && exit 1", "build": "tsc" From 31df23a7e7cf6fe0ed0bf3caf2c1415f9d97de32 Mon Sep 17 00:00:00 2001 From: Mohammed Date: Mon, 1 May 2023 15:57:54 +0100 Subject: [PATCH 3/5] chore: add npm specific readme --- README.md | 127 ++++++++++++++++++++++++++++++++++---------------- dev/README.md | 53 +++++++++++++++++++++ package.json | 2 +- 3 files changed, 141 insertions(+), 41 deletions(-) create mode 100644 dev/README.md diff --git a/README.md b/README.md index df01751..72069be 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,100 @@ -## On-chain-nft -Get on-chain NFT mints/transfers/burns including their metadata. Supported metadata formats: -- http/https -- IPFS -- Arweave -- Base64 +Import library -## Dev -Clone the repo ``` -git clone git@github.com:mohammed-almujil/on-chain-nfts.git -cd on-chain-nfts +import * as onChainNFT from 'on-chain-nfts' ``` -Install dependencies +# ETH +Set ETH provider ``` -npm install -npm install -g ts-node +onChainNFT.setEthProvider(process.env.PROVIDER_URL); ``` - -### **Ethereum** - -ETH NFTs +Optionally set IPFS hostnames. More here https://ipfs.github.io/public-gateway-checker/ ``` -const onChainNFT = require('./index') - -onChainNFT.setEthProvider(PROVIDER_URL); - -//All NFTs -const all = await onChainNFT.getEthNFTs({ blockNumber: blockNumber }); - -//ERC-721 NFTs only -const erc721 = await onChainNFT.getERC721({ blockNumber: blockNumber }); - -//ERC-1155 only -const erc1155 = await onChainNFT.getERC1155({ blockNumber: blockNumber }); - +onChainNFT.setIpfsHostnames([ + 'gateway.pinata.cloud', + 'cloudflare-ipfs.com', + 'ipfs-gateway.cloud', + 'gateway.ipfs.io', + '4everland.io', + 'cf-ipfs.com', + 'ipfs.jpu.jp', + 'dweb.link' + ]); ``` - -Optionally set IPFS hostnames. The code will try the hostnames one by one in case of failure. More here https://ipfs.github.io/public-gateway-checker/ +Optionally set Arweave hostnames ``` -onChainNFT.setIpfsHostnames(['gateway.pinata.cloud','cloudflare-ipfs.com']); +onChainNFT.setArweaveHostnames([ + 'arweave.net' + ]); ``` - -Optionally set Arweave hostnames. The code will try the hostnames one by one in case of failure. +Get all NFTs +``` +const result = await onChainNFT.getEthNFTs({ blockNumber: blockNumber }); +``` +Get ERC-721 only +``` +const result = await onChainNFT.getERC721({ blockNumber: blockNumber }); ``` -onChainNFT.setArweaveHostnames(['arweave.net']); +GET ERC-1155 only ``` -### **Tests** +const result = await onChainNFT.getERC1155({ blockNumber: blockNumber }); -Run tests locally, make sure PROVIDER_URL ENV variable is set then run ``` -ts-node test.ts -``` \ No newline at end of file + +Example results +``` +[ + { + "nft_type": "ERC-721", + "tx_type": "TRANSFER", + "block_number": 17166445, + "transaction_hash": "0x2a5a692383fbab5c43b70fe3ff501a80d7e0540b75d2f3d2c9de86ace8f57607", + "chain": "Ethereum", + "from": "0x3bEd6c7Ec492D0d57f68F8c402FB7e2DE51c1165", + "to": "0x743776E5A345fE62d7D85282407c94E616A03176", + "token_contract": "0x32973908FaeE0Bf825A343000fE412ebE56F802A", + "token_id": "4555", + "token_uri": "https://pixelmon.club/api/4555", + "metadata": { + "name": "Pixelmon #4555", + "image_url": "https://pixelmon-training-rewards.s3-accelerate.amazonaws.com/0/Tatsumaki.jpg", + "external_url": "https://pixelmon.club/", + "reward_bitmask": 6, + "attributes": [ + { + "trait_type": "Species", + "value": "Tatsumaki" + }, + ... + ], + "animation_url": "https://pixelmon-training-rewards.s3-accelerate.amazonaws.com/6/Tatsumaki.mp4" + } + }, + { + "nft_type": "ERC-1155", + "tx_type": "TRANSFER", + "block_number": 17166445, + "transaction_hash": "0x2a5a692383fbab5c43b70fe3ff501a80d7e0540b75d2f3d2c9de86ace8f57607", + "chain": "Ethereum", + "from": "0x3bEd6c7Ec492D0d57f68F8c402FB7e2DE51c1165", + "to": "0x000000000000000000000000000000000000dEaD", + "token_contract": "0xADaE0Ddaf90170a44ADEbcFB8eeDE12041D13220", + "token_id": "2", + "token_value": "3", + "token_uri": "https://pixelmon.club/api/serum/meta/2", + "metadata": { + "name": "Tube", + "animation_url": "https://pixelmon.club/serum/tube.mp4", + "image_url": "https://pixelmon.club/serum/tube.png", + "attributes": [ + { + "trait_type": "Evolution Stage", + "value": "E2" + }, + ... + ] + } + } +] +``` + diff --git a/dev/README.md b/dev/README.md new file mode 100644 index 0000000..df01751 --- /dev/null +++ b/dev/README.md @@ -0,0 +1,53 @@ +## On-chain-nft +Get on-chain NFT mints/transfers/burns including their metadata. Supported metadata formats: +- http/https +- IPFS +- Arweave +- Base64 + +## Dev +Clone the repo +``` +git clone git@github.com:mohammed-almujil/on-chain-nfts.git +cd on-chain-nfts +``` +Install dependencies +``` +npm install +npm install -g ts-node +``` + +### **Ethereum** + +ETH NFTs +``` +const onChainNFT = require('./index') + +onChainNFT.setEthProvider(PROVIDER_URL); + +//All NFTs +const all = await onChainNFT.getEthNFTs({ blockNumber: blockNumber }); + +//ERC-721 NFTs only +const erc721 = await onChainNFT.getERC721({ blockNumber: blockNumber }); + +//ERC-1155 only +const erc1155 = await onChainNFT.getERC1155({ blockNumber: blockNumber }); + +``` + +Optionally set IPFS hostnames. The code will try the hostnames one by one in case of failure. More here https://ipfs.github.io/public-gateway-checker/ +``` +onChainNFT.setIpfsHostnames(['gateway.pinata.cloud','cloudflare-ipfs.com']); +``` + +Optionally set Arweave hostnames. The code will try the hostnames one by one in case of failure. +``` +onChainNFT.setArweaveHostnames(['arweave.net']); +``` +### **Tests** + +Run tests locally, make sure PROVIDER_URL ENV variable is set then run +``` +ts-node test.ts +``` \ No newline at end of file diff --git a/package.json b/package.json index 2d45461..72ab2f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "on-chain-nfts", - "version": "1.0.0", + "version": "1.0.1", "description": "Get on-chain NFT mints/transfers/burns including their metadata", "main": "dist/index.js", "types": "dist/index.d.ts", From 8151f4177d13f5a3be665de83e50c9518375d8e8 Mon Sep 17 00:00:00 2001 From: Mohammed Date: Mon, 1 May 2023 16:00:03 +0100 Subject: [PATCH 4/5] chore: improve npm readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 72069be..a6da14e 100644 --- a/README.md +++ b/README.md @@ -29,15 +29,15 @@ onChainNFT.setArweaveHostnames([ ``` Get all NFTs ``` -const result = await onChainNFT.getEthNFTs({ blockNumber: blockNumber }); +const result = await onChainNFT.getEthNFTs({ blockNumber: 17166445 }); ``` Get ERC-721 only ``` -const result = await onChainNFT.getERC721({ blockNumber: blockNumber }); +const result = await onChainNFT.getERC721({ blockNumber: 17166445 }); ``` GET ERC-1155 only ``` -const result = await onChainNFT.getERC1155({ blockNumber: blockNumber }); +const result = await onChainNFT.getERC1155({ blockNumber: 17166445 }); ``` From 521f4123dd27202307dc409ed071c07330aab34b Mon Sep 17 00:00:00 2001 From: Mohammed Date: Mon, 1 May 2023 16:07:34 +0100 Subject: [PATCH 5/5] chore: improve npm and dev readmes --- README.md | 5 +++-- dev/README.md | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a6da14e..f78c7f9 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ -Import library +Get on-chain NFT mints/transfers/burns including their metadata. +# Get started ``` import * as onChainNFT from 'on-chain-nfts' ``` -# ETH +## ETH Set ETH provider ``` onChainNFT.setEthProvider(process.env.PROVIDER_URL); diff --git a/dev/README.md b/dev/README.md index df01751..a10b71b 100644 --- a/dev/README.md +++ b/dev/README.md @@ -50,4 +50,15 @@ onChainNFT.setArweaveHostnames(['arweave.net']); Run tests locally, make sure PROVIDER_URL ENV variable is set then run ``` ts-node test.ts +``` + +### **NPM publishing** + +Build +``` +npm run build +``` +Publish. Only files in the `dist` folder will be pushed +``` +npm publish ``` \ No newline at end of file