import { JsonRpcSigner, Wallet, Signer } from "../signers"; import { Contract } from "./contract"; export class ContractFactory { abi: any; bytecode: string; signer: Wallet | JsonRpcSigner; contract: Contract; constructor(abi: any, bytecode: string, signer?: any) { this.abi = abi; this.bytecode = bytecode; this.signer = signer; } /** * Returns a new instance of the ContractFactory * with the same interface and bytecode, * but with a different signer. */ public connect(signer: Signer): ContractFactory { return new ContractFactory(this.abi, this.bytecode, signer) } public async deploy(...args: Array): Promise { const account = await this.signer.getAccount(); const contract = this.signer.provider.cfxClient.Contract({ "abi": this.abi, "bytecode": this.bytecode }); const receipt = await contract.constructor().sendTransaction({ from: account.address }).executed(); const contractAddress = receipt["contractCreated"]; return new Contract(contractAddress, this.abi, this.signer); } }