A tutorial for deploying a smart contract on Zircuit
Overview
Deploying your first contract on Zircuit is easy! This tutorial will show you how.
If you already have an existing development environment for Ethereum, this will be fast and probably take only 10-15 minutes.
We have even provided you a boilerplate project to make this process even simpler!
Walkthrough
1. Set Up Hardhat
Create the folder for you new project and navigate within
mkdir my-zircuit-coin
cd my-zircuit-coin
Install Hardhat using npm (Node Package Manager):
npm install --save-dev hardhat
Install the hardhat toolbox for a later step
npm i @nomicfoundation/hardhat-toolbox
Initialize a new Hardhat project:
2. Write Your Smart Contract
We created a sample smart contract file which has everything you need for easy deployment. Place this file in contracts/Token.sol inside of your hardhat project.
// WARNING:
// THIS CODE IS SIMPLIFIED AND WAS CREATED FOR TESTING
// PURPOSES ONLY. DO NOT USE THIS CODE IN PRODUCTION!
pragma solidity 0.8.19;
contract Token {
string public name = "Name Goes here";
string public symbol = "TICKER";
// The fixed amount of tokens, stored in an unsigned integer type variable.
uint256 public totalSupply = 21000000;
// An address type variable is used to store ethereum accounts.
address public owner;
// A mapping is a key/value map. Here we store each account's balance.
mapping(address => uint256) balances;
// The Transfer event helps off-chain applications understand
// what happens within your contract.
event Transfer(address indexed _from, address indexed _to, uint256 _value);
constructor() {
balances[msg.sender] = totalSupply;
owner = msg.sender;
}
function transfer(address to, uint256 amount) external {
require(balances[msg.sender] >= amount, "Not enough tokens");
// Transfer the amount.
balances[msg.sender] -= amount;
balances[to] += amount;
// Notify off-chain applications of the transfer.
emit Transfer(msg.sender, to, amount);
}
function balanceOf(address account) external view returns (uint256) {
return balances[account];
}
}
All you need to do now to customize your token is replace the following section of the Token.sol file:
string public name = "Name Goes Here";
string public symbol = "TICKER";
// The fixed amount of tokens, stored in an unsigned integer type variable.
uint256 public totalSupply = 21000000;
These values are just filler, so put in a fun name for your token, a ticker and adjust the supply as you see fit!
3. Set Up Your Network and Solidity Compiler Configuration
Edit the hardhat.config.js file to define network configurations. In this case, all you need to do is enter your Zircuit private key. A sample is shown below.
Use this Hardhat command to compile your contract:
5. Write A Deployment Script
In the scripts directory, create a deployment script, for instance deploy.js. This script will handle the deployment of your smart contract. A sample is below.