ethers#ContractFactory TypeScript Examples

The following examples show how to use ethers#ContractFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts    From hypervisor with The Unlicense 7 votes vote down vote up
export async function deployContract(
  name: string,
  factory: ContractFactory,
  signer: Signer,
  args: Array<any> = [],
): Promise<Contract> {
  const contract = await factory.connect(signer).deploy(...args)
  console.log('Deploying', name)
  console.log('  to', contract.address)
  console.log('  in', contract.deployTransaction.hash)
  return contract.deployed()
}
Example #2
Source File: deploy.ts    From bodhi.js with Apache License 2.0 6 votes vote down vote up
main = async () => {
  const { wallet, provider } = await setup();

  console.log('Deploy HelloWorld');

  const instance = await ContractFactory.fromSolidity(HelloWorld).connect(wallet).deploy();

  console.log('HelloWorld address:', instance.address);

  const variable = await instance.helloWorld();

  console.log('Stored variable:', variable);

  provider.api.disconnect();
}
Example #3
Source File: deploy.ts    From BarnBridge-Barn with Apache License 2.0 6 votes vote down vote up
export async function deployDiamond (diamondArtifactName: string, facets: Array<Contract>, owner: string): Promise<Contract> {
    const diamondCut = [];

    for (const facet of facets) {
        diamondCut.push([
            facet.address,
            diamond.FacetCutAction.Add,
            diamond.getSelectors(facet),
        ]);
    }

    const diamondFactory: ContractFactory = await ethers.getContractFactory(diamondArtifactName);
    const deployedDiamond: Contract = await diamondFactory.deploy(diamondCut, owner);
    await deployedDiamond.deployed();

    return deployedDiamond;
}
Example #4
Source File: deploy-beacon.ts    From openzeppelin-upgrades with MIT License 6 votes vote down vote up
export function makeDeployBeacon(hre: HardhatRuntimeEnvironment): DeployBeaconFunction {
  return async function deployBeacon(ImplFactory: ContractFactory, opts: Options = {}) {
    const { impl } = await deployBeaconImpl(hre, ImplFactory, opts);

    const UpgradeableBeaconFactory = await getUpgradeableBeaconFactory(hre, ImplFactory.signer);
    const beaconDeployment: Required<Deployment & DeployTransaction> = await deploy(UpgradeableBeaconFactory, impl);
    const beaconContract = UpgradeableBeaconFactory.attach(beaconDeployment.address);

    // @ts-ignore Won't be readonly because beaconContract was created through attach.
    beaconContract.deployTransaction = beaconDeployment.deployTransaction;
    return beaconContract;
  };
}
Example #5
Source File: BasicTokenFactory.ts    From panvala with Apache License 2.0 6 votes vote down vote up
export class BasicTokenFactory extends ContractFactory {
  constructor(signer?: Signer) {
    super(_abi, _bytecode, signer);
  }

  deploy(
    _name: string,
    _symbol: string,
    _decimals: BigNumberish,
    _initialSupply: BigNumberish
  ): Promise<BasicToken> {
    return super.deploy(_name, _symbol, _decimals, _initialSupply) as Promise<BasicToken>;
  }
  getDeployTransaction(
    _name: string,
    _symbol: string,
    _decimals: BigNumberish,
    _initialSupply: BigNumberish
  ): UnsignedTransaction {
    return super.getDeployTransaction(_name, _symbol, _decimals, _initialSupply);
  }
  attach(address: string): BasicToken {
    return super.attach(address) as BasicToken;
  }
  connect(signer: Signer): BasicTokenFactory {
    return super.connect(signer) as BasicTokenFactory;
  }
  static connect(address: string, signerOrProvider: Signer | Provider): BasicToken {
    return new Contract(address, _abi, signerOrProvider) as BasicToken;
  }
}
Example #6
Source File: BadReturnValueERC20__factory.ts    From nova with GNU Affero General Public License v3.0 6 votes vote down vote up
export class BadReturnValueERC20__factory extends ContractFactory {
  constructor(signer?: Signer) {
    super(_abi, _bytecode, signer);
  }

  deploy(
    overrides?: Overrides & { from?: string | Promise<string> }
  ): Promise<BadReturnValueERC20> {
    return super.deploy(overrides || {}) as Promise<BadReturnValueERC20>;
  }
  getDeployTransaction(
    overrides?: Overrides & { from?: string | Promise<string> }
  ): TransactionRequest {
    return super.getDeployTransaction(overrides || {});
  }
  attach(address: string): BadReturnValueERC20 {
    return super.attach(address) as BadReturnValueERC20;
  }
  connect(signer: Signer): BadReturnValueERC20__factory {
    return super.connect(signer) as BadReturnValueERC20__factory;
  }
  static readonly bytecode = _bytecode;
  static readonly abi = _abi;
  static createInterface(): BadReturnValueERC20Interface {
    return new utils.Interface(_abi) as BadReturnValueERC20Interface;
  }
  static connect(
    address: string,
    signerOrProvider: Signer | Provider
  ): BadReturnValueERC20 {
    return new Contract(address, _abi, signerOrProvider) as BadReturnValueERC20;
  }
}
Example #7
Source File: UniswapV3Deployer.ts    From hardhat-v3-deploy with MIT License 6 votes vote down vote up
private async deployContract<T>(
    abi: any,
    bytecode: string,
    deployParams: Array<any>,
    actor: Signer
  ) {
    const factory = new ContractFactory(abi, bytecode, actor);
    return await factory.deploy(...deployParams);
  }
Example #8
Source File: Admin__factory.ts    From hypervisor with The Unlicense 6 votes vote down vote up
constructor(
    ...args: [signer: Signer] | ConstructorParameters<typeof ContractFactory>
  ) {
    if (args.length === 1) {
      super(_abi, _bytecode, args[0]);
    } else {
      super(...args);
    }
  }
Example #9
Source File: DSAuthEventsFactory.ts    From dai-backstop-syndicate with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
export class DSAuthEventsFactory extends ContractFactory {
  constructor(signer?: Signer) {
    super(_abi, _bytecode, signer);
  }

  deploy(): Promise<DSAuthEvents> {
    return super.deploy() as Promise<DSAuthEvents>;
  }
  getDeployTransaction(): UnsignedTransaction {
    return super.getDeployTransaction();
  }
  attach(address: string): DSAuthEvents {
    return super.attach(address) as DSAuthEvents;
  }
  connect(signer: Signer): DSAuthEventsFactory {
    return super.connect(signer) as DSAuthEventsFactory;
  }
  static connect(
    address: string,
    signerOrProvider: Signer | Provider
  ): DSAuthEvents {
    return new Contract(address, _abi, signerOrProvider) as DSAuthEvents;
  }
}
Example #10
Source File: helpers.ts    From etherspot-sdk with MIT License 6 votes vote down vote up
export async function deployToken(wallet: Wallet): Promise<string> {
  const provider = wallet.provider;

  // Read the contract artifact, which was generated by Remix
  const metadata = JSON.parse(fs.readFileSync('./src/common/artifacts/ERC20/DevToken.json').toString());

  // Set gas limit and gas price, using the default Ropsten provider
  const price = utils.formatUnits(await provider.getGasPrice(), 'gwei');
  console.log(utils.parseUnits(price, 'gwei'));
  const options = { gasLimit: 10000000, gasPrice: utils.parseUnits(price, 'gwei') };

  // Deploy the contract
  const factory = new ContractFactory(metadata.abi, metadata.data.bytecode.object, wallet);
  const contract = await factory.deploy(options);
  await contract.deployed();
  console.log(`Deployment successful! Contract Address: ${contract.address}`);
  return contract.address;
}
Example #11
Source File: AaveTokenV1Mock__factory.ts    From commonwealth with GNU General Public License v3.0 6 votes vote down vote up
export class AaveTokenV1Mock__factory extends ContractFactory {
  constructor(signer?: Signer) {
    super(_abi, _bytecode, signer);
  }

  deploy(
    overrides?: Overrides & { from?: string | Promise<string> }
  ): Promise<AaveTokenV1Mock> {
    return super.deploy(overrides || {}) as Promise<AaveTokenV1Mock>;
  }
  getDeployTransaction(
    overrides?: Overrides & { from?: string | Promise<string> }
  ): TransactionRequest {
    return super.getDeployTransaction(overrides || {});
  }
  attach(address: string): AaveTokenV1Mock {
    return super.attach(address) as AaveTokenV1Mock;
  }
  connect(signer: Signer): AaveTokenV1Mock__factory {
    return super.connect(signer) as AaveTokenV1Mock__factory;
  }
  static connect(
    address: string,
    signerOrProvider: Signer | Provider
  ): AaveTokenV1Mock {
    return new Contract(address, _abi, signerOrProvider) as AaveTokenV1Mock;
  }
}
Example #12
Source File: Distributor__factory.ts    From kitty-contracts with MIT License 6 votes vote down vote up
export class Distributor__factory extends ContractFactory {
  constructor(...args: DistributorConstructorParams) {
    if (isSuperArgs(args)) {
      super(...args);
    } else {
      super(_abi, _bytecode, args[0]);
    }
  }

  deploy(
    _distributors: string[],
    overrides?: Overrides & { from?: string | Promise<string> }
  ): Promise<Distributor> {
    return super.deploy(_distributors, overrides || {}) as Promise<Distributor>;
  }
  getDeployTransaction(
    _distributors: string[],
    overrides?: Overrides & { from?: string | Promise<string> }
  ): TransactionRequest {
    return super.getDeployTransaction(_distributors, overrides || {});
  }
  attach(address: string): Distributor {
    return super.attach(address) as Distributor;
  }
  connect(signer: Signer): Distributor__factory {
    return super.connect(signer) as Distributor__factory;
  }
  static readonly bytecode = _bytecode;
  static readonly abi = _abi;
  static createInterface(): DistributorInterface {
    return new utils.Interface(_abi) as DistributorInterface;
  }
  static connect(
    address: string,
    signerOrProvider: Signer | Provider
  ): Distributor {
    return new Contract(address, _abi, signerOrProvider) as Distributor;
  }
}