Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Goerli #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,24 +381,24 @@ To do so, we will use the [Hardhat](https://hardhat.org) development framework w

### Smart Contract Deployment

Now that we have written both our contracts, let's deploy them to the [Rinkeby Testnet](https://rinkeby.etherscan.com). Ensure you have some ETH on the Rinkeby Testnet.
Now that we have written both our contracts, let's deploy them to the [Goerli Testnet](https://goerli.etherscan.io). Ensure you have some ETH on the Goerli Testnet.

- Install the `dotenv` package from NPM to be able to use environment variables specified in `.env` files in the `hardhat.config.js`. Execute the following command in your Terminal in the `hardhat-tutorial` directory.
```bash
npm install dotenv
```
- Now create a `.env` file in the `hardhat-tutorial` directory and set the following two environment variables. Follow the instructions to get their values. Make sure the Rinkeby private key you use is has ETH on the Rinkeby Testnet.
- Now create a `.env` file in the `hardhat-tutorial` directory and set the following two environment variables. Follow the instructions to get their values. Make sure the Goerli private key you use is has ETH on the Goerli Testnet.

```bash
// Go to https://www.alchemyapi.io, sign up, create
// a new App in its dashboard and select the network as Rinkeby, and replace "add-the-alchemy-key-url-here" with its key url
// a new App in its dashboard and select the network as Goerli, and replace "add-the-alchemy-key-url-here" with its key url
ALCHEMY_API_KEY_URL="add-the-alchemy-key-url-here"

// Replace this private key with your RINKEBY account private key
// Replace this private key with your GOERLI account private key
// To export your private key from Metamask, open Metamask and
// go to Account Details > Export Private Key
// Be aware of NEVER putting real Ether into testing accounts
RINKEBY_PRIVATE_KEY="add-the-rinkeby-private-key-here"
GOERLI_PRIVATE_KEY="add-the-goerli-private-key-here"
```

- Now, let's write a deployment script to automatically deploy both our contracts for us. Create a new file, or replace the existing default one, named `deploy.js` under `hardhat-tutorial/scripts`, and add the following code:
Expand Down Expand Up @@ -451,22 +451,22 @@ Now that we have written both our contracts, let's deploy them to the [Rinkeby T
module.exports = { CRYPTODEVS_NFT_CONTRACT_ADDRESS };
```

- Now, let's add the Rinkeby Network to your Hardhat Config so we can deploy to Rinkeby. Open your `hardhat.config.js` file and replace it with the following:
- Now, let's add the Goerli Network to your Hardhat Config so we can deploy to Goerli. Open your `hardhat.config.js` file and replace it with the following:

```javascript
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config({ path: ".env" });

const ALCHEMY_API_KEY_URL = process.env.ALCHEMY_API_KEY_URL;

const RINKEBY_PRIVATE_KEY = process.env.RINKEBY_PRIVATE_KEY;
const GOERLI_PRIVATE_KEY = process.env.GOERLI_PRIVATE_KEY;

module.exports = {
solidity: "0.8.9",
networks: {
rinkeby: {
goerli: {
url: ALCHEMY_API_KEY_URL,
accounts: [RINKEBY_PRIVATE_KEY],
accounts: [GOERLI_PRIVATE_KEY],
},
},
};
Expand All @@ -480,15 +480,15 @@ Now that we have written both our contracts, let's deploy them to the [Rinkeby T

- Let's deploy! Execute the following command in your Terminal from the `hardhat-tutorial` directory
```bash
npx hardhat run scripts/deploy.js --network rinkeby
npx hardhat run scripts/deploy.js --network goerli
```
- Save the `FakeNFTMarketplace` and `CryptoDevsDAO` contract addresses that get printed in your Terminal. You will need those later.

### Frontend Development

Whew! So much coding!

We've successfully developed and deployed our contracts to the Rinkeby Testnet. Now, it's time to build the Frontend interface so users can create and vote on proposals from the website.
We've successfully developed and deployed our contracts to the Goerli Testnet. Now, it's time to build the Frontend interface so users can create and vote on proposals from the website.

To develop the website, we will be using [Next.js](https://nextjs.org/) as we have so far, which is a meta-framework built on top of [React](https://reactjs.org/).

Expand Down Expand Up @@ -792,9 +792,9 @@ To develop the website, we will be using [Next.js](https://nextjs.org/) as we ha
const web3Provider = new providers.Web3Provider(provider);

const { chainId } = await web3Provider.getNetwork();
if (chainId !== 4) {
window.alert("Please switch to the Rinkeby network!");
throw new Error("Please switch to the Rinkeby network");
if (chainId !== 5) {
window.alert("Please switch to the Goerli network!");
throw new Error("Please switch to the Goerli network");
}

if (needSigner) {
Expand Down Expand Up @@ -832,7 +832,7 @@ To develop the website, we will be using [Next.js](https://nextjs.org/) as we ha
useEffect(() => {
if (!walletConnected) {
web3ModalRef.current = new Web3Modal({
network: "rinkeby",
network: "goerli",
providerOptions: {},
disableInjectedProvider: false,
});
Expand Down
6 changes: 3 additions & 3 deletions hardhat-tutorial/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ require("dotenv").config({ path: ".env" });

const ALCHEMY_API_KEY_URL = process.env.ALCHEMY_API_KEY_URL;

const RINKEBY_PRIVATE_KEY = process.env.RINKEBY_PRIVATE_KEY;
const GOERLI_PRIVATE_KEY = process.env.GOERLI_PRIVATE_KEY;

module.exports = {
solidity: "0.8.4",
networks: {
rinkeby: {
goerli: {
url: ALCHEMY_API_KEY_URL,
accounts: [RINKEBY_PRIVATE_KEY],
accounts: [GOERLI_PRIVATE_KEY],
},
},
};
8 changes: 4 additions & 4 deletions my-app/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ export default function Home() {
const web3Provider = new providers.Web3Provider(provider);

const { chainId } = await web3Provider.getNetwork();
if (chainId !== 4) {
window.alert("Please switch to the Rinkeby network!");
throw new Error("Please switch to the Rinkeby network");
if (chainId !== 5) {
window.alert("Please switch to the Goerli network!");
throw new Error("Please switch to the Goerli network");
}

if (needSigner) {
Expand Down Expand Up @@ -213,7 +213,7 @@ export default function Home() {
useEffect(() => {
if (!walletConnected) {
web3ModalRef.current = new Web3Modal({
network: "rinkeby",
network: "goerli",
providerOptions: {},
disableInjectedProvider: false,
});
Expand Down