LogoLogo
Social LinksDevelopers
  • Kick off
    • 🌠Getting started
    • πŸ“ΊFinding guidance
  • Essential Concepts
    • πŸ•΅οΈβ€β™€οΈWhat is 3Base ?
    • 🎭3Base’s RaaS Platform
    • ⚑The 3Base Advantage
    • β˜„οΈSupported Rollup Stacks
    • πŸ¦„3Base Unifier
    • 🏴The 3Base Rollup Stack
    • πŸ–¨οΈ3Base’s Arbitrum Stack Integration
    • 🎀Supported DA Layers
  • Handbooks
    • πŸ“”Deploying Contracts
    • πŸŒ‰Bridge Tokens
    • πŸ—žοΈ3Base Rollup Guide
    • πŸ› οΈTooling
    • πŸ‘¨β€πŸ’ΌThe Architecture
  • Learning Resources
    • β™’Layer 3 – A Massive Step in Blockchain Evolution
    • 🫰Coinbase’s Base Chain Facilitating the Layer 3 Revolution
    • πŸ—οΈBuilding the Ideal RaaS Platform on Base
    • πŸ›Why Implement More Layers on Base? And Why Now?
    • πŸͺ„Optimistic Rollups
    • 🦼ZK-Rollups
    • πŸ“MultiSig and MPC Contract Security
  • ❓FAQ
Powered by GitBook

Copyright Β© 2024 3Base . All rights reserved.

On this page
  • What is Hardhat?
  • Creating a Hardhat Project
  • Creating Your Smart Contract
  • Creating Your Configuration File
  • Deploying Your Smart Contract

Was this helpful?

Export as PDF
  1. Handbooks

Deploying Contracts

Deploying Contracts using Hardhat

PreviousHandbooksNextBridge Tokens

Last updated 11 months ago

Was this helpful?

You can deploy your contracts in 3Base using hardhat.

What is Hardhat?

Hardhat is a development environment for Ethereum. It helps developer manage and automate building smart contracts. It consists of different components for editing, compiling, debugging and deploying your smart contracts and dApps, all of which work together to create a complete development environment.

Creating a Hardhat Project

  1. Create a directory for you project

//make adirectory and go inside it 
mkdir 3Base_Project && cd 3Base_Project
  1. Initialize the project with hardhat

npx hardhat init 
  1. Choose the Configuration of your hardhat project, a sample typescript project(recommended)

Creating Your Smart Contract

  1. Add your contracts to the contracts folder or

  2. Create a contracts directory, if there is none

mkdir contracts && cd contracts
  1. Create your contract in the contracts directory

touch your_contract.sol

Creating Your Configuration File

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

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

{
"privateKey": "YOUR_PRIVATE_KEY_HERE"
}
  1. Add secrets.json to .gitignore, to avoid pushing your private key to github

  2. Modify the hardhat.config.ts file as below

// hardhat.config.ts

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
const { privateKey } = require("./secrets.json");

const config: HardhatUserConfig = {
  solidity: {
    version: "0.8.24",
  },
  networks: {
    three_base: {
      url: `RPC URL`,//INSERT YOUR RPC URL HERE
      accounts: [privateKey],
      timeout: 60000,
    },
  },
};

export default config;

Deploying Your Smart Contract

  1. Compile your contract

npx hardhat compile
  1. Create a scripts directory and create your deployment scripts

mkdir scripts && cd scripts
touch deploy.ts
  1. 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.waitForDeployment();

  // 4. Use the contract instance to get the contract address
  const contract_address = await your_contract.getAddress();
  console.log("Your_Contract deployed to:", contract_address);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });
  1. Deploy your_contract.sol using the command below

npx hardhat run scripts/deploy.ts
πŸ“”