.env
file to store the secrets..env
. Here, you will set up the environment variables for your Chainststack endpoint and your wallet’s private key.
hardhat.config.js
in the root directory. This file is used to configure various settings for your Hardhat projects, such as the network you want to deploy your contracts on, the compilers you want to use, and the plugins you want to enable.
Delete the default code in the file and replace it with the following:
require("@nomicfoundation/hardhat-toolbox");
imports the Hardhat Toolbox plugin, which provides several useful tools and utilities for Hardhat projects.require("dotenv").config();
loads environment variables from a .env
file using the dotenv
package.module.exports = { ... }
exports a JavaScript object containing the configuration for the Hardhat project.solidity: "0.8.18",
sets the Solidity compiler version to 0.8.18.networks: { ... }
defines the network configurations for the Hardhat project.defaultNetwork: { ... }
defines the default network that Hardhat will use.base_testnet: { ... }
defines the configuration for the base
network.url: ${process.env.CHAINSTACK_ENDPOINT},
sets the RPC URL for the Base network.accounts: [process.env.YOUR_PRIVATE_KEY],
sets the accounts for the base
network using the PRIVATE_KEY
environment variable. This will allow the Hardhat project to deploy contracts and interact with the Base Testnet using the specified private key.contracts
. Create a new file named CBS.sol
, and paste the following code inside it:
ChainBase
is an implementation of an ERC-721 token. ERC-721 is a standard for non-fungible tokens on the Ethereum blockchain, meaning each token has a unique value and is not interchangeable with any other token. ERC-721 tokens are often used for digital collectibles or assets.
Then install the OpenZeppelin package in your project:
scripts
directory inside the root of your project, you will find a file named deploy.js
. Replace its content with the following:
ChainBase
smart contract to the Base Sepolia Testnet, and returns the address of the newly deployed contract in the terminal. You can search for your contract on the Base Sepolia explorer.
To run this script, execute the following command in the terminal: