Diamond Tutorial

1) Clone the hardhat-1-diamond repo from Nick Mudge

git clone [https://github.com/mudgen/diamond-1-hardhat](https://github.com/mudgen/diamond-1-hardhat)

2) Change to the new directory

cd diamond-1-hardhat

3) Install dependencies

npm install

Automatically verify your smatcontracts on etherscan by installing the extension with-

npm install --save-dev @nomiclabs/hardhat-etherscan

4) Edit hardhat.config

  • add Etherscan plugin import to allow for automatic smart contract verification

  • add module exports

    networks: {
    goerli: {
    accounts: ["YOUR_PRIVATE_KEY"]
    etherscan: {
    // Your API key for Etherscan
    // Obtain one at [https://etherscan.io/](https://etherscan.io/)

5) Deploy Diamond

  • Compile code

    npx hardhat compile
  • Deploy Diamond

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

6) Create script for facet deployment

// Deploy facets and set the `facetCuts` variable
console.log('Deploying facets')
const FacetNames = [
// The `facetCuts` variable is the FacetCut[] that contains the functions to add during diamond deployment
const facetCuts = []
for (const FacetName of FacetNames) {
const Facet = await ethers.getContractFactory(FacetName)
const facet = await Facet.deploy()
await facet.deployed()
console.log(`${FacetName} deployed: ${facet.address}`)
facetAddress: facet.address,
action: FacetCutAction.Add,
functionSelectors: getSelectors(facet)

7) Deploy Facet

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

8) Verify Contract

  • Run the following command with your Facet smart contract address:

    npx hardhat verify --network goerli DEPLOYED_CONTRACT_ADDRESS

9) Diamond Cut