Create a new file -- hello.js in scripts
folder. We'll require Hardhat's native environment in order to interact with our smart contract --- therefore, let's import
it.
const hre = require("hardhat");
const hre = require("hardhat");
const main = async () => {
console.log("Hello World");
};
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
To execute the script that we just made, just run
the below command.
npx hardhat run scripts/hello.js
npx
- telling NodeJS that you wanna do somethinghardhat
- specifying the package that you want to userun
- stating that you wanna run somethingscripts/hello.js
- setting the path of the file that you wanna runcontracts
folder get compiled + generate all the deployment info.compile
, then why were folders generated, huh? -- coz' Hardhat doesn't care
it simply finds
+ compiles
all contracts automagically :)p.s., in order to integrate smart contract into your frontend -- you'll require only .json file stored @ below path.
artifacts/contracts/[CONTRACT_NAME].sol/[CONTRACT_NAME].json
When you are dealing with many contracts + constantly executing some scripts
-- they will run successfully on first execution;
but after that, they might just keep emitting errors -- if it happens, just use clean
command -- it deletes artifacts
folder and
removes all the files from cache
folder.
npx hardhat clean
You know how everything works right from inside out. But, it ain't worth anything. Click here & let's get em' deployed -- within 3 min.