Skip to content

Commit

Permalink
Make Ethers an optional peer dependency (bpierre#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpierre authored Aug 19, 2021
1 parent 5ff1435 commit b9cf832
Show file tree
Hide file tree
Showing 11 changed files with 2,203 additions and 1,624 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ yarn add use-nft
useNft() uses a concept of “fetchers”, in order to provide different ways to retrieve data from Ethereum. If you use the [Ethers](https://github.com/ethers-io/ethers.js) in your app, using `ethersFetcher()` is recommended. Otherwise you can use `ethereumFetcher()`, which only requires a [standard Ethereum provider](https://eips.ethereum.org/EIPS/eip-1193), like the one provided by MetaMask.

```jsx
import { getDefaultProvider, Contract } from "ethers"
import { getDefaultProvider, } from "ethers"
import { NftProvider, useNft } from "use-nft"

// We are using the "ethers" fetcher here.
const ethersConfig = {
ethers: { Contract },
provider: getDefaultProvider("homestead")
provider: getDefaultProvider("homestead"),
}

// Alternatively, you can use the "ethereum" fetcher. Note
Expand Down Expand Up @@ -74,7 +73,10 @@ The useNft() hook requires two arguments: the NFT `contract` address, and its to
The returned value is an object containing information about the loading state:

```tsx
const { status, loading, error, reload, nft } = useNft("0xd07dc4262bcdbf85190c01c996b4c06a461d2430", "90473")
const { status, loading, error, reload, nft } = useNft(
"0xd07dc4262bcdbf85190c01c996b4c06a461d2430",
"90473"
)

// one of "error", "loading" and "done"
status
Expand Down Expand Up @@ -141,20 +143,27 @@ NftProvider requires a prop to be passed: `fetcher`. It can take a declaration f
##### With Ethers.js
Make sure to add either `ethers` or `@ethersproject/contracts` to your app:
```console
yarn add ethers
```
Then:
```tsx
<NftProvider fetcher={["ethers", { ethers, provider }]} />
<NftProvider fetcher={["ethers", { provider }]} />
```
- `ethers` is the default import of the Ethers library (note that only `{ Contract }` is needed, so you can pass this instead).
- `provider` is a [provider](https://docs.ethers.io/v5/api/providers/) from the Ethers library (not to be mistaken with [standard Ethereum providers](https://eips.ethereum.org/EIPS/eip-1193)).
Where `provider` is a [provider](https://docs.ethers.io/v5/api/providers/) from the [Ethers](https://docs.ethers.io/) library (not to be mistaken with [standard Ethereum providers](https://eips.ethereum.org/EIPS/eip-1193)).
##### With an Ethereum provider
```tsx
<NftProvider fetcher={["ethereum", { ethereum }]} />
```
`ethereum` is a [standard Ethereum providers](https://eips.ethereum.org/EIPS/eip-1193).
Where `ethereum` is a [standard Ethereum provider](https://eips.ethereum.org/EIPS/eip-1193).
##### Custom fetcher
Expand Down Expand Up @@ -222,7 +231,7 @@ Pass the fetcher declaration to the `FetchWrapper` and call the `fetchNft` funct

```js
// See the documentation for <NftProvider /> fetcher prop
const fetcher = ["ethers", { ethers, provider: ethers.getDefaultProvider() }]
const fetcher = ["ethers", { provider: ethers.getDefaultProvider() }]

const fetchWrapper = new FetchWrapper(fetcher)

Expand Down
Loading

0 comments on commit b9cf832

Please sign in to comment.