Hardhat Project Setup
Install and use the Hardhat plugin
The Hardhat plugin extends Hardhat network by listening to incoming blocks and synchronizing them directly with the dashboard. Once installed and included, you won't need to run the CLI as it will be able to listen and synchronize blocks directly.
Add
hardhat-ethernal
to your package.json
, and run npm install
or yarn
In your
hardhat-config.js
file, require the plugin:require('hardhat-ethernal');
That's it! Blocks and transactions will now be synchronized.
It's possible to disable the synchronization by setting
ethernalSync
to false
on the hre
object.You can also specify which workspace you want to synchronize blocks & transactions to (default to the last one used in the dashboard).
By default, transactions will be traced using
experimentalAddHardhatNetworkMessageTraceHook
, showing CALLx and CREATEx operations in the dashboard. You can disable this feature with the ethernalTrace
flag.You can automatically reset your workspace by setting the
ethernalResetOnStart
property to the name of the workspace. Everytime the node starts, all accounts/blocks/transactions/contracts will be deleted.extendEnvironment((hre) => {
hre.ethernalSync = true;
hre.ethernalWorkspace = 'Workspace';
hre.ethernalTrace = false;
hre.ethernalResetOnStart = 'Hardhat';
});
You can log in either by using
ethernal login
Or by calling Hardhat commands with extra env variables:
ETHERNAL_EMAIL=[email protected] ETHERNAL_PASSWORD=yourpwd npx hardhat node
Require the package in your deploy script:
require('hardhat-ethernal');
The plugin will add an
ethernal
object with a push
function on the hre
object.
This function takes two parameters:name
: name of the contract (case sensitive). It needs to match exactly the name of the deployed contractaddress
: address of the contract
You should call this function anytime after the contract has been successfully deployed.
This function returns an empty promise.
By default, the push function is not going to upload AST to Ethernal. If you want to use "Storage" tab on contracts pages, you'll need to activate it. To do so, set the
hre.ethernalUploadAst = true
flag in your Hardhat config file (this will upload the ast field, as well as the source field).const hre = require("hardhat");
async function main() {
const Greeter = await hre.ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, Hardhat!");
await hre.ethernal.push({
name: 'Greeter',
address: greeter.address
})
console.log("Greeter deployed to:", greeter.address);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
You can manually reset a workspace by calling:
hre.ethernal.resetWorkspace(workspaceName)
(async function). All accounts/blocks/transactions/contracts will be deleted;Last modified 1yr ago