How to create and deploy a smart contract with Hardhat on XDC Network

  • Node.js installed on your system
  • CLI/Terminal
  • Text Editor
mkdir HardhatTutorialcd HardhatTutorial
npm install -d hardhat
npx hardhat
npm install — save-dev @nomiclabs/hardhat-ethers ethers @nomiclabs/hardhat-waffle ethereum-waffle chai
npm cache clean
require(“@nomiclabs/hardhat-waffle”);/*** @type import(‘hardhat/config’).HardhatUserConfig*/const Private_Key = “ADD_YOUR_PRIVATE_KEY_HERE”module.exports = {solidity: “0.7.3”,networks: {xinfin: {url: `ADD_YOUR_RPC_ ENDPOINT_HERE`,accounts: [`0x${Private_Key}`]}}};
// SPDX-License-Identifier: MITpragma solidity ^0.7.3;contract HelloWorld {string saySomething;constructor() {saySomething = “Hello World!”;}function speak() public view returns(string memory) {return saySomething;}}
npx hardhat compile
async function main() {const [deployer] = await ethers.getSigners();console.log(“Deploying contracts with the account:”,deployer.address);console.log(“Account balance:”, (await deployer.getBalance()).toString());const HelloWorld = await ethers.getContractFactory(“HelloWorld”);const contract = await HelloWorld.deploy();console.log(“Contract deployed at:”, contract.address);}main().then(() => process.exit(0)).catch(error => {console.error(error);process.exit(1);});
npx hardhat run scripts/deploy.js — network xinfin

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store