-
Notifications
You must be signed in to change notification settings - Fork 0
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 #13 from getsafle/feature-multichain-nft-detection
Updated the SDK to enable multichain NFT discovery
- Loading branch information
Showing
6 changed files
with
78 additions
and
42 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 |
---|---|---|
@@ -1,33 +1,47 @@ | ||
# **Safle NFT Controller** | ||
|
||
Safle NFT Controller SDK | ||
This library enables the developer to detect Non Fungible Tokens (NFT) for any public address across the supported chains. | ||
|
||
<br> | ||
|
||
## **Installation and Usage** | ||
|
||
> Installation | ||
Install the package by running the command, | ||
|
||
`npm install @getsafle/nft-controller` | ||
```sh | ||
npm install @getsafle/nft-controller | ||
``` | ||
|
||
Import the package into your project using, | ||
|
||
`const safleNftController = require('@getsafle/nft-controller');` | ||
```js | ||
const safleNftController = require('@getsafle/nft-controller'); | ||
``` | ||
|
||
## **NFT Controller** | ||
<br> | ||
|
||
> Initialising | ||
## Initialization | ||
|
||
<br> | ||
|
||
Initialise the class using, | ||
|
||
`const nftController = new safleNftController.NftController();` | ||
|
||
> Methods | ||
<br> | ||
|
||
## Methods | ||
|
||
<br> | ||
|
||
> Discover the NFTs and get their details | ||
Get user nft details | ||
```js | ||
const nfts = await nftController.detectNFTs(publicAddress, chain); | ||
``` | ||
|
||
`const nftDetails = await nftController.getNftDetails(publicAddress, contractAddress);` | ||
* `publicAddress` - Public address to detect NFTs. | ||
* `chain` (optional) - Optional chain parameter to detect the NFTs. Supported chains : `Ethereum`, `Polygon` and `BSC`. | ||
|
||
* `publicAddress` - user wallet public address, | ||
* `contractAddress` - NFT contract address |
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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
module.exports = { | ||
OPENSEA_BASE_URL: 'https://api.opensea.io/api/v1', | ||
OPENSEA_API_KEY: '', | ||
NFT_DETECTION_API: 'https://nft.metafi.codefi.network/accounts', | ||
CHAIN_ID: { | ||
ethereum: 1, | ||
polygon: 137, | ||
bsc: 56, | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,28 +1,25 @@ | ||
const axios = require('axios'); | ||
const { OPENSEA_BASE_URL } = require('../config'); | ||
|
||
const Config = require('../config'); | ||
|
||
async function getRequest({ url, apiKey }) { | ||
async function getRequest(url) { | ||
try { | ||
const response = await axios({ | ||
url, | ||
method: 'GET', | ||
headers: { | ||
'X-API-KEY': apiKey, | ||
}, | ||
}); | ||
const response = await axios.get(url); | ||
|
||
return { response: response.data }; | ||
} catch (error) { | ||
return { error: error.response }; | ||
} | ||
} | ||
|
||
async function getUserNftDataApi({ publicAddress, contractAddress }){ | ||
return `${OPENSEA_BASE_URL}/assets?owner=${publicAddress}&asset_contract_address=${contractAddress}`; | ||
function inputValidator(chain) { | ||
if (!Config.CHAIN_ID[chain.toLowerCase()] && chain !== 'all') { | ||
throw `${chain} chain not supported.` | ||
} | ||
} | ||
|
||
module.exports = { | ||
getRequest, getUserNftDataApi, | ||
getRequest, | ||
inputValidator, | ||
}; | ||
|