Hardhat is an Ethereum development environment for professionals. It facilitates performing frequent tasks, such as running tests, automatically checking code for mistakes or interacting with a smart contract. Check out the plugin list to use it with your existing tools.
Built by the Nomic Foundation for the Ethereum community.
Join our Hardhat Support Discord server to stay up to date on new releases, plugins and tutorials.
💡 The Nomic Foundation is hiring! Check our open positions.
To install Hardhat, go to an empty folder, initialize an npm project (i.e. npm init), and run
npm install --save-dev hardhat
Once it's installed, just run this command and follow its instructions:
npx hardhat init
On Hardhat's website you will find:
You can register custom precompiles in Hardhat Network with the networks.hardhat.customPrecompiles option.
module.exports = {
networks: {
hardhat: {
customPrecompiles: [
{
address: "0x0000000000000000000000000000000000000100",
function: ({ data }) => ({
executionGasUsed: 7n,
returnValue: Uint8Array.from(data),
}),
},
],
},
},
};The handler uses the same interface as ethereumjs precompiles. It receives a PrecompileInput object and must return an ExecResult.
Once configured, you can call the precompile from tests with eth_call:
it("calls the custom precompile", async function () {
const result = await network.provider.send("eth_call", [
{
to: "0x0000000000000000000000000000000000000100",
data: "0x1234abcd",
},
]);
console.log(result);
// 0x1234abcd
});You can also call it from Solidity with call or staticcall:
(bool success, bytes memory output) = address(0x100).staticcall(input);
require(success, "precompile call failed");Restrictions:
- The address must be a valid 20-byte address
- The address cannot be the zero address
- The address cannot overlap with the built-in precompiles at
0x1through0x8 - Each configured address must be unique
To run only the custom precompile tests across Hardhat Core:
pnpm exec mocha --recursive "test/internal/**/*.ts" --grep "customPrecompiles|custom precompile"To run the full Hardhat Core test suite:
pnpm testpnpm test runs pretest first, which builds the workspace before running Mocha. If that build is failing for an unrelated reason, use the focused mocha command above to verify just the custom precompile changes.
Contributions are always welcome! Feel free to open any issue or send a pull request.
Go to CONTRIBUTING.md to learn about how to set up Hardhat's development environment.
Hardhat Support Discord server: for questions and feedback.
👷♀️👷♂️👷♀️👷♂️👷♀️👷♂️👷♀️👷♂️👷♀️👷♂️👷♀️👷♂️👷♀️👷♂️
