-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from mohammed-almujil/dev
NPM publishing
- Loading branch information
Showing
8 changed files
with
196 additions
and
80 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 |
---|---|---|
@@ -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" | ||
}, | ||
... | ||
] | ||
} | ||
} | ||
] | ||
``` | ||
|
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,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 | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,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 } |
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
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