ethers#ContractInterface TypeScript Examples

The following examples show how to use ethers#ContractInterface. 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 ether-swr with MIT License 7 votes vote down vote up
export function getContract(
  address: string,
  abi: ContractInterface,
  provider: Provider | Web3Provider
): Contract {
  let contract = contracts.get(address)
  if (contract) {
    return contract
  }
  contract = new Contract(address, abi, provider as Provider)
  contracts.set(address, contract)
  return contract
}
Example #2
Source File: env.ts    From panvala with Apache License 2.0 6 votes vote down vote up
export async function loadContracts(provider) {
  const { chainId } = await provider.getNetwork();
  const signer = provider.getSigner();

  // Addresses
  const tokenAddress =
    chainId === 4
      ? '0x4912d6aBc68e4F02d1FdD6B79ed045C0A0BAf772'
      : chainId === 1 && '0xD56daC73A4d6766464b38ec6D91eB45Ce7457c44';
  const tcAddress =
    chainId === 4
      ? '0xA062C59F42a45f228BEBB6e7234Ed1ea14398dE7'
      : chainId === 1 && '0x9a7B675619d3633304134155c6c976E9b4c1cfB3';
  const exchangeAddress =
    chainId === 4
      ? '0x25EAd1E8e3a9C38321488BC5417c999E622e36ea'
      : chainId === 1 && '0xF53bBFBff01c50F2D42D542b09637DcA97935fF7';

  // Get codes
  const tokenCode = await provider.getCode(tokenAddress);
  const tcCode = await provider.getCode(tcAddress);
  const exchangeCode = await provider.getCode(exchangeAddress);

  // prettier-ignore
  if (!tokenAddress || !tcAddress || !exchangeAddress || !tokenCode || !tcCode || !exchangeCode) {
        throw new Error('Invalid address or no code at address.')
      }

  // Init token, token capacitor, uniswap exchange contracts
  const token = new Contract(tokenAddress, tokenAbi, signer);
  const tokenCapacitor = new Contract(tcAddress, tcAbi, signer);
  const exchange = new Contract(exchangeAddress, exchangeAbi as ContractInterface, signer);

  return {
    token,
    tokenCapacitor,
    exchange,
  };
}
Example #3
Source File: ethers-provider.ts    From simple-pancakeswap-sdk with MIT License 6 votes vote down vote up
/**
   * Creates a contract instance
   * @param abi The ABI
   * @param contractAddress The contract address
   */
  public getContract<TGeneratedTypedContext>(
    abi: ContractInterface,
    contractAddress: string
  ): TGeneratedTypedContext {
    const contract = new Contract(contractAddress, abi, this._ethersProvider);

    return (contract as unknown) as TGeneratedTypedContext;
  }
Example #4
Source File: ethers-provider.ts    From simple-uniswap-sdk with MIT License 6 votes vote down vote up
/**
   * Creates a contract instance
   * @param abi The ABI
   * @param contractAddress The contract address
   */
  public getContract<TGeneratedTypedContext>(
    abi: ContractInterface,
    contractAddress: string
  ): TGeneratedTypedContext {
    const contract = new Contract(contractAddress, abi, this._ethersProvider);

    return contract as unknown as TGeneratedTypedContext;
  }
Example #5
Source File: bond.ts    From lobis-frontend with MIT License 5 votes vote down vote up
public readonly bondContractABI: ContractInterface;
Example #6
Source File: bond.ts    From lobis-frontend with MIT License 5 votes vote down vote up
protected abstract reserveContractAbi: ContractInterface;
Example #7
Source File: lp-bond.ts    From lobis-frontend with MIT License 5 votes vote down vote up
readonly reserveContractAbi: ContractInterface;
Example #8
Source File: stable-bond.ts    From lobis-frontend with MIT License 5 votes vote down vote up
readonly reserveContractAbi: ContractInterface;
Example #9
Source File: bond.ts    From rugenerous-frontend with MIT License 5 votes vote down vote up
public readonly bondContractABI: ContractInterface;
Example #10
Source File: bond.ts    From rugenerous-frontend with MIT License 5 votes vote down vote up
protected abstract reserveContractAbi: ContractInterface;
Example #11
Source File: lp-bond.ts    From rugenerous-frontend with MIT License 5 votes vote down vote up
readonly reserveContractAbi: ContractInterface;
Example #12
Source File: stable-bond.ts    From rugenerous-frontend with MIT License 5 votes vote down vote up
readonly reserveContractAbi: ContractInterface;
Example #13
Source File: bond.ts    From wonderland-frontend with MIT License 5 votes vote down vote up
public readonly bondContractABI: ContractInterface;
Example #14
Source File: bond.ts    From wonderland-frontend with MIT License 5 votes vote down vote up
protected abstract reserveContractAbi: ContractInterface;
Example #15
Source File: lp-bond.ts    From wonderland-frontend with MIT License 5 votes vote down vote up
readonly reserveContractAbi: ContractInterface;
Example #16
Source File: stable-bond.ts    From wonderland-frontend with MIT License 5 votes vote down vote up
readonly reserveContractAbi: ContractInterface;