-
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 #5 from mohammed-almujil/dev
Dev
- Loading branch information
Showing
14 changed files
with
558 additions
and
383 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
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 |
---|---|---|
|
@@ -8,29 +8,46 @@ Get on-chain NFT mints/transfers/burns including their metadata. Supported metad | |
## Dev | ||
Clone the repo | ||
``` | ||
git clone [email protected]:mohammed-almujil/on-chain-nft.git | ||
cd on-chain-nft | ||
git clone [email protected]:mohammed-almujil/on-chain-nfts.git | ||
cd on-chain-nfts | ||
``` | ||
Install dependencies | ||
``` | ||
npm install | ||
npm install -g ts-node | ||
``` | ||
Set ETH provider URL in test.ts | ||
|
||
### **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.setIpfsHostnames(['gateway.pinata.cloud','cloudflare-ipfs.com']); | ||
onChainNFT.setArweaveHostnames(['arweave.net']); | ||
``` | ||
### **Tests** | ||
|
||
Run tests locally | ||
Run tests locally, make sure PROVIDER_URL ENV variable is set then run | ||
``` | ||
ts-node test.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 |
---|---|---|
@@ -1,13 +1,29 @@ | ||
import * as eth from './src/eth' | ||
import { NFTOptions } from './src/models'; | ||
import { type NFTOptions, } from './src/models' | ||
import { setIpfsHostnames, setArweaveHostnames } from './src/services' | ||
|
||
async function getERC721(NFTOptions: NFTOptions) { | ||
let NFTs = await eth.getERC721(NFTOptions) | ||
const result = NFTs.map((nft) => nft.toDict()); | ||
return result | ||
const NFTs = await eth.getERC721(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); | ||
|
||
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); |
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,62 +1,62 @@ | ||
import { AbiItem } from 'web3-utils' | ||
|
||
|
||
const ERC721Transfer = [{ | ||
type: 'address', | ||
name: 'from', | ||
indexed: true, | ||
}, { | ||
type: 'address', | ||
name: 'to', | ||
indexed: true, | ||
}, { | ||
type: 'uint256', | ||
name: 'tokenId', | ||
indexed: true, | ||
}, | ||
]; | ||
|
||
const ERC721TokenURI: AbiItem= | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: 'uint256', | ||
name: 'tokenId', | ||
type: 'uint256' | ||
} | ||
], | ||
import { type AbiItem } from 'web3-utils' | ||
const ERC721Transfer = [ | ||
{ type: 'address', name: 'from', indexed: true }, | ||
{ type: 'address', name: 'to', indexed: true }, | ||
{ type: 'uint256', name: 'tokenId', indexed: true } | ||
] | ||
const ERC721: AbiItem[] = [ | ||
{ | ||
constant: true, | ||
inputs: [{ name: '_tokenId', type: 'uint256' }], | ||
name: 'tokenURI', | ||
outputs: [ | ||
{ | ||
internalType: 'string', | ||
name: '', | ||
type: 'string' | ||
} | ||
], | ||
outputs: [{ name: '', type: 'string' }], | ||
payable: false, | ||
stateMutability: 'view', | ||
type: 'function' | ||
}; | ||
} | ||
] | ||
const ERC1155TransferSingle = [ | ||
{ type: 'address', name: 'operator', indexed: true }, | ||
{ type: 'address', name: 'from', indexed: true }, | ||
{ type: 'address', name: 'to', indexed: true }, | ||
{ type: 'uint256', name: 'id' }, | ||
{ type: 'uint256', name: 'value' } | ||
] | ||
|
||
const ERC721: AbiItem[]= [ | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"name": "_tokenId", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "tokenURI", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function", | ||
}] | ||
; | ||
const ERC1155TransferMulti = [ | ||
{ type: 'address', name: 'operator', indexed: true }, | ||
{ type: 'address', name: 'from', indexed: true }, | ||
{ type: 'address', name: 'to', indexed: true }, | ||
{ type: 'uint256[]', name: 'ids' }, | ||
{ type: 'uint256[]', name: 'values' } | ||
] | ||
|
||
export { ERC721TokenURI, ERC721Transfer, ERC721 }; | ||
const ERC1155: AbiItem[] = [ | ||
{ | ||
inputs: [{ internalType: 'uint256', name: 'id', type: 'uint256' }], | ||
name: 'uri', | ||
outputs: [{ internalType: 'string', name: '', type: 'string' }], | ||
stateMutability: 'view', | ||
type: 'function' | ||
}, | ||
{ | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
indexed: false, | ||
internalType: "string", | ||
name: "value", | ||
type: "string" | ||
}, | ||
{ | ||
indexed: true, | ||
internalType: "uint256", | ||
name: "id", | ||
type: "uint256" | ||
} | ||
], | ||
name: "URI", | ||
type: "event" | ||
} | ||
] | ||
export { ERC721Transfer, ERC721, ERC1155TransferSingle, ERC1155TransferMulti, ERC1155, } |
Oops, something went wrong.