Skip to content

Commit

Permalink
Merge pull request #6 from mohammed-almujil/chore/prepare-library-for…
Browse files Browse the repository at this point in the history
…-npm

Prepare library for npm publishing
  • Loading branch information
mohammed-almujil authored May 1, 2023
2 parents 0671d22 + 521f412 commit 8b1f047
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 80 deletions.
128 changes: 88 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,101 @@
## On-chain-nft
Get on-chain NFT mints/transfers/burns including their metadata. Supported metadata formats:
- http/https
- IPFS
- Arweave
- Base64
Get on-chain NFT mints/transfers/burns including their metadata.

## Dev
Clone the repo
# Get started
```
git clone [email protected]: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: 17166445 });
```
Get ERC-721 only
```
const result = await onChainNFT.getERC721({ blockNumber: 17166445 });
```
onChainNFT.setArweaveHostnames(['arweave.net']);
GET ERC-1155 only
```
### **Tests**
const result = await onChainNFT.getERC1155({ blockNumber: 17166445 });
Run tests locally, make sure PROVIDER_URL ENV variable is set then run
```
ts-node test.ts
```

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"
},
...
]
}
}
]
```

64 changes: 64 additions & 0 deletions dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## 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 [email protected]: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
```

### **NPM publishing**

Build
```
npm run build
```
Publish. Only files in the `dist` folder will be pushed
```
npm publish
```
29 changes: 0 additions & 29 deletions index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"name": "on-chain-nfts",
"version": "1.0.0",
"version": "1.0.1",
"description": "Get on-chain NFT mints/transfers/burns including their metadata",
"main": "index.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/**/*"
],
"scripts": {
"test": "ts-node test.ts && exit 1"
"test": "ts-node test.ts && exit 1",
"build": "tsc"
},
"repository": {
"type": "git",
Expand Down
26 changes: 26 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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 }
2 changes: 1 addition & 1 deletion test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const onChainNFT = require('./index')
const onChainNFT = require('./src/')

async function test() {
onChainNFT.setEthProvider(process.env.PROVIDER_URL);
Expand Down
14 changes: 8 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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. */
Expand All @@ -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. */
Expand Down Expand Up @@ -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__/*"]
}

0 comments on commit 8b1f047

Please sign in to comment.