XR One
  • Welcome
    • Introduction to XR One
      • Vision
      • About the XR One Network
        • Paint Points
        • The Future is DeMoN
          • DeMoN: A Decentralized Modular Network Whitepaper
    • Important Links
  • Technology
    • XR One
      • Architecture
        • Arbitrum Orbit
        • AnyTrust
          • Data Availability Committee (DAC)
        • RaaS
        • Accounts
          • Account Abstraction
          • Multi-Party Computation
        • Bridge
      • Partners
    • XR One Products
      • NFT Avatars
      • On-chain names
      • Marketplaces
      • On-chain tournaments
      • $XR1 liquidity mining
      • Faustian
    • Nodes
      • Hero Nodes
      • What are Hero Nodes?
      • What are Node Sales?
      • What Makes the Hero Node sale Different
      • Sale Structure
      • XR Airdrop for Node Holders
      • Daily rewards
    • Security
      • Audits
      • Bug Bounty
      • Sequencer Decentralization
      • Multi-Sig Operations
      • Withdrawal Delay
    • Roadmap
  • Tokenomics
    • $XR Token
      • Utility
      • Hero Node Pricing Tiers
    • Token Distribution
    • Emission Schedule
  • Ecosystem
    • Games
      • Saltwater Games
        • Celeros
        • Resurgence
        • Freerunner
    • Agentic AI
      • MySidekick
        • $SKICK
    • Native Tooling
      • Faustian
    • The XR Foundation
      • Constitution
      • ByLaws
      • Amended and Restated Articles of Association of the XR Foundation
      • Foundation Grants
      • DAO Governance
      • Stakeholders
  • Connect
    • XR Sepolia (Testnet)
      • tXR Token
      • Add XR Sepolia to Wallet
      • Bridge to XR Sepolia
      • XR Sepolia Block Explorer
      • XR Sepolia Analytics
    • XR One (Mainnet)
  • Deploy
    • Deploy to XR Sepolia
      • Using Foundry
      • Using Hardhat
      • Using Remix
  • GUIDES
    • Hero Nodes
      • Owner's Manual
        • Purchasing
        • Transferring
        • Delegation
      • Operator's Manual
        • Requirements
        • Installation
        • Operation
Powered by GitBook
On this page
  • What is Hardhat?
  • Creating a Hardhat Project
  • Creating Your Smart Contract
  • Creating Your Configuration File
  • Deploying Your Smart Contract
  1. Deploy
  2. Deploy to XR Sepolia

Using Hardhat

What is Hardhat?

Hardhat is a development environment for Ethereum that helps developers manage and automate the common tasks involved in building smart contracts and decentralized applications. It can directly interact with Caldera's Ethereum API, allowing for the deployment of smart contracts into the Caldera network.

Additionally, Hardhat is a comprehensive set of tools for creating Ethereum-based software, which includes various components that aid in editing, compiling, debugging, and deploying smart contracts and decentralized applications. All of these components work together to create a complete development environment.

Creating a Hardhat Project

  1. Create a directory for your project:

    mkdir hardhat && cd hardhat
  2. Initialize the project, which will create a package.json file

    npm init -y
  3. Install Hardhat

    npm install hardhat
  4. Create a project

    npx hardhat
  5. Create an empty hardhat.config.js and install the Ethers plugin to use the Ethers.js library to interact with the network.

    npm install @nomiclabs/hardhat-ethers ethers

Creating Your Smart Contract

  1. Create a contracts directory

    mkdir contracts && cd contracts
  2. Create your_contract.sol file in contracts directory

    touch your_contract.sol

Creating Your Configuration File

Modify the Hardhat configuration file and create a secure file to store your private key in.

  1. Create a secrets.json file to store your private key

    touch secrets.json
  2. Add your private key to secrets.json

    {
        "privateKey": "YOUR-PRIVATE-KEY-HERE"
    }
  3. Add the file to your project's .gitignore, and never reveal your private key.

  4. Modify the hardhat.config.js file

    • Import the Ethers.js plugin

    • Import the secrets.json file

    • Inside the module.exports add the Caldera network configuration

    require('@nomiclabs/hardhat-ethers');
    const { privateKey } = require('./secrets.json');
    
    module.exports = {
        solidity: "0.8.1",
        defaultNetwork: "rinkeby",
        networks: {
            xr: {
                url: "https://xr-sepolia-testnet.rpc.caldera.xyz/http",
                chainId: 2730,
            }
        },
    }

Deploying Your Smart Contract

  1. Compile the contract

    npx hardhat compilejs
  2. Create a new directory for the script and name it scripts and add a new file to it called deploy.js

    mkdir scripts && cd scriptstouch deploy.js
  3. Create a deployment script, like the one below

    async function main() {
        // 1. Get the contract to deploy
        const Your_Contract = await ethers.getContractFactory('your_contract');
        console.log('Deploying Your_Contract...');
    
        // 2. Instantiating a new smart contract
        const your_contract = await Your_Contract.deploy();
    
        // 3. Waiting for the deployment to resolve
        await your_contract.deployed();
    
        // 4. Use the contract instance to get the contract address
        console.log('Your_Contract deployed to:', your_contract.address);
    }
    
    main()
    .then(() => process.exit(0))
    .catch((error) => {
        console.error(error);
        process.exit(1);
        }
    );
  4. Deploy your_contract.sol using the command below

    npx hardhat run scripts/deploy.js --network xr
PreviousUsing FoundryNextUsing Remix

Last updated 1 year ago