How to Deploy

This section will cover how to deploy contracts to the AirDAO network using Hardhat or Foundry project setup.

This tutorial cover both cloning existing project and initializing from scratch.

From Scratch

Hardhat

For hardhat example we use default hardhat template contract.

Install dependencies and initiate project:

npm i hardhat
npx hardhat init

Follow the initialization process and wait for installation process.

Hardhat creates default contract, and we will use it for that example.

Configuration for AIRDAO network:

Open ./hardhat.config.js (or ./hardhat.config.ts) and modify the following parameters

  1. Modify networks:

// Some imports here ...

const YOUR_PRIVATE_KEY = process.env.PRIVATE_KEY

module.exports = {
// Hardhat configuration ...
  networks: {
    devnet: {
      url: "https://network.ambrosus-dev.io",
      accounts: [YOUR_PRIVATE_KEY]
    },
    testnet: {
      url: "https://network.ambrosus-test.io",
      accounts: [YOUR_PRIVATE_KEY]
    },
    mainnet: {
      url: "https://network.ambrosus.io",
      accounts: [YOUR_PRIVATE_KEY]
    }
  },
// Hardhat configuration ...
}
  1. Modify the compiler settings, the evmVersion should be istanbul/petersburg:

module.exports = {
  // Hardhat configuration ...
  solidity: {
    // Solc configuration ...
    // version: "0.8.20",
    settings: {
      evmVersion: "istanbul",
    }
  },
  // Hardhat configuration ...
}
  1. (Optional for verifying contracts) Modify the hardhat-verify parameters (etherscan and sourcify):

// Some imports here ...

module.exports = {
// Hardhat configuration ...
  etherscan: { 
    enabled: false
  },
  sourcify: {
    enabled: true,
    apiUrl: "https://sourcify.ambrosus.io/"
  },
// Hardhat configuration ...
}

Deployment process:

npx hardhat ignition deploy ./ignition/modules/Lock.js --network testnet

Follow the ignition deployment process and the address will be printed to console.

Contract verification:

  1. via explorer

    1. search for deployed address

    2. drag&drop file from artifacts/build-info to explorer verification page in “Contract“ section.

  2. with cmd

hardhat verify <CONTRACT_ADDRESS_TO_VERIFY> --network testnet

Foundry

For the foundry example we will use hello_foundry template.

Initiate project:

forge init hello_foundry
cd ./hello_foundry

Configuration for AIRDAO network:

Modify the foundry.toml file with configuration

evm_version = "Istanbul"

[rpc_endpoints]
devnet = "https://network.ambrosus-dev.io/"
testnet = "https://network.ambrosus-test.io"
mainnet = "https://network.ambrosus.io"

Use --verifier sourcify --verifier-url https://sourcify.ambrosus.io/ --verify when deploying to verify your contracts.

Deployment process:

Once you will be ready with deployment script, run it with --legacy flag and additional values for verification, network and keys (example for script/Counter.s.sol:CounterScript)

forge script -f <devnet|testnet|mainnet> --private-key <YOUR_PRIVATE_KEY> --legacy --broadcast --verifier sourcify --verifier-url https://sourcify.ambrosus.io/ --verify CounterScript

Contract verification:

  1. via explorer

    1. search for deployed address

    2. drag&drop file from out/build-info to explorer verification page in “Contract“ section.

  2. with cmd

forge verify-contract -r <devnet|testnet|mainnet> --verifier sourcify --verifier-url https://sourcify.ambrosus.io/ <CONTRACT_ADDRESS_TO_VERIFY> Counter 

Forking

If you want to fork existing project just fork and edit the configuration.

To deploy this project in AirDAO we didn’t modify any solidity file! All that needed to be done was to write scripts for deployment (since they were not in the repository), and specify our networks in the configuration file (see above)

Foundry

Update the foundry.toml config with EVM version and RPCs like here.

Create deployment script like that:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console} from "forge-std/Script.sol";
import {PolyLend} from "../src/PolyLend.sol";

contract PolyLendScript is Script {
    PolyLend public polyLend;

    function setUp() public {}

    function run() public {
        vm.startBroadcast();

        polyLend = new PolyLend(address(SOME_ADDRESS_HERE), address(ANOTHER_ADDRESS_HERE));

        vm.stopBroadcast();
    }
}

Run the script via CLI:

forge script -f <devnet|testnet|mainnet> --private-key <YOUR_PRIVATE_KEY> --legacy --broadcast --verifier sourcify --verifier-url https://sourcify.ambrosus.io/ --verify PolyLendScript

Hardhat

For completeness purposes, we tried to use hardhat framework with this project.

Update the hardhat.config.[j,t]s config with EVM version and RPCs like here.

Copy project contracts and dependencies to hardhat empty project.

Create hardhat ignition script to deploy contracts:

const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");


module.exports = buildModule("PolyLendModule", (m) => {
  const conditionalTokensAddress = "0x345cA3e014Aaf5dcA488057592ee47305D9B3e10";
  const usdcAddress = "0xB6318deCa7eE555d306d2d3d2a12B98C048234bE";

  const InterestLib = m.library("InterestLib");
  const lock = m.contract(
    "PolyLend",
    [conditionalTokensAddress, usdcAddress],
    { libraries: { InterestLib } }
  );
  return { lock };
});

Then run npx hardhat ignition deploy ./ignition/modules/PolyLend.js --network testnet

Verified contracts

Last updated