-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hardhat): add deployment persistence to hardhat node
- Add volume mappings for deployments, artifacts and cache - Implement manual deployment file saving - Update hardhat configuration for proper deployment paths This change ensures that deployed contracts persist between container restarts by saving deployment data to mounted volumes. Note: Block persistence still requires a different solution (Ganache/Geth/Besu) as Hardhat Network doesn't support state persistence. Related issue: #669
- Loading branch information
Showing
7 changed files
with
104 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module.exports = async function ({ getNamedAccounts, deployments, network }) { | ||
const { deploy, save, getArtifact } = deployments; | ||
const { deployer } = await getNamedAccounts(); | ||
|
||
console.log("Starting deployment of GhostContract..."); | ||
|
||
const result = await deploy('GhostContract', { | ||
from: deployer, | ||
args: [], | ||
log: true, | ||
deterministicDeployment: false, | ||
gasPrice: 0, | ||
gasLimit: 5000000, | ||
waitConfirmations: 1 | ||
}); | ||
|
||
const artifact = await getArtifact('GhostContract'); | ||
const deploymentData = { | ||
address: result.address, | ||
abi: artifact.abi, | ||
bytecode: artifact.bytecode, | ||
transactionHash: result.transactionHash | ||
}; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const deploymentDir = path.join('./deployments', network.name); | ||
const deploymentFile = path.join(deploymentDir, 'GhostContract.json'); | ||
|
||
fs.mkdirSync(deploymentDir, { recursive: true }); | ||
|
||
fs.writeFileSync(deploymentFile, JSON.stringify(deploymentData, null, 2)); | ||
|
||
console.log(`Deployment successful! Contract deployed at: ${result.address}`); | ||
}; | ||
|
||
module.exports.tags = ['GhostContract']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,8 @@ | |
}, | ||
"engines": { | ||
"node": ">=18.0.0" | ||
}, | ||
"devDependencies": { | ||
"hardhat-deploy": "^0.14.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/sh | ||
|
||
echo "Checking and compiling contracts if needed..." | ||
npx hardhat compile | ||
|
||
echo "Starting Hardhat node..." | ||
npx hardhat node --hostname 0.0.0.0 --no-deploy & | ||
|
||
# Wait for the node to start | ||
sleep 5 | ||
|
||
# Check if the contract is already deployed (using hardhat network) | ||
if [ ! -f "/app/deployments/hardhat/GhostContract.json" ]; then | ||
echo "Running deployments..." | ||
npx hardhat deploy | ||
else | ||
echo "Contracts already deployed, skipping deployment..." | ||
fi | ||
|
||
# Keep the container running | ||
wait |