Commit 8c3e8e11 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #1368 from ethereum-optimism/sc/fix-contract-browser-compat

fix: correctly use contract artifact import
parents cdaf2490 ecc2f8c1
---
'@eth-optimism/contracts': patch
'@eth-optimism/message-relayer': patch
---
Patch so contracts package will correctly use the browser-compatible contract artifacts import
import * as path from 'path'
import * as glob from 'glob'
import { import {
ethers, ethers,
ContractFactory, ContractFactory,
...@@ -11,16 +9,16 @@ import { ...@@ -11,16 +9,16 @@ import {
import { Interface } from 'ethers/lib/utils' import { Interface } from 'ethers/lib/utils'
export const getContractDefinition = (name: string, ovm?: boolean): any => { export const getContractDefinition = (name: string, ovm?: boolean): any => {
const match = glob.sync( // We import this using `require` because hardhat tries to build this file when compiling
path.resolve(__dirname, `../artifacts${ovm ? '-ovm' : ''}`) + // the contracts, but we need the contracts to be compiled before the contract-artifacts.ts
`/**/${name.split('-').join(':')}.json` // file can be generated.
) // eslint-disable-next-line @typescript-eslint/no-var-requires
const { getContractArtifact } = require('./contract-artifacts')
if (match.length > 0) { const artifact = getContractArtifact(name, ovm)
return require(match[0]) if (artifact === undefined) {
} else {
throw new Error(`Unable to find artifact for contract: ${name}`) throw new Error(`Unable to find artifact for contract: ${name}`)
} }
return artifact
} }
export const getContractInterface = ( export const getContractInterface = (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment