Skip to content

Commit

Permalink
Merge pull request #5 from mohammed-almujil/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mohammed-almujil authored Apr 2, 2023
2 parents 03ba6be + 0671d22 commit d893a56
Show file tree
Hide file tree
Showing 14 changed files with 558 additions and 383 deletions.
5 changes: 0 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,5 @@
],
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
"comma-dangle": ["error", "always"],
"semi": [2, "always"],
"quotes": [2, "single", { "avoidEscape": true }]
}
}
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
32 changes: 24 additions & 8 deletions index.ts
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);
114 changes: 57 additions & 57 deletions src/eth/ABI.ts
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, }
Loading

0 comments on commit d893a56

Please sign in to comment.