async CallContractMethod({
    contract,
    contractAddress,
    abi,
    methodName,
    methodArgs=[],
    value,
    overrides={},
    formatArguments=true,
    cacheContract=true,
    signer
  }) {
    while(this.locked) {
      await new Promise(resolve => setTimeout(resolve, 100));
    }

    this.locked = true;

    try {
      contract = contract || this.Contract({contractAddress, abi, signer, cacheContract});

      abi = contract.interface.abi;

      // Automatically format contract arguments
      if(formatArguments) {
        methodArgs = this.FormatContractArguments({
          abi,
          methodName,
          args: methodArgs
        });
      }

      if(value) {
        // Convert Ether to Wei
        overrides.value = "0x" + Utils.EtherToWei(value.toString()).toString(16);
      }

      if(contract.functions[methodName] === undefined) {
        throw Error("Unknown method: " + methodName);
      }

      let result;
      let success = false;
      while(!success) {
        try {
          result = await contract.functions[methodName](...methodArgs, overrides);
          success = true;
        } catch(error) {
          if(error.code === -32000 || error.code === "REPLACEMENT_UNDERPRICED") {
            const latestBlock = await this.MakeProviderCall({methodName: "getBlock", args: ["latest"]});
            overrides.gasLimit = latestBlock.gasLimit;
            overrides.gasPrice = overrides.gasPrice ? overrides.gasPrice * 1.50 : 8000000000;
          } else {
            throw error;
          }
        }
      }

      return result;
    } finally {
      this.locked = false;
    }
  }
// Accepts either contract object or contract address
Accepts either contract object or contract address
Accepts either contract object or contract address
async CallContractMethod({
    contract,
    contractAddress,
    abi,
    methodName,
    methodArgs=[],
    value,
    overrides={},
    formatArguments=true,
    cacheContract=true,
    signer
  }) {
    while(this.locked) {
      await new Promise(resolve => setTimeout(resolve, 100));
    }
    this.locked = true;
    try {
      contract = contract || this.Contract({contractAddress, abi, signer, cacheContract});
      abi = contract.interface.abi;
      if(formatArguments) {
        methodArgs = this.FormatContractArguments({
          abi,
          methodName,
          args: methodArgs
        });
      }
      if(value) {
        overrides.value = "0x" + Utils.EtherToWei(value.toString()).toString(16);
      }
      if(contract.functions[methodName] === undefined) {
        throw Error("Unknown method: " + methodName);
      }
      let result;
      let success = false;
      while(!success) {
        try {
          result = await contract.functions[methodName](...methodArgs, overrides);
          success = true;
        } catch(error) {
          if(error.code === -32000 || error.code === "REPLACEMENT_UNDERPRICED") {
            const latestBlock = await this.MakeProviderCall({methodName: "getBlock", args: ["latest"]});
            overrides.gasLimit = latestBlock.gasLimit;
            overrides.gasPrice = overrides.gasPrice ? overrides.gasPrice * 1.50 : 8000000000;
          } else {
            throw error;
          }
        }
      }
      return result;
    } finally {
      this.locked = false;
    }
  }
async CallContractMethod ( { contract , contractAddress , abi , methodName , methodArgs = [ ] , value , overrides = { } , formatArguments = true , cacheContract = true , signer } ) { while ( this . locked ) { await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ; } this . locked = true ; try { contract = contract || this . Contract ( { contractAddress , abi , signer , cacheContract } ) ; abi = contract . interface . abi ; if ( formatArguments ) { methodArgs = this . FormatContractArguments ( { abi , methodName , args : methodArgs } ) ; } if ( value ) { overrides . value = "0x" + Utils . EtherToWei ( value . toString ( ) ) . toString ( 16 ) ; } if ( contract . functions [ methodName ] === undefined ) { throw Error ( "Unknown method: " + methodName ) ; } let result ; let success = false ; while ( ! success ) { try { result = await contract . functions [ methodName ] ( ... methodArgs , overrides ) ; success = true ; } catch ( error ) { if ( error . code === - 32000 || error . code === "REPLACEMENT_UNDERPRICED" ) { const latestBlock = await this . MakeProviderCall ( { methodName : "getBlock" , args : [ "latest" ] } ) ; overrides . gasLimit = latestBlock . gasLimit ; overrides . gasPrice = overrides . gasPrice ? overrides . gasPrice * 1.50 : 8000000000 ; } else { throw error ; } } } return result ; } finally { this . locked = false ; } }
Accepts either contract object or contract address
Accepts either contract object or contract address
// Automatically format contract arguments // Convert Ether to Wei