-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FetchWrapper (Node & non-React support) (#46)
FetchWrapper is a class that allows to use the library with other frontend libraries than React, or with NodeJS. Unline the `useNft()` hook, `FetchWrapper#fetchNft()` does not retry, cache, or do anything else than attempting to fetch the NFT data once.
- Loading branch information
Showing
11 changed files
with
10,251 additions
and
7 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
.yarn/ |
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,23 @@ | ||
const ethers = require("ethers") | ||
const FetchWrapper = require("use-nft").FetchWrapper | ||
|
||
// nodejs does not have a fetch function, set it here | ||
// not required for applications that run in a browser | ||
const fetch = require("node-fetch") | ||
if (!globalThis.fetch) { | ||
globalThis.fetch = fetch | ||
} | ||
|
||
const fetchNfts = async () => { | ||
const fetcher = ["ethers", { ethers, provider: ethers.getDefaultProvider() }] | ||
const fetchWrapper = new FetchWrapper(fetcher) | ||
|
||
const nft = await fetchWrapper.fetchNft( | ||
"0xd07dc4262bcdbf85190c01c996b4c06a461d2430", | ||
"90473" | ||
) | ||
|
||
console.log(nft) | ||
} | ||
|
||
fetchNfts() |
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,29 @@ | ||
{ | ||
"name": "fetchwrapper", | ||
"version": "1.0.0", | ||
"description": "Example for FetchWrapper", | ||
"main": "index.js", | ||
"scripts": { | ||
"dev": "esnext run index.js --watch", | ||
"build": "esnext build index.js dist/index.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/spectrexyz/use-nft.git" | ||
}, | ||
"author": "Daniel Gretzke", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/spectrexyz/use-nft/issues" | ||
}, | ||
"homepage": "https://github.com/spectrexyz/use-nft#readme", | ||
"dependencies": { | ||
"ethers": "^5.1.3", | ||
"node-fetch": "^2.6.1", | ||
"use-nft": "portal:../.." | ||
}, | ||
"devDependencies": { | ||
"esnext-scripts": "^2.1.1", | ||
"nodemon": "^2.0.7" | ||
} | ||
} |
Oops, something went wrong.