I've been trying to deploy a contract with ethers.js using the artifacts produced by hardhat compile, but it fails on factory creation with an "invalid bytecode" error, because the json
bytecode key in the json file from artfacts/MyContract.sol/MyContract.json' contains non-hex characters which cause ethers.js ContractFactory constructor to throw an invalid bytecode error.
Examing what's actually in the json, most of it looks like a hex string, but sometime I am seeing as section that looks like this:
3__$1ca363c46bd7f7114c4ccedbc882b31c3a$__9163: a section of code that starts with
__$ and ending with
$__. (which I suspect is an address, but not certain).
Is there some way to exact from the results of hardhat compile pure bytecode that doesn't have these embbeded non-hex characters and can be used to deploy a contract with ethers.js directly?
Additional note: I think these codes have do with libraries used by the smart contracts in question. But how to get the merged bytecode from the contracts actually deployed which includes the necessary bytecode to call the libraries isn't clear to me.