@@ -42,7 +42,7 @@ airtight using tests in lesson 4. Now we're going use all of this knowledge and
42
42
connect it to a frontend for users to see and interact with.
43
43
44
44
We're going to start where we left off in lesson 4. Open your code editor and
45
- ` cd ` into the ` ** TierNFT** ` project directory.
45
+ ` cd ` into the ** ` TierNFT ` ** project directory.
46
46
47
47
For all things related to our frontend we are going to create a new sub-directory
48
48
within our project's root directory to maintain good practice, keep our code clean,
@@ -151,7 +151,8 @@ of our choice along with some other customisations.
151
151
- ` import { alchemyProvider } from 'wagmi/providers/alchemy'; ` and
152
152
` import { publicProvider } from 'wagmi/providers/public'; ` give us the provider configs
153
153
for the providers we will be using. In our app we are using an ` alchemyProvider ` along
154
- with a fall back ` publicProvider ` .
154
+ with a fall back ` publicProvider ` . A provider allows our application to communicate with
155
+ a blockchain.
155
156
- ` useEffect ` and ` useState ` are react hooks that help us perform side effects and
156
157
capture the state, respectively. More on [ state] ( https://www.freecodecamp.org/news/what-is-state-in-react-explained-with-examples/ )
157
158
and the [ useEffect] ( https://www.freecodecamp.org/news/react-useeffect-absolute-beginners/ ) hook.
@@ -169,7 +170,7 @@ After importing, we create the configurations we need, and create a new instance
169
170
const { chains , provider } = configureChains (
170
171
[chain .polygonMumbai ],
171
172
[
172
- alchemyProvider ({ apiKey: process .env .ALCHEMY_ID }),
173
+ alchemyProvider ({ apiKey: process .env .API_KEY }),
173
174
publicProvider ()
174
175
]
175
176
);
@@ -191,7 +192,14 @@ const wagmiClient = createClient({
191
192
For this application we will continue using the ` mumbai ` testnet. Other chains can
192
193
be added simply using the following syntax: ` chain.chain_name ` .
193
194
For custom providers, like the ` alchemyProvider ` we can pass in our private
194
- ` apiKey ` as well.
195
+ ` apiKey ` as well.
196
+
197
+ Set your API Key in a new file named ` .env ` inside our ` frontend ` directory
198
+ as follows:
199
+
200
+ ``` dotenv
201
+ API_KEY='YOUR-API-KEY-FROM-PROVIDER'
202
+ ```
195
203
196
204
Now we can wrap our application in the ` RainbowKitProvider ` and ` WagmiConfig `
197
205
so that have access to their features throughout our application. Our code should
@@ -360,7 +368,7 @@ import { useEffect, useState } from 'react';
360
368
```
361
369
362
370
- RainbowKit provides us a ready-made ` ConnectButton ` .
363
- - We need to the ` useAccount ` hook from WAGMI to check account connection
371
+ - We need to use the ` useAccount ` hook from WAGMI to check account connection
364
372
and ` useContractRead ` and ` useContractWrite ` to interact with our smart
365
373
contract. We will look into WAGMI and these hooks a little down the line.
366
374
- ` TierABI ` is our contract's Application Binary Interface (ABI). The ABI
@@ -513,11 +521,11 @@ const mintToken = async (e) => {
513
521
```
514
522
515
523
- We pass in ` e ` as an argument so that we can pick the amount of ETH
516
- associated with a particular Tier. This is
517
- - We want to wait for our minting transaction to complete before moving
518
- on to other pieces of code.This is passed to the mint function using the
524
+ associated with a particular Tier. This is passed to the mint function using the
519
525
` recklesslySetUnpreparedOverrides ` override config. Read more about it
520
- [ here] ( https://wagmi.sh/docs/hooks/useContractWrite#override-config ) .
526
+ [ here] ( https://wagmi.sh/docs/hooks/useContractWrite#override-config ) .
527
+ - We want to wait for our minting transaction to complete before moving
528
+ on to other pieces of code so we use ` wait() ` .
521
529
- After minting is processed we log the returned data to ensure the
522
530
success of our transaction.
523
531
- Using ` try...catch ` statements makes our error handling more robust. The
0 commit comments