How to use the ethers.ethers.Contract function in ethers

To help you get started, we’ve selected a few ethers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tasitlabs / tasit-sdk / packages / action / src / contract / Contract.ts View on Github external
constructor(address: string, abi: string, wallet: Wallet | undefined) {
    if (!Utils.isAddress(address) || !Utils.isABI(abi))
      throw new Error(`Cannot create a Contract without a address and ABI`);

    if (wallet && !Utils.isEthersJsSigner(wallet))
      throw new Error(`Cannot set an invalid wallet for a Contract`);

    const provider = ProviderFactory.getProvider();

    // If there's a wallet, connect it with provider.
    // Otherwise use provider directly (for read operations only).
    const signerOrProvider = wallet ? wallet.connect(provider) : provider;

    const ethersContract = new ethers.Contract(address, abi, signerOrProvider);

    super(ethersContract);
    this.provider = provider;
    this.ethersContract = ethersContract;
    this.addFunctionsToContract();
  }
github JoinColony / colonyNetwork / packages / reputation-miner / ReputationMiner.js View on Github external
const metaColony = new ethers.Contract(metaColonyAddress, this.colonyContractDef.abi, this.realWallet);
    this.clnyAddress = await metaColony.getToken();

    if (this.useJsTree) {
      this.reputationTree = new PatriciaTree();
    } else {
      this.patriciaTreeContractDef = await this.loader.load({ contractName: "PatriciaTree" }, { abi: true, address: false, bytecode: true });
      this.patriciaTreeNoHashContractDef = await this.loader.load(
        { contractName: "PatriciaTreeNoHash" },
        { abi: true, address: false, bytecode: true }
      );

      const contractFactory = new ethers.ContractFactory(this.patriciaTreeContractDef.abi, this.patriciaTreeContractDef.bytecode, this.ganacheWallet);
      const contract = await contractFactory.deploy();
      await contract.deployed();
      this.reputationTree = new ethers.Contract(contract.address, this.patriciaTreeContractDef.abi, this.ganacheWallet);
    }

    this.nReputations = ethers.constants.Zero;
    this.reputations = {};
    this.gasPrice = ethers.utils.hexlify(20000000000);
  }
github DeltaCamp / apollo-link-ethereum / packages / apollo-link-ethereum-resolver-ethersjs / src / EthersResolver.ts View on Github external
}

    let address = contractDirectives ? contractDirectives.address : null
    if (!address) {
      address = this.abiMapping.getAddress(contractName, chainId)
    }
    if (!address) {
      throw new Error(`Address not present in query against abi ${contractName}`)
    }
    let contract = this.contractCache[chainId][address]
    if (!contract) {
      const abi: any = this.abiMapping.getAbi(contractName)
      if (!abi) {
        throw new Error(`Could not find abi for name ${contractName}`)
      }
      contract = new ethers.Contract(address, abi, provider)
      this.contractCache[chainId][address] = contract
    }
    return contract
  }