Skip to content

Instantly share code, notes, and snippets.

@0xalpharush
Created April 26, 2022 20:03
Show Gist options
  • Save 0xalpharush/d347abfafca7923b2d2795379712aeb9 to your computer and use it in GitHub Desktop.
Save 0xalpharush/d347abfafca7923b2d2795379712aeb9 to your computer and use it in GitHub Desktop.
# 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