U2U Network Documentations
  • Introduction
    • Our Vision
    • Litepaper
      • Overview
        • U2U Network Diagram
        • U2U Network with DEPIN and Web3 Eco System
      • Consensus
  • Services
    • RPC
      • RPC Endpoints
      • Ethereum API Methods
        • eth_blockNumber
        • eth_call
        • eth_chainId
        • eth_estimateGas
        • eth_feeHistory
        • eth_gasPrice
        • eth_getBalance
        • eth_getBlockByHash
        • eth_getBlockByNumber
        • eth_getBlockTransactionCountByHash
        • eth_getBlockTransactionCountByNumber
        • eth_getCode
        • eth_getLogs
        • eth_getProof
        • eth_getStorageAt
        • eth_getTransactionByBlockHashAndIndex
        • eth_getTransactionByBlockNumberAndIndex
        • eth_getTransactionByHash
        • eth_getTransactionCount
        • eth_getTransactionReceipt
        • eth_getUncleByBlockHashAndIndex
        • eth_getUncleByBlockNumberAndIndex
        • eth_getUncleCountByBlockHash
        • eth_getUncleCountByBlockNumber
        • eth_maxPriorityFeePerGas
        • eth_sendRawTransaction
        • eth_subscribe
        • eth_unsubscribe
        • net_version
        • net_listening
        • net_peerCount
        • web3_clientVersion
        • web3_sha3
        • debug_traceTransaction
      • DAG API Methods
        • dag_getEvent
        • dag_getEventPayload
        • dag_getHeads
        • eth_currentEpoch
      • Trace API Methods
        • trace_block
        • trace_get
        • trace_transaction
        • trace_filter
    • Explorer
      • Explorer URLs
      • Explorer API
        • Account
        • Block
        • Contract
        • Logs
        • Stats
        • Token
        • Transaction
      • GraphQL
      • Explorer RPC API
      • Smart Contract Verification
        • Via explorer
        • Via hardhat plugin
      • Testnet Faucet
    • Wallets
      • Metamask
      • Wallet Connect
      • Coinbase Wallet
      • U2U Super App
        • Policy
    • Staking
      • How To Stake?
      • FAQ
    • The Graph
      • Deploy a Graph Node
      • Deploy a Subgraph
    • Bridge
      • Smart Contracts & EOA
    • Oracle
      • Smart Contracts & EOA
  • Network
    • Node Types
    • Requirements
    • Build Dependencies
    • Run Normal Node
      • Mainnet Normal Node
      • Testnet Normal Node
      • Run via Docker
    • Run Validator Node
      • Mainnet Validator Node
      • Testnet Validator Node
    • Run A Local Test Network
    • Troubleshooting
  • SUBNET
    • Overview
    • Subnet Node Type
    • Requirements
    • NFT Digital License
    • Subnet Node Setup
      • Master Node
      • Verifier Node
      • Edge Node CLI
  • For Developers
    • SDK
    • Smart Contract Development
      • What are smart contracts?
      • What is gas?
      • Structure of a smart contract
      • Your first smart contract
      • Test your smart contract
      • Deploy your smart contract
      • Submit your contract to explorer
      • Interact With Your Smart Contract
      • Integrate Your Smart Contract With a Frontend
      • Additional Resources
    • Smart Contract Deployment
      • Deploy with Remix
      • Deploy with Hardhat
Powered by GitBook
On this page
  • Prepare your project
  • Network configuration
  • Deploy!
  • Further
  1. For Developers
  2. Smart Contract Deployment

Deploy with Hardhat

Hardhat consists of different components for editing, compiling, debugging and deploying your smart contracts and dApps.

PreviousDeploy with Remix

Last updated 11 months ago

Prepare your project

Either using existing project or follow these steps to create a new hardhat project:

However in this tutorial, we will use hardhat to scaffold a sample project with these simple steps:

mkdir sample_project
cd sample_project
npm init -y
npm install --save-dev hardhat
npx hardhat init

Then it will appear as follow, please select Create a Typescript project:

888    888                      888 888               888
888    888                      888 888               888
888    888                      888 888               888
8888888888  8888b.  888d888 .d88888 88888b.   8888b.  888888
888    888     "88b 888P"  d88" 888 888 "88b     "88b 888
888    888 .d888888 888    888  888 888  888 .d888888 888
888    888 888  888 888    Y88b 888 888  888 888  888 Y88b.
888    888 "Y888888 888     "Y88888 888  888 "Y888888  "Y888

👷 Welcome to Hardhat v2.17.4 👷‍

? What do you want to do? … 
  Create a JavaScript project
❯ Create a TypeScript project
  Create an empty hardhat.config.js
  Quit

It will ask more questions, just follow them and finish setting up your sample project:

✔ What do you want to do? · Create a TypeScript project
✔ Hardhat project root: · /Users/steven/codekeeper/u2u/sample_project
✔ Do you want to add a .gitignore? (Y/n) · y
✔ Do you want to install this sample project's dependencies with npm (@nomicfoundation/hardhat-toolbox)? (Y/n) · y

Hardhat has scaffolded a project contains Lock contract. Our sample project should contain these folders and files:

contracts/
scripts/
test/
hardhat.config.ts

These are the default paths for a Hardhat project.

  • contracts/ is where the source files for your contracts should be.

  • test/ is where your tests should go.

  • scripts/ is where simple automation scripts go.

Network configuration

In U2U network, we support both:

  • Mainnet Solaris:

    • ChainID: 39

    • RPC URL: https://rpc-mainnet.u2u.xyz/

    • Explorer API URL: https://u2uscan.xyz/api

    • Explorer URL: https://u2uscan.xyz

  • Testnet Nebulas:

    • ChainID: 2484

    • RPC URL: https://rpc-nebulas-testnet.u2u.xyz/

    • Explorer API URL: https://testnet.u2uscan.xyz/api

    • Explorer URL: https://testnet.u2uscan.xyz

Your hardhat.config.js or hardhat.config.ts should look like this:

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
  solidity: "0.8.19",
  networks: {
    solaris: {
      url: 'https://rpc-mainnet.u2u.xyz/',
      accounts: ["YOUR_PRIVATE_KEY"], // it should start with 0x...
    },
    nebulas: {
      url: 'https://rpc-nebulas-testnet.u2u.xyz/',
      accounts: ["YOUR_PRIVATE_KEY"], // it should start with 0x...
    }
  },
  etherscan: {
    apiKey: {
      solaris: "abc", // arbitrary string
      nebulas: "abc", // arbitrary string
    },
    customChains: [
      {
        network: "solaris",
        chainId: 39,
        urls: {
          apiURL: "https://u2uscan.xyz/api",
          browserURL: "https://u2uscan.xyz"
        }
      },
      {
        network: "nebulas",
        chainId: 2484,
        urls: {
          apiURL: "https://testnet.u2uscan.xyz/api",
          browserURL: "https://testnet.u2uscan.xyz"
        }
      },
    ]
  }
};

export default config;

Deploy!

Run below command to run deploy script on U2U Solaris mainnet:

npx hardhat run scripts/deploy.ts --network solaris

Or in U2U Nebulas testnet:

npx hardhat run scripts/deploy.ts --network nebulas

Further

Your basic (hardhat.config.js or hardhat.config.ts) will be configured to the network you are working on, ie. U2U network.

Here we add an RPC url without an apiKey, however some value is still required. You can use any arbitrary string. .

You can verify the contract source code with Hardhat. .

https://hardhat.org/hardhat-runner/docs/guides/project-setup
https://hardhat.org/hardhat-runner/docs/guides/compile-contracts
Hardhat config file
More info
Learn more