How to Deploy Smart Contracts on Base Blockchain
Base is a layer-two (L-2) chain developed by Coinbase, built on OP Stack, a layer-two scaling solution for Ethereum. It's an optimistic rollup chain built on open-sourced OP Stack technology. Base offers a secure, low-cost, and developer-friendly way for anyone to build decentralized apps (DApps) on-chain.
Currently, Base mainnet has not officially launched and users can use its testnet for testing. Base’s mainnet is expected to launch sometime in August.
In this guide, we will walk you through the process of deploying a Non-Fungible Token (NFT) smart contract (ERC-721) on the Base test network using a developer tool called Hardhat.
Before we dive into the deployment process, there are a few prerequisites you need to have in place:
- Node v18+: Ensure you have Node version 18 or above installed. You can download it from here.
- Coinbase Wallet: To deploy a smart contract, you will need a web3 wallet. You can create a wallet by downloading the Coinbase Wallet browser extension.
- Wallet funds: Deploying contracts to the blockchain requires a gas fee. Therefore, you will need to fund your wallet with ETH to cover those gas fees. You can fund your wallet with Base Goerli ETH using options like the Coinbase Faucet | Base Goerli.
Setting Up Your Project
Before deploying smart contracts to Base, you need to set up your development environment by creating a Node.js project. Follow these steps:
- Create a new Node.js project by running:
npm init --y
- Install Hardhat and create a new Hardhat project by running:
npm install --save-dev hardhat
Configuring Hardhat with Base
To deploy smart contracts to the Base network, you will need to configure your Hardhat project and add the Base network. This involves adding Base as a network to your project's hardhat.config.ts file and installing the @nomicfoundation/hardhat-toolbox plugin.
Here is a sample configuration:
To install @nomicfoundation/hardhat-toolbox, run:
npm install --save-dev @nomicfoundation/hardhat-toolbox
Creating and Compiling the Smart Contract
Next, you will create a smart contract for Base and compile it. Below is a simple NFT smart contract (ERC-721) written in Solidity.
Here is the sample contract:
You will need to add the OpenZeppelin Contracts library to your project and compile the contract using Hardhat.
npm install --save @openzeppelin/contracts
npx hardhat compile
Deploying the Smart Contract
Once your contract has been successfully compiled, you can deploy the contract to the Base Goerli test network. This involves modifying the scripts/deploy.ts in your project and running a specific command.
Here is a sample deployment script:
To deploy the contract to the Base Goerli test network, run:
npx hardhat run scripts/deploy.ts --network base-goerli
Verifying the Smart Contract
If you want to interact with your contract on the block explorer, you, or someone, needs to verify it first.
To verify your contract, run:
npx hardhat verify --network base-goerli <deployed address>
Interacting with the Smart Contract
Once your contract is verified, you can use the Read Contract and Write Contract tabs to interact with the deployed contract. You'll need to connect your wallet first, by clicking the Connect button.
By following this guide, you should be able to deploy and interact with a smart contract on the Base blockchain.