Overview
@midl/hardhat-deploy
provides tools and utilities for deploying and interacting with smart contracts in a hybrid environment using Hardhat and MIDL.js.
In general the process of writing and deploying contracts is similar to the standard Hardhat workflow, but with some MIDL-specific features and configurations.
@midl/hardhat-deploy
relies on hardhat-deploy
plugin to manage deployments execution order, however it uses its own deployment artifacts format to store MIDL-specific data.
Installation
pnpm add @midl/hardhat-deploy hardhat-deploy
npm install @midl/hardhat-deploy hardhat-deploy
yarn add @midl/hardhat-deploy hardhat-deploy
Usage
In your Hardhat configuration file (hardhat.config.ts
), you can set up the MIDL environment and extend your configuration with MIDL-specific settings:
Configuration
In your Hardhat configuration file (hardhat.config.ts
), you can set up the MIDL environment and extend your configuration with the following settings.
TIP
For more details on the configuration options, see the Configuration Reference.
import "hardhat-deploy";
import "@midl/hardhat-deploy";
import { midlRegtest } from "@midl/executor";
import { type HardhatUserConfig, vars } from "hardhat/config";
import "@nomicfoundation/hardhat-verify";
export default (<HardhatUserConfig>{
solidity: "0.8.28",
defaultNetwork: "regtest",
midl: {
networks: {
regtest: {
mnemonic: vars.get("MNEMONIC"),
path: "deployments",
confirmationsRequired: 1,
btcConfirmationsRequired: 1,
hardhatNetwork: "regtest",
network: {
explorerUrl: "https://mempool.regtest.midl.xyz",
id: "regtest",
network: "regtest",
},
},
},
},
networks: {
regtest: {
url: midlRegtest.rpcUrls.default.http[0],
chainId: midlRegtest.id,
},
},
etherscan: {
apiKey: {
regtest: "empty",
},
customChains: [
{
network: "regtest",
chainId: midlRegtest.id,
urls: {
apiURL: "https://blockscout.regtest.midl.xyz/api",
browserURL: "https://blockscout.regtest.midl.xyz",
},
},
],
},
});
Usage
Create a new deployment script in the deploy
directory (e.g., deploy/01_deploy_contracts.ts
) and use the provided methods to deploy and interact with contracts.
import type { HardhatRuntimeEnvironment } from "hardhat/types";
export default async function deploy(hre: HardhatRuntimeEnvironment) {
await hre.midl.initialize();
// Deploy a contract
await hre.midl.deploy('MyContract', { args: ["Hello, MIDL!"] });
// Call a contract method
await hre.midl.callContract('MyContract', 'setGreeting', { args: ["Hi!"] });
// Execute all intentions (send transactions)
await hre.midl.execute();
}
See the Advanced Usage for more examples on commonly used functionality.