readDeployments.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const path = require("path");
  2. const fs = require("fs");
  3. const PROJECT_ROOT = path.resolve(__dirname, "..");
  4. const DEPLOYMENT_PATH = path.resolve(PROJECT_ROOT, "deployments");
  5. function getDeploymentAddresses(networkName) {
  6. let folderName = networkName;
  7. if (networkName === "hardhat") {
  8. folderName = "localhost";
  9. }
  10. const networkFolderName = fs
  11. .readdirSync(DEPLOYMENT_PATH)
  12. .filter((f) => f === folderName)[0];
  13. if (networkFolderName === undefined) {
  14. throw new Error("missing deployment files for endpoint " + folderName);
  15. }
  16. let rtnAddresses = {};
  17. const networkFolderPath = path.resolve(DEPLOYMENT_PATH, folderName);
  18. const files = fs
  19. .readdirSync(networkFolderPath)
  20. .filter((f) => f.includes(".json"));
  21. files.forEach((file) => {
  22. const filepath = path.resolve(networkFolderPath, file);
  23. const data = JSON.parse(fs.readFileSync(filepath));
  24. const contractName = file.split(".")[0];
  25. rtnAddresses[contractName] = data.address;
  26. });
  27. return rtnAddresses;
  28. }
  29. module.exports = {
  30. getDeploymentAddresses,
  31. };