BuildSpace

There are roughly 27m software developers in the world. Only 18k of them (0.07%) work on web3 every month. Those 18k engineers have created $2tn in market cap across the top 100 projects. $112m of value per person. Learn web3 development with BuildSpace

Mint Collection

mkdir epic-nfts
cd epic-nfts
npm init -y
npm install --save-dev hardhat
npx hardhat
npm install @openzeppelin/contracts
npx hardhat run scripts/sample-script.js

Compiled 2 Solidity files successfully Deploying a Greeter with greeting: Hello, Hardhat! Greeter deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3

You are using a version of Node.js that is not supported by Hardhat, and it may work incorrectly, or not work at all. Please, make sure you are using a supported version of Node.js. To learn more about which versions of Node.js are supported go to https://hardhat.org/nodejs-versions NOTE. Using node -v to learn I'm on v17.0.1

Boom! I Our local environment is set up and we also ran/deployed a smart contract to a local blockchain. Basically what's happening here step-by-step is:

  1. Hardhat compiles your smart contract from solidity to bytecode.

  2. Hardhat will spin up a "local blockchain" on your computer. It's like a mini, test version of Ethereum running on your computer to help you quickly test stuff!

  3. Hardhat will then "deploy" your compiled contract to your local blockchain. That's that address you see at the end there. It's our deployed contract, on our mini version of Ethereum.

If you're curious, feel free to look at the code inside the project to see how it works. Specifically, check out Greeter.sol which is the smart contract and sample-script.js which actually runs the contract.

Don't use VSCode's terminal, use your own separate terminal! Sometimes the VSCode terminal gives issues if the compiler isn't set.

contract

// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.1;

import "hardhat/console.sol";

contract MyEpicNFT {
    constructor() {
        console.log("This is my NFT contract. Whoa!");
    }
}

script

const main = async () => {
  const nftContractFactory = await hre.ethers.getContractFactory('MyEpicNFT');
  const nftContract = await nftContractFactory.deploy();
  await nftContract.deployed();
  console.log("Contract deployed to:", nftContract.address);
};

const runMain = async () => {
  try {
    await main();
    process.exit(0);
  } catch (error) {
    console.log(error);
    process.exit(1);
  }
};

runMain();

Run it

npx hardhat run scripts/run.js

Compiled 2 Solidity files successfully Living the Web3 Life. Good Vibes! Contract deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3

Last updated