Created
April 26, 2022 20:03
-
-
Save 0xalpharush/d347abfafca7923b2d2795379712aeb9 to your computer and use it in GitHub Desktop.
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
# add this to your hardhat config | |
# compilers: [ | |
# { | |
# version: "0.8.13", | |
# settings: { | |
# viaIR: true, | |
# outputSelection: { | |
# "*": { | |
# "*": ["irOptimized"], | |
# }, | |
# }, | |
# } | |
# ] | |
import os | |
import json | |
import subprocess | |
subprocess.run(["npx", "hardhat", "compile"]) | |
assert "artifacts" in os.listdir() | |
for dirpath, _, files in os.walk(os.path.join(os.getcwd(), "artifacts", "build-info")): | |
for f in files: | |
artifact = os.path.abspath(os.path.join(dirpath, f)) | |
with open(artifact) as a: | |
data = json.load(a) | |
if "contracts/Contract.sol" in data["output"]["contracts"]: | |
with open("ir.sol", "w+") as file: | |
file.write(str(data["output"]["contracts"]["contracts/Contract.sol"]["Contract"]["irOptimized"])) | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment