Skip to content

bfortuner/hardhat-basics

Repository files navigation

Hardhat Hackathon Boilerplate

This repository contains a sample project that you can use as the starting point for your Ethereum project. It's also a great fit for learning the basics of smart contract development.

This project is intended to be used with the Hardhat Beginners Tutorial, but you should be able to follow it by yourself by reading the README and exploring its contracts, tests, scripts and frontend directories. Hardhat documentation.

Quick start

The first things you need to do are cloning this repository and installing its dependencies:

git clone https://github.com/nomiclabs/hardhat-hackathon-boilerplate.git
cd hardhat-hackathon-boilerplate
npm install

Once installed, let's run Hardhat's testing network:

npx hardhat node

Then, on a new terminal, go to the repository's root folder and run this to deploy your contract:

npx hardhat run scripts/deploy.js --network localhost

Finally, we can run the frontend with:

cd frontend
npm install
npm start

Note: There's an issue in ganache-core that can make the npm install step fail.

If you see npm ERR! code ENOLOCAL, try running npm ci instead of npm install.

Open http://localhost:3000/ to see your Dapp. You will need to have Metamask installed and listening to localhost 8545.

User Guide

You can find detailed instructions on using this repository and many tips in its documentation.

For a complete introduction to Hardhat, refer to this guide.

What’s Included?

Your environment will have everything you need to build a Dapp powered by Hardhat and React.

Troubleshooting

  • Invalid nonce errors: if you are seeing this error on the npx hardhat node console, try resetting your Metamask account. This will reset the account's transaction history and also the nonce. Open Metamask, click on your account followed by Settings > Advanced > Reset Account.

Notes

For local tests and localhost node, Hardhat determins the deployer/owner address. For ropsten, it uses your real MetaMask wallet account address you provide in .env.

# Compile contracts
npx hardhat compile

# Default HardHat Network
npx hardhat test

# Ganache Network (Make sure your Ganache node isn't running)
npx hardhat --network ganache test

# Spin up the local network
npx hardhat node --network localhost

# Spin up the console for testing again localhost
npx hardhat console --network localhost

# Deploy the contract
npx hardhat run scripts/deploy.js --network [ropsten|localhost]

# Send some money to the contract
npx hardhat --network [ropsten|localhost] faucet <YOUR_METAMASK_ADDRESS>

# For Ropsten, check your contract on Metamask
https://ropsten.etherscan.io/tx/0xcfcfe5bafb8acece04a42a78708dcdf1809c2cfd1a50f878d04232588bbdd8db

# Note the UI hardcodes the network_id / chain_id
ropsten = 3
localhost = 1337
let token = await ethers.getContractAt("Token", contractAddress);
await token.owner();
// https://mikemcl.github.io/bignumber.js/
(await token.totalSupply()).toNumber();  // Might overflow if converted to JS number
(await token.balanceOf("0xe3ab88afc9e121ef423cdd8410a36aeb2e769bef")).toNumber();

Kill server if it's stuck

lsof -i :8545
kill <PID>

Deployment

DANGER: If you push change to main branch, and vercel will deploy automatically

Faucet

Ropsten Faucet

ECR-20 Tokens

Solidity

Latest Deployment

Deploying the contracts with the account: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 Account balance: 10000000000000000000000 Token address: 0x5FbDB2315678afecb367f032d93F642f64180aa3

NFT - ERC721

Commands

# Deploy
npx hardhat run scripts/deploy-game-item-erc721.js --network localhost

Contracts

IPFS

Using Pinata for upload

Metadata

{
  "name": "Shield",
  "description": "Protective equipment",
  "image": "https://gateway.pinata.cloud/ipfs/QmdVoXheRz1tjTnUfxx3HBS6rzZkvQxuNfARyKgtPcWzZo/Screen%20Shot%202021-03-04%20at%202.07.15%20PM.png",
  "attributes": [
    {
      "trait_type": "Base", 
      "value": "Metal"
    },
    {
      "display_type": "boost_percentage", 
      "trait_type": "Defense Increase", 
      "value": 10
    }, 
}

View the items

Shield1 Metadata https://gateway.pinata.cloud/ipfs/QmdUEtnLR8jiqrqhAmXmBcmMWemvFTPbvv6BqRM1uJ4VNY/shield1_metadata.json

How to get the Global Token Id from the wners token map

let userGlobalTokenId; let userTokenURI; userGlobalTokenId = await token.tokenOfOwnerByIndex(addr1.address, 0); userTokenURI = await token.tokenURI(userGlobalTokenId);

About

Playing with Solidity and Hardhat

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published