Skip to content

Instantly share code, notes, and snippets.

@yann300
Created March 2, 2022 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yann300/6ec29d3d7531b9e773c03e4c0965de4b to your computer and use it in GitHub Desktop.
Save yann300/6ec29d3d7531b9e773c03e4c0965de4b to your computer and use it in GitHub Desktop.
// Right click on the script name and hit "Run" to execute
const { expect } = require("chai");
const { ethers } = require("hardhat");
(async () => {
try {
// function getContractFactoryFromArtifact(artifact: Artifact, signer?: ethers.Signer): Promise<ethers.ContractFactory>;
// function getContractFactoryFromArtifact(artifact: Artifact, factoryOptions: FactoryOptions): Promise<ethers.ContractFactory>;
const metadata = JSON.parse(await remix.call('fileManager', 'readFile', 'contracts/artifacts/Storage.json'))
/*
export interface Artifact {
_format: string;
contractName: string;
sourceName: string;
abi: any[];
bytecode: string; // "0x"-prefixed hex string
deployedBytecode: string; // "0x"-prefixed hex string
linkReferences: LinkReferences;
deployedLinkReferences: LinkReferences;
}
*/
/*
interface Libraries {
[libraryName: string]: string;
}
interface FactoryOptions {
signer?: ethers.Signer;
libraries?: Libraries;
}
*/
const artifact = {
contractName: '',
sourceName: 'contracts/1_Storage.sol',
abi: metadata.abi,
bytecode: '0x' + metadata.data.bytecode.object,
deployedBytecode: '0x' + metadata.data.deployedBytecode.object,
linkReferences: metadata.data.bytecode.linkReferences,
deployedLinkReferences: metadata.data.deployedBytecode.linkReferences,
}
const options = {
libraries: metadata.deploy['VM:-'].linkReferences['contracts/1_Storage.sol']
}
console.log(options)
const factory = await ethers.getContractFactoryFromArtifact(artifact, options)
const storage = await factory.deploy();
await storage.deployed();
expect((await storage.retrieve()).toString()).to.equal('0')
const storeValue = await storage.store(333);
// wait until the transaction is mined
await storeValue.wait();
expect((await storage.retrieve()).toString()).to.equal('333')
expect((await storage.getFromLib()).toString()).to.equal('34');
} catch (e) {
console.log(e.message)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment