Skip to content

tiagobndr/pba-workshop-dapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

react-solidity-hardhat template

This template sets up a combination of Solidity smart contracts and a React front-end app that interacts with these smart contracts.
This template includes:

The project is configured to deploy on "Passet Hub" network

Setting up environment

First, set up Metamask wallet for Passet Hub network, and get some PAS there. (docs)
In contracts directory, set up private key for hardhat:

npx hardhat vars set PRIVATE_KEY "INSERT_PRIVATE_KEY"

How to export private key from Metamask wallet

1. Writing smart contracts

Contracts are written in contracts/contracts. Each smart contract has a Hardhat Ignition module counterpart in contracts/igniton/modules. More on that in Hardhat Ignition docs.

  1. Edit smart contracts in contracts/contracts
  2. Edit ignition module in contracts/igniton/modules
  3. Run npx hardhat compile to compile smart contracts
  4. Run npx hardhat ignition deploy ./ignition/modules/<ModuleName>.ts --network polkadotHubTestnet to deploy them

Note on committing ignition/deployments

This is a directory that contains build and deployment artifacts from hardhat. They aren't ignored, becuase they are used for types generation for frontend: if there's a smart contract already deployed, you may want to keep it in git, so a fresh clone would give you a working frontend.

However, several issues with hardhat are resolved by removing ignition/deployments directory, to start fresh deployment. These issues include:

An unexpected error occurred:

Error: Could not parse row {...
[ MyTokenModule ] reconciliation failed ⛔

The module contains changes to executed futures:
...

In such cases, do rm -rf ignition/deployments, deploy the new contract, and commit the artifacts anew :)

2. Interacting with smart contracts from frontend app

  1. Generate types from deployed smart contracts by running npm run generate in frontend directory
  2. Run npm run dev to start vite environment
  3. You can import contract ABI and deployed addresses from src/generated.ts:
import {
  myTokenModuleMyTokenAddress,
  myTokenModuleMyTokenAbi,
} from "./generated";

const contractAddress = myTokenModuleMyTokenAddress[420420422];
// ...
writeContract({
  address: contractAddress,
  abi: myTokenModuleMyTokenAbi,
  functionName: "mint",
  args: [address, BigInt(amount) * 10n ** BigInt(params.decimals)],
});

More info at:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published