With Hardhat
Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.

Setting up the development environment

There are a few dependencies to install before we start. Please install the following:
Do ensure that your npm modules have been added to your path
After installing the above dependencies, we can proceed to install hardhat:
1
npm install --save-dev hardhat
Copied!
To create your Hardhat project, run this command while you are in the project's root folder:
1
npx hardhat
Copied!
Return (choose the most appropriate option):
1
? What do you want to do? ...
2
> Create a basic sample project
3
Create an advanced sample project
4
Create an advanced sample project that uses TypeScript
5
Create an empty hardhat.config.js
6
Quit
Copied!
Let’s create the sample project and go through these steps to try out the sample task and compile, test and deploy the sample contract.
The sample project will ask you to install hardhat-waffle and hardhat-ethers, which makes Hardhat compatible with tests built with Waffle. You can learn more about it in this guide.
Hardhat will let you know how, but, in case you missed it, you can install them with npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers

hardhat-config

  • After setting up your truffle project, be it cloning a repository or initializing a new hardhat project
  • Open hardhat-config.js
  • Edit hardhat-config.js with f(x)Core network credentials
  • Create a .env file to store your private key of that corresponding wallet address
The files below are just an example, feel free to rename your variables:
.env
1
FXCORE_WALLET_PRIVATE_KEY=c3b8df3c3165067e05XXXXXXXXXXXXXXXXXXXXXXXXxxxxXXXXXXbb
Copied!
hardhat.config.js
1
require("@nomiclabs/hardhat-waffle");
2
require("dotenv").config();
3
const fxcorePrivateKey=process.env.FXCORE_WALLET_PRIVATE_KEY
4
5
module.exports = {
6
defaultNetwork: "fxtestnet",
7
networks: {
8
hardhat: {
9
},
10
fxtestnet: {
11
url: "https://testnet-fx-json-web3.functionx.io:8545",
12
accounts: [`0x${fxcorePrivateKey}`]
13
}
14
},
15
solidity: {
16
version: "0.8.0",
17
settings: {
18
optimizer: {
19
enabled: true,
20
runs: 200
21
}
22
}
23
},
24
}
25
Copied!
if you have not already installed dontenv, please do so by running the following command:
1
npm install dotenv
Copied!

Compile Smart contract file

1
npx hardhat compile
Copied!

Deploying on f(x)Core Network

Run this command in root of the project directory:
1
npx hardhat run scripts/sample-script.js --network fxtestnet
Copied!
Contract will be deployed on f(x)Core network, it will look something like this:
1
Greeter deployed to: 0x70A8aa0fb6a0B4732b2daaBc3143E4C3d560DD57
Copied!
Remember your address would differ, the above is just to provide an idea of structure. Congratulations! You have successfully deployed Greeter Smart Contract. Now you can interact with the Smart Contract.
You can check the deployment status on Testnet.