@dedge_security/hardhat2-deployment-notifier
v0.2.0
Published
Hardhat plugin to notify endpoints on contract deployment
Readme
@dedge_security/hardhat2-deployment-notifier
A Hardhat plugin that automatically sends deployment information to a configurable endpoint whenever a smart contract is deployed.
Requirements
- Node.js 20+
- Hardhat 2.x
Features
- Automatically captures deployment information
- Sends data to configurable HTTP endpoint
- Includes git commit ID, contract address, ABI, constructor arguments, file path, and contract name
- Configurable timeout and error handling
- Works with any EVM network supported by Hardhat
Installation
npm install --save-dev @dedge_security/hardhat2-deployment-notifierConfiguration
Add the following to your hardhat.config.js:
module.exports = {
// ... other config
deploymentNotifier: {
endpoint: "http://localhost:3000/api/deployments", // Required: endpoint URL
timeout: 10000, // Optional: request timeout in ms (default: 10000)
failOnError: false, // Optional: throw error if notification fails (default: false)
},
};Usage
Method 1: Using the Custom Deploy Task
The plugin provides a custom deploy task:
# Deploy without constructor arguments
npx hardhat deploy --contract MyContract --network localhost
# Deploy with constructor arguments
npx hardhat deploy --contract MyContract arg1 arg2 arg3 --network localhostMethod 2: Using in Deployment Scripts
You can also use the plugin's functionality directly in your deployment scripts:
const hre = require("hardhat");
async function main() {
const MyContract = await ethers.getContractFactory("MyContract");
const contract = await MyContract.deploy(arg1, arg2);
await contract.waitForDeployment();
const address = await contract.getAddress();
// Get deployment information
const filePath = hre.deploymentNotifier.getContractFilePath("MyContract");
const abi = hre.deploymentNotifier.getContractABI("MyContract");
const bytecode = hre.deploymentNotifier.getContractBytecode("MyContract");
// Send notification
await hre.deploymentNotifier.notifyDeployment({
address,
contractName: "MyContract",
constructorArgs: [arg1, arg2],
abi,
bytecode,
filePath,
transactionHash: hre.deploymentNotifier.getDeploymentTransactionHash(contract),
deployerAddress: hre.deploymentNotifier.getDeployerAddress(contract),
});
}Data Sent to Endpoint
The plugin sends a POST request with the following JSON payload
{
"gitCommitId": "abc123...",
"gitRepositoryUrl": "https://github.com/org/repo.git",
"contractName": "MyContract",
"contractAddress": "0x...",
"filePath": "contracts/MyContract.sol",
"network": "localhost",
"chainId": "31337",
"timestamp": "2024-01-01T00:00:00.000Z",
"transactionHash": "0x...",
"deployerAddress": "0x...",
"constructorArguments": [...],
"abi": [...],
"bytecode": "0x6080604052..."
}API Reference
hre.deploymentNotifier.notifyDeployment(deploymentData)
Sends deployment notification to the configured endpoint.
Parameters:
deploymentData(object):address(string): Contract addresscontractName(string): Contract nameconstructorArgs(array): Constructor argumentsabi(array): Contract ABIbytecode(string): Deployment bytecode (hex)filePath(string): Source file pathtransactionHash(string, optional): Deployment transaction hashdeployerAddress(string, optional): Address that deployed the contract
Returns: Promise that resolves when notification is sent
hre.deploymentNotifier.getGitCommitId()
Gets the current git commit ID.
Returns: string | null
hre.deploymentNotifier.getContractFilePath(contractName)
Gets the source file path for a contract.
Parameters:
contractName(string): Name of the contract
Returns: string | null
hre.deploymentNotifier.getContractABI(contractName)
Gets the ABI for a contract.
Parameters:
contractName(string): Name of the contract
Returns: array | null
hre.deploymentNotifier.getContractBytecode(contractName)
Gets the deployment bytecode for a contract.
Parameters:
contractName(string): Name of the contract
Returns: string (hex string with "0x" prefix)
hre.deploymentNotifier.getDeploymentTransactionHash(contract)
Gets the deployment transaction hash from a deployed contract instance (returned by ContractFactory.deploy()).
Parameters:
contract(object): Deployed contract instance
Returns: string | null
hre.deploymentNotifier.getDeployerAddress(contract)
Gets the deployer address from a deployed contract instance (returned by ContractFactory.deploy()).
Parameters:
contract(object): Deployed contract instance
Returns: string | null
Error Handling
By default, if the notification fails, the plugin will log a warning but not fail the deployment. To make deployments fail if notification fails, set failOnError: true in the configuration.
Example
See the example/ directory for a complete working example with a mock server.
Build and Test
npm run clean
npm run build
npm run testPublishing to npm
Trigger a github release with tag hardhat2-vX.X.X
Version Management
- Update the version in
package.jsonfollowing semantic versioning:- Patch version (1.0.0 → 1.0.1): Bug fixes
- Minor version (1.0.0 → 1.1.0): New features, backward compatible
- Major version (1.0.0 → 2.0.0): Breaking changes
License
MIT
