How to deploy contract with linked libraries or get contract factory in hardhat-viem #4626
-
Deploying contract with library Model , its usage in contract like: In ethers , we call If we don't pass the libraries , viem panic in deployment : How to pass libraries when deploying? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Had the same problem. I've submitted the following PR that will provide such support. However, for now I can only suggest copy pasting the code as a workaround and parse the bytecode on your own. export async function resolveBytecodeWithLinkedLibraries(
artifact: Artifact,
libraries: Libraries<viemT.Address>
): Promise<string>; Once you have it you will only need to parse bytecode and deploy it using const artifact = await hre.artifacts.readArtifact(
contractName,
);
const publicClient = await hre.viem.getPublicClient();
const [client] = await hre.viem.getWalletClients();
const hash = await client.deployContract({
abi: artifact.abi,
bytecode: resolveBytecodeWithLinkedLibraries(artifact, { library: '0x00...00' }),
args: [],
});
return publicClient.waitForTransactionReceipt({ hash }); |
Beta Was this translation helpful? Give feedback.
Had the same problem. I've submitted the following PR that will provide such support. However, for now I can only suggest copy pasting the code as a workaround and parse the bytecode on your own.
You will need this function.
Once you have it you will only need to parse bytecode and deploy it using
deployContract
.