text: "use strict";
  
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
  
  var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
  
  var _Array$isArray = require("@babel/runtime-corejs3/core-js-stable/array/is-array");
  
  var _getIteratorMethod = require("@babel/runtime-corejs3/core-js/get-iterator-method");
  
  var _Symbol = require("@babel/runtime-corejs3/core-js-stable/symbol");
  
  var _Array$from = require("@babel/runtime-corejs3/core-js-stable/array/from");
  
  var _sliceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
  
  _Object$defineProperty(exports, "__esModule", {
    value: true
  });
  
  exports.default = exports.EthereumEvents = void 0;
  
  var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind"));
  
  var _values = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/values"));
  
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/toConsumableArray"));
  
  var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
  
  var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
  
  var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
  
  var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
  
  var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
  
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
  
  var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
  
  var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
  
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
  
  var _construct2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/construct"));
  
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
  
  var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
  
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
  
  var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
  
  var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
  
  var _web = _interopRequireDefault(require("web3"));
  
  var _ParseObject = _interopRequireDefault(require("./ParseObject"));
  
  var _ParseQuery = _interopRequireDefault(require("./ParseQuery"));
  
  var _ParseUser = _interopRequireDefault(require("./ParseUser"));
  
  var _ParseACL = _interopRequireDefault(require("./ParseACL"));
  
  var _MoralisErd = _interopRequireDefault(require("./MoralisErd"));
  
  var _MoralisDot = _interopRequireDefault(require("./MoralisDot"));
  
  var _MoralisWalletConnectProvider = _interopRequireDefault(require("./MoralisWalletConnectProvider"));
  
  var _MoralisInjectedProvider = _interopRequireDefault(require("./MoralisInjectedProvider"));
  
  var _TransferUtils = _interopRequireDefault(require("./TransferUtils"));
  
  var _Cloud = require("./Cloud");
  
  var _detectProvider = _interopRequireDefault(require("@metamask/detect-provider"));
  
  var _createSigningData = _interopRequireDefault(require("./createSigningData"));
  
  var _context28, _context29, _context30, _context31;
  
  function _createForOfIteratorHelper(o, allowArrayLike) {
    var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"];
  
    if (!it) {
      if (_Array$isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
        if (it) o = it;
        var i = 0;
  
        var F = function () {};
  
        return {
          s: F,
          n: function () {
            if (i >= o.length) return {
              done: true
            };
            return {
              done: false,
              value: o[i++]
            };
          },
          e: function (_e) {
            throw _e;
          },
          f: F
        };
      }
  
      throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
    }
  
    var normalCompletion = true,
        didErr = false,
        err;
    return {
      s: function () {
        it = it.call(o);
      },
      n: function () {
        var step = it.next();
        normalCompletion = step.done;
        return step;
      },
      e: function (_e2) {
        didErr = true;
        err = _e2;
      },
      f: function () {
        try {
          if (!normalCompletion && it.return != null) it.return();
        } finally {
          if (didErr) throw err;
        }
      }
    };
  }
  
  function _unsupportedIterableToArray(o, minLen) {
    var _context32;
  
    if (!o) return;
    if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  
    var n = _sliceInstanceProperty(_context32 = Object.prototype.toString.call(o)).call(_context32, 8, -1);
  
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return _Array$from(o);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  }
  
  function _arrayLikeToArray(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
  
    for (var i = 0, arr2 = new Array(len); i < len; i++) {
      arr2[i] = arr[i];
    }
  
    return arr2;
  }
  
  var EventEmitter = require('events');
  
  var EthereumEvents = {
    CONNECT: 'connect',
    DISCONNECT: 'disconnect',
    ACCOUNTS_CHANGED: 'accountsChanged',
    CHAIN_CHANGED: 'chainChanged'
  };
  exports.EthereumEvents = EthereumEvents;
  var WARNING = 'Non ethereum enabled browser';
  var ERROR_WEB3_MISSING = 'Missing web3 instance, make sure to call Moralis.enableWeb3() or Moralis.authenticate()';
  
  function uniq(arr) {
    return (0, _filter.default)(arr).call(arr, function (v, i) {
      return (0, _indexOf.default)(arr).call(arr, v) === i;
    });
  }
  
  var MoralisWeb3 = /*#__PURE__*/function () {
    function MoralisWeb3() {
      (0, _classCallCheck2.default)(this, MoralisWeb3);
      var MWeb3 = typeof _web.default === 'function' ? _web.default : window.Web3;
  
      for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }
  
      return (0, _construct2.default)(MWeb3, args);
    }
  
    (0, _createClass2.default)(MoralisWeb3, null, [{
      key: "isWeb3Enabled",
      value: function () {
        return this.ensureWeb3IsInstalled();
      }
    }, {
      key: "setEnableWeb3",
      value: function (fn) {
        this.customEnableWeb3 = fn;
      }
    }, {
      key: "enableWeb3",
      value: function () {
        var _enableWeb = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(options) {
          var web3, Web3Provider, web3Provider;
          return _regenerator.default.wrap(function (_context) {
            while (1) {
              switch (_context.prev = _context.next) {
                case 0:
                  if (!this.customEnableWeb3) {
                    _context.next = 6;
                    break;
                  }
  
                  _context.next = 3;
                  return this.customEnableWeb3(options);
  
                case 3:
                  web3 = _context.sent;
                  _context.next = 12;
                  break;
  
                case 6:
                  Web3Provider = MoralisWeb3.getWeb3Provider(options);
                  web3Provider = new Web3Provider();
                  this.activeWeb3Provider = web3Provider;
                  _context.next = 11;
                  return web3Provider.activate(options);
  
                case 11:
                  web3 = _context.sent;
  
                case 12:
                  this.web3 = web3;
                  return _context.abrupt("return", web3);
  
                case 14:
                case "end":
                  return _context.stop();
              }
            }
          }, _callee, this);
        }));
  
        return function () {
          return _enableWeb.apply(this, arguments);
        };
      }()
    }, {
      key: "enable",
      value: function () {
        var _enable = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(options) {
          return _regenerator.default.wrap(function (_context2) {
            while (1) {
              switch (_context2.prev = _context2.next) {
                case 0:
                  // eslint-disable-next-line no-console
                  console.warn('Moralis.enable() is deprecated and will be removed, use Moralis.enableWeb3() instead.');
                  return _context2.abrupt("return", this.enableWeb3(options));
  
                case 2:
                case "end":
                  return _context2.stop();
              }
            }
          }, _callee2, this);
        }));
  
        return function () {
          return _enable.apply(this, arguments);
        };
      }()
    }, {
      key: "isDotAuth",
      value: function (options) {
        switch (options === null || options === void 0 ? void 0 : options.type) {
          case 'dot':
          case 'polkadot':
          case 'kusama':
            return true;
  
          default:
            return false;
        }
      }
    }, {
      key: "isElrondAuth",
      value: function (options) {
        switch (options === null || options === void 0 ? void 0 : options.type) {
          case 'erd':
          case 'elrond':
            return true;
  
          default:
            return false;
        }
      }
    }, {
      key: "getWeb3Provider",
      value: function (options) {
        switch (options === null || options === void 0 ? void 0 : options.provider) {
          case 'walletconnect':
          case 'walletConnect':
          case 'wc':
            return _MoralisWalletConnectProvider.default;
  
          default:
            return _MoralisInjectedProvider.default;
        }
      }
    }, {
      key: "cleanup",
      value: function () {
        var _cleanup = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
          return _regenerator.default.wrap(function (_context3) {
            while (1) {
              switch (_context3.prev = _context3.next) {
                case 0:
                  if (!this.activeWeb3Provider) {
                    _context3.next = 3;
                    break;
                  }
  
                  _context3.next = 3;
                  return this.activeWeb3Provider.deactivate();
  
                case 3:
                  // Prevent a bug when there is stale data active
                  _MoralisWalletConnectProvider.default.cleanupStaleData();
  
                case 4:
                case "end":
                  return _context3.stop();
              }
            }
          }, _callee3, this);
        }));
  
        return function () {
          return _cleanup.apply(this, arguments);
        };
      }()
    }, {
      key: "authenticate",
      value: function () {
        var _authenticate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(options) {
          var _context4, _user$get;
  
          var isLoggedIn, web3, message, data, accounts, accountsLower, _accountsLower, ethAddress, signature, authData, user;
  
          return _regenerator.default.wrap(function (_context5) {
            while (1) {
              switch (_context5.prev = _context5.next) {
                case 0:
                  _context5.next = 2;
                  return _ParseUser.default.currentAsync();
  
                case 2:
                  isLoggedIn = _context5.sent;
  
                  if (!isLoggedIn) {
                    _context5.next = 6;
                    break;
                  }
  
                  _context5.next = 6;
                  return _ParseUser.default.logOut();
  
                case 6:
                  _context5.next = 8;
                  return MoralisWeb3.cleanup();
  
                case 8:
                  if (!MoralisWeb3.isDotAuth(options)) {
                    _context5.next = 10;
                    break;
                  }
  
                  return _context5.abrupt("return", _MoralisDot.default.authenticate(options));
  
                case 10:
                  if (!MoralisWeb3.isElrondAuth(options)) {
                    _context5.next = 12;
                    break;
                  }
  
                  return _context5.abrupt("return", _MoralisErd.default.authenticate(options));
  
                case 12:
                  _context5.next = 14;
                  return this.enableWeb3(options);
  
                case 14:
                  web3 = _context5.sent;
                  message = (options === null || options === void 0 ? void 0 : options.signingMessage) || MoralisWeb3.getSigningData();
                  _context5.next = 18;
                  return (0, _createSigningData.default)(message);
  
                case 18:
                  data = _context5.sent;
                  _context5.next = 21;
                  return web3.eth.getAccounts();
  
                case 21:
                  accounts = _context5.sent;
                  accountsLower = (0, _map.default)(accounts).call(accounts, function (v) {
                    return v.toLowerCase();
                  });
                  _accountsLower = (0, _slicedToArray2.default)(accountsLower, 1), ethAddress = _accountsLower[0];
  
                  if (ethAddress) {
                    _context5.next = 26;
                    break;
                  }
  
                  throw new Error('Address not found');
  
                case 26:
                  _context5.next = 28;
                  return web3.eth.personal.sign(data, ethAddress, '');
  
                case 28:
                  signature = _context5.sent;
  
                  if (signature) {
                    _context5.next = 31;
                    break;
                  }
  
                  throw new Error('Data not signed');
  
                case 31:
                  authData = {
                    id: ethAddress,
                    signature: signature,
                    data: data
                  };
                  _context5.next = 34;
                  return _ParseUser.default.logInWith('moralisEth', {
                    authData: authData
                  });
  
                case 34:
                  user = _context5.sent;
                  _context5.next = 37;
                  return user.setACL(new _ParseACL.default(user));
  
                case 37:
                  if (user) {
                    _context5.next = 39;
                    break;
                  }
  
                  throw new Error('Could not get user');
  
                case 39:
                  user.set('accounts', uniq((0, _concat.default)(_context4 = []).call(_context4, accountsLower, (_user$get = user.get('accounts')) !== null && _user$get !== void 0 ? _user$get : [])));
                  user.set('ethAddress', ethAddress);
                  _context5.next = 43;
                  return user.save(null, options);
  
                case 43:
                  return _context5.abrupt("return", user);
  
                case 44:
                case "end":
                  return _context5.stop();
              }
            }
          }, _callee4, this);
        }));
  
        return function () {
          return _authenticate.apply(this, arguments);
        };
      }()
    }, {
      key: "link",
      value: function () {
        var _link = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(account, options) {
          var _context6, _user$get2;
  
          var web3, data, user, ethAddress, EthAddress, query, ethAddressRecord, signature, authData;
          return _regenerator.default.wrap(function (_context7) {
            while (1) {
              switch (_context7.prev = _context7.next) {
                case 0:
                  _context7.next = 2;
                  return MoralisWeb3.enableWeb3(options);
  
                case 2:
                  web3 = _context7.sent;
                  data = (options === null || options === void 0 ? void 0 : options.signingMessage) || MoralisWeb3.getSigningData();
                  _context7.next = 6;
                  return _ParseUser.default.currentAsync();
  
                case 6:
                  user = _context7.sent;
                  ethAddress = account.toLowerCase();
                  EthAddress = _ParseObject.default.extend('_EthAddress');
                  query = new _ParseQuery.default(EthAddress);
                  _context7.next = 12;
                  return query.get(ethAddress).catch(function () {
                    return null;
                  });
  
                case 12:
                  ethAddressRecord = _context7.sent;
  
                  if (ethAddressRecord) {
                    _context7.next = 20;
                    break;
                  }
  
                  _context7.next = 16;
                  return web3.eth.personal.sign(data, account, '');
  
                case 16:
                  signature = _context7.sent;
                  authData = {
                    id: ethAddress,
                    signature: signature,
                    data: data
                  };
                  _context7.next = 20;
                  return user.linkWith('moralisEth', {
                    authData: authData
                  });
  
                case 20:
                  user.set('accounts', uniq((0, _concat.default)(_context6 = [ethAddress]).call(_context6, (_user$get2 = user.get('accounts')) !== null && _user$get2 !== void 0 ? _user$get2 : [])));
                  user.set('ethAddress', ethAddress);
                  _context7.next = 24;
                  return user.save(null, options);
  
                case 24:
                  return _context7.abrupt("return", user);
  
                case 25:
                case "end":
                  return _context7.stop();
              }
            }
          }, _callee5);
        }));
  
        return function () {
          return _link.apply(this, arguments);
        };
      }()
    }, {
      key: "unlink",
      value: function () {
        var _unlink = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(account) {
          var _user$get3;
  
          var accountsLower, EthAddress, query, ethAddressRecord, user, accounts, nextAccounts;
          return _regenerator.default.wrap(function (_context8) {
            while (1) {
              switch (_context8.prev = _context8.next) {
                case 0:
                  accountsLower = account.toLowerCase();
                  EthAddress = _ParseObject.default.extend('_EthAddress');
                  query = new _ParseQuery.default(EthAddress);
                  _context8.next = 5;
                  return query.get(accountsLower);
  
                case 5:
                  ethAddressRecord = _context8.sent;
                  _context8.next = 8;
                  return ethAddressRecord.destroy();
  
                case 8:
                  _context8.next = 10;
                  return _ParseUser.default.currentAsync();
  
                case 10:
                  user = _context8.sent;
                  accounts = (_user$get3 = user.get('accounts')) !== null && _user$get3 !== void 0 ? _user$get3 : [];
                  nextAccounts = (0, _filter.default)(accounts).call(accounts, function (v) {
                    return v !== accountsLower;
                  });
                  user.set('accounts', nextAccounts);
                  user.set('ethAddress', nextAccounts[0]);
                  _context8.next = 17;
                  return user._unlinkFrom('moralisEth');
  
                case 17:
                  _context8.next = 19;
                  return user.save();
  
                case 19:
                  return _context8.abrupt("return", user);
  
                case 20:
                case "end":
                  return _context8.stop();
              }
            }
          }, _callee6);
        }));
  
        return function () {
          return _unlink.apply(this, arguments);
        };
      }()
    }, {
      key: "initPlugins",
      value: function () {
        var _initPlugins = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(installedPlugins) {
          var _this = this;
  
          var specs, allPlugins;
          return _regenerator.default.wrap(function (_context12) {
            while (1) {
              switch (_context12.prev = _context12.next) {
                case 0:
                  _context12.t0 = installedPlugins;
  
                  if (_context12.t0) {
                    _context12.next = 5;
                    break;
                  }
  
                  _context12.next = 4;
                  return (0, _Cloud.run)('getPluginSpecs');
  
                case 4:
                  _context12.t0 = _context12.sent;
  
                case 5:
                  specs = _context12.t0;
                  if (!this.Plugins) this.Plugins = {};
  
                  if (specs) {
                    _context12.next = 9;
                    break;
                  }
  
                  return _context12.abrupt("return");
  
                case 9:
                  allPlugins = this.Plugins;
                  (0, _forEach.default)(specs).call(specs, function (plugin) {
                    var _context9;
  
                    allPlugins[plugin.name] = {};
                    (0, _forEach.default)(_context9 = plugin.functions).call(_context9, function (f) {
                      allPlugins[plugin.name][f] = /*#__PURE__*/function () {
                        var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(params, options) {
                          var _context10;
  
                          var response, error, triggerReturn;
                          return _regenerator.default.wrap(function (_context11) {
                            while (1) {
                              switch (_context11.prev = _context11.next) {
                                case 0:
                                  if (!options) options = {};
                                  _context11.next = 3;
                                  return (0, _Cloud.run)((0, _concat.default)(_context10 = "".concat(plugin.name, "_")).call(_context10, f), params);
  
                                case 3:
                                  response = _context11.sent;
  
                                  if (response.data.success) {
                                    _context11.next = 7;
                                    break;
                                  }
  
                                  error = (0, _stringify.default)(response.data.data, null, 2);
                                  throw new Error("Something went wrong\n".concat(error));
  
                                case 7:
                                  if (!(options.disableTriggers !== true)) {
                                    _context11.next = 13;
                                    break;
                                  }
  
                                  _context11.next = 10;
                                  return _this.handleTriggers(response.data.result.triggers, response.data.result.data);
  
                                case 10:
                                  triggerReturn = _context11.sent;
  
                                  if (!triggerReturn) {
                                    _context11.next = 13;
                                    break;
                                  }
  
                                  return _context11.abrupt("return", triggerReturn);
  
                                case 13:
                                  return _context11.abrupt("return", response.data.result);
  
                                case 14:
                                case "end":
                                  return _context11.stop();
                              }
                            }
                          }, _callee7);
                        }));
  
                        return function () {
                          return _ref.apply(this, arguments);
                        };
                      }();
                    });
                  });
                  this.Plugins = allPlugins;
  
                case 12:
                case "end":
                  return _context12.stop();
              }
            }
          }, _callee8, this);
        }));
  
        return function () {
          return _initPlugins.apply(this, arguments);
        };
      }()
    }, {
      key: "handleTriggers",
      value: function () {
        var _handleTriggers = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(triggersArray, payload) {
          var _this2 = this;
  
          var response, _loop, i, _ret;
  
          return _regenerator.default.wrap(function (_context18) {
            while (1) {
              switch (_context18.prev = _context18.next) {
                case 0:
                  if (triggersArray) {
                    _context18.next = 2;
                    break;
                  }
  
                  return _context18.abrupt("return");
  
                case 2:
                  _loop = /*#__PURE__*/_regenerator.default.mark(function _loop(i) {
                    var _triggersArray$i, _triggersArray$i2, _triggersArray$i2$opt, _triggersArray$i3, _triggersArray$i3$opt, _triggersArray$i4, _triggersArray$i5, _triggersArray$i5$opt, _triggersArray$i6, _triggersArray$i7, _triggersArray$i8, _triggersArray$i9, _triggersArray$i10, _triggersArray$i11, _triggersArray$i12, _triggersArray$i13, _triggersArray$i14, _triggersArray$i15, _triggersArray$i16, _triggersArray$i17, _triggersArray$i18, _triggersArray$i19, _triggersArray$i20, _triggersArray$i21, _triggersArray$i22, _triggersArray$i23, _triggersArray$i24, _triggersArray$i25, _triggersArray$i27, _triggersArray$i29, _triggersArray$i30, _triggersArray$i31;
  
                    var _context13, _context14;
  
                    return _regenerator.default.wrap(function (_context17) {
                      while (1) {
                        switch (_context17.prev = _context17.next) {
                          case 0:
                            _context17.t0 = (_triggersArray$i = triggersArray[i]) === null || _triggersArray$i === void 0 ? void 0 : _triggersArray$i.name;
                            _context17.next = _context17.t0 === 'openUrl' ? 3 : _context17.t0 === 'web3Transaction' ? 6 : _context17.t0 === 'web3Sign' ? 19 : _context17.t0 === 'callPluginEndpoint' ? 36 : _context17.t0 === 'web3SignV4' ? 58 : 73;
                            break;
  
                          case 3:
                            // Open url in a new tab
                            if (((_triggersArray$i2 = triggersArray[i]) === null || _triggersArray$i2 === void 0 ? void 0 : (_triggersArray$i2$opt = _triggersArray$i2.options) === null || _triggersArray$i2$opt === void 0 ? void 0 : _triggersArray$i2$opt.newTab) === true || !((_triggersArray$i3 = triggersArray[i]) !== null && _triggersArray$i3 !== void 0 && (_triggersArray$i3$opt = _triggersArray$i3.options) !== null && _triggersArray$i3$opt !== void 0 && _triggersArray$i3$opt.hasOwnProperty('newTab'))) window.open((_triggersArray$i4 = triggersArray[i]) === null || _triggersArray$i4 === void 0 ? void 0 : _triggersArray$i4.data); // Open url in the same tab
  
                            if (((_triggersArray$i5 = triggersArray[i]) === null || _triggersArray$i5 === void 0 ? void 0 : (_triggersArray$i5$opt = _triggersArray$i5.options) === null || _triggersArray$i5$opt === void 0 ? void 0 : _triggersArray$i5$opt.newTab) === false) window.open((_triggersArray$i6 = triggersArray[i]) === null || _triggersArray$i6 === void 0 ? void 0 : _triggersArray$i6.data, '_self');
                            return _context17.abrupt("break", 74);
  
                          case 6:
                            if (_this2.ensureWeb3IsInstalled()) {
                              _context17.next = 8;
                              break;
                            }
  
                            throw new Error(ERROR_WEB3_MISSING);
  
                          case 8:
                            if (!(((_triggersArray$i7 = triggersArray[i]) === null || _triggersArray$i7 === void 0 ? void 0 : _triggersArray$i7.shouldAwait) === true)) {
                              _context17.next = 12;
                              break;
                            }
  
                            _context17.next = 11;
                            return _this2.web3.eth.sendTransaction((_triggersArray$i8 = triggersArray[i]) === null || _triggersArray$i8 === void 0 ? void 0 : _triggersArray$i8.data);
  
                          case 11:
                            response = _context17.sent;
  
                          case 12:
                            // Trigger a web3 transaction (does NOT await)
                            if (((_triggersArray$i9 = triggersArray[i]) === null || _triggersArray$i9 === void 0 ? void 0 : _triggersArray$i9.shouldAwait) === false) response = _this2.web3.eth.sendTransaction((_triggersArray$i10 = triggersArray[i]) === null || _triggersArray$i10 === void 0 ? void 0 : _triggersArray$i10.data); // Save the response returned by the web3 trasanction
  
                            if (((_triggersArray$i11 = triggersArray[i]) === null || _triggersArray$i11 === void 0 ? void 0 : _triggersArray$i11.saveResponse) === true) _this2.memoryCard.save(response); // Return payload and response
  
                            if (!(((_triggersArray$i12 = triggersArray[i]) === null || _triggersArray$i12 === void 0 ? void 0 : _triggersArray$i12.shouldReturnPayload) === true)) {
                              _context17.next = 16;
                              break;
                            }
  
                            return _context17.abrupt("return", {
                              v: {
                                payload: payload,
                                response: response
                              }
                            });
  
                          case 16:
                            if (!(((_triggersArray$i13 = triggersArray[i]) === null || _triggersArray$i13 === void 0 ? void 0 : _triggersArray$i13.shouldReturnResponse) === true)) {
                              _context17.next = 18;
                              break;
                            }
  
                            return _context17.abrupt("return", {
                              v: response
                            });
  
                          case 18:
                            return _context17.abrupt("break", 74);
  
                          case 19:
                            if (_this2.ensureWeb3IsInstalled()) {
                              _context17.next = 21;
                              break;
                            }
  
                            throw new Error(ERROR_WEB3_MISSING);
  
                          case 21:
                            if (triggersArray[i].message) {
                              _context17.next = 23;
                              break;
                            }
  
                            throw new Error('web3Sign trigger does not have a message to sign');
  
                          case 23:
                            if (!(!triggersArray[i].signer || !_this2.web3.utils.isAddress(triggersArray[i].signer))) {
                              _context17.next = 25;
                              break;
                            }
  
                            throw new Error('web3Sign trigger signer address missing or invalid');
  
                          case 25:
                            if (!(((_triggersArray$i14 = triggersArray[i]) === null || _triggersArray$i14 === void 0 ? void 0 : _triggersArray$i14.shouldAwait) === true)) {
                              _context17.next = 29;
                              break;
                            }
  
                            _context17.next = 28;
                            return _this2.web3.eth.personal.sign(triggersArray[i].message, triggersArray[i].signer);
  
                          case 28:
                            response = _context17.sent;
  
                          case 29:
                            // Sign a message using web3 (does NOT await)
                            if (((_triggersArray$i15 = triggersArray[i]) === null || _triggersArray$i15 === void 0 ? void 0 : _triggersArray$i15.shouldAwait) === false) response = _this2.web3.eth.personal.sign(triggersArray[i].message, triggersArray[i].signer); // Save response
  
                            if (((_triggersArray$i16 = triggersArray[i]) === null || _triggersArray$i16 === void 0 ? void 0 : _triggersArray$i16.saveResponse) === true) _this2.memoryCard.save(response); // Return payload and response
  
                            if (!(((_triggersArray$i17 = triggersArray[i]) === null || _triggersArray$i17 === void 0 ? void 0 : _triggersArray$i17.shouldReturnPayload) === true)) {
                              _context17.next = 33;
                              break;
                            }
  
                            return _context17.abrupt("return", {
                              v: {
                                payload: payload,
                                response: response
                              }
                            });
  
                          case 33:
                            if (!(((_triggersArray$i18 = triggersArray[i]) === null || _triggersArray$i18 === void 0 ? void 0 : _triggersArray$i18.shouldReturnResponse) === true)) {
                              _context17.next = 35;
                              break;
                            }
  
                            return _context17.abrupt("return", {
                              v: response
                            });
  
                          case 35:
                            return _context17.abrupt("break", 74);
  
                          case 36:
                            if (triggersArray[i].pluginName) {
                              _context17.next = 38;
                              break;
                            }
  
                            throw new Error('callPluginEndpoint trigger does not have an plugin name to call');
  
                          case 38:
                            if (triggersArray[i].endpoint) {
                              _context17.next = 40;
                              break;
                            }
  
                            throw new Error('callPluginEndpoint trigger does not have an endpoint to call');
  
                          case 40:
                            if (!(((_triggersArray$i19 = triggersArray[i]) === null || _triggersArray$i19 === void 0 ? void 0 : _triggersArray$i19.shouldAwait) === true)) {
                              _context17.next = 45;
                              break;
                            } // Check if a saved response has to be used to fill a parameter needed by the plugin
  
  
                            if (triggersArray[i].useSavedResponse === true) {
                              triggersArray[i].params[triggersArray[i].savedResponseAs] = _this2.memoryCard.get(triggersArray[i].savedResponseAt);
                            } // Call the endpoint
  
  
                            _context17.next = 44;
                            return (0, _Cloud.run)((0, _concat.default)(_context13 = "".concat(triggersArray[i].pluginName, "_")).call(_context13, triggersArray[i].endpoint), triggersArray[i].params);
  
                          case 44:
                            response = _context17.sent;
  
                          case 45:
                            // Call a plugin endpoint (does NOT await)
                            if (((_triggersArray$i20 = triggersArray[i]) === null || _triggersArray$i20 === void 0 ? void 0 : _triggersArray$i20.shouldAwait) === false) {
                              // Check if a saved response has to be used to fill a parameter needed by the plugin
                              if (triggersArray[i].useSavedResponse === true) {
                                triggersArray[i].params[triggersArray[i].savedResponseAs] = _this2.memoryCard.get(triggersArray[i].savedResponseAt);
                              } // Call the endpoint
  
  
                              response = (0, _Cloud.run)((0, _concat.default)(_context14 = "".concat(triggersArray[i].pluginName, "_")).call(_context14, triggersArray[i].endpoint), triggersArray[i].params);
                            } // If the response contains a trigger, run it
  
  
                            if (!(triggersArray[i].runResponseTrigger === true)) {
                              _context17.next = 50;
                              break;
                            }
  
                            _context17.next = 49;
                            return _this2.handleTriggers(response.data.result.triggers, response.data.result.data);
  
                          case 49:
                            response = _context17.sent;
  
                          case 50:
                            // Save response
                            if (((_triggersArray$i21 = triggersArray[i]) === null || _triggersArray$i21 === void 0 ? void 0 : _triggersArray$i21.saveResponse) === true) _this2.memoryCard.save(response); // If should not run the response trigger, continues the loop and does not return (to avoid breaking the loop execution and run other pending triggers)
  
                            if (!(((_triggersArray$i22 = triggersArray[i]) === null || _triggersArray$i22 === void 0 ? void 0 : _triggersArray$i22.runResponseTrigger) === false)) {
                              _context17.next = 53;
                              break;
                            }
  
                            return _context17.abrupt("return", "continue");
  
                          case 53:
                            if (!(((_triggersArray$i23 = triggersArray[i]) === null || _triggersArray$i23 === void 0 ? void 0 : _triggersArray$i23.shouldReturnPayload) === true)) {
                              _context17.next = 55;
                              break;
                            }
  
                            return _context17.abrupt("return", {
                              v: {
                                payload: 'payload',
                                response: response
                              }
                            });
  
                          case 55:
                            if (!(((_triggersArray$i24 = triggersArray[i]) === null || _triggersArray$i24 === void 0 ? void 0 : _triggersArray$i24.shouldReturnResponse) === true)) {
                              _context17.next = 57;
                              break;
                            }
  
                            return _context17.abrupt("return", {
                              v: response
                            });
  
                          case 57:
                            return _context17.abrupt("break", 74);
  
                          case 58:
                            if (_this2.ensureWeb3IsInstalled()) {
                              _context17.next = 60;
                              break;
                            }
  
                            throw new Error(ERROR_WEB3_MISSING);
  
                          case 60:
                            if (triggersArray[i].parameters) {
                              _context17.next = 62;
                              break;
                            }
  
                            throw new Error('web3SignV4 trigger does not have `parameters` to sign');
  
                          case 62:
                            if (triggersArray[i].from) {
                              _context17.next = 64;
                              break;
                            }
  
                            throw new Error('web3SignV4 trigger does not have a `from` address');
  
                          case 64:
                            if (!(((_triggersArray$i25 = triggersArray[i]) === null || _triggersArray$i25 === void 0 ? void 0 : _triggersArray$i25.shouldAwait) === true)) {
                              _context17.next = 67;
                              break;
                            }
  
                            _context17.next = 67;
                            return _this2.web3.currentProvider.send({
                              method: 'eth_signTypedData_v4',
                              params: triggersArray[i].parameters,
                              from: triggersArray[i].from
                            },
                            /*#__PURE__*/
                            // eslint-disable-next-line no-loop-func
                            function () {
                              var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(error, result) {
                                var _triggersArray$i26;
  
                                return _regenerator.default.wrap(function (_context15) {
                                  while (1) {
                                    switch (_context15.prev = _context15.next) {
                                      case 0:
                                        if (!error) {
                                          _context15.next = 2;
                                          break;
                                        }
  
                                        throw new Error(error.message || error);
  
                                      case 2:
                                        // Save response
                                        if (((_triggersArray$i26 = triggersArray[i]) === null || _triggersArray$i26 === void 0 ? void 0 : _triggersArray$i26.saveResponse) === true) _this2.memoryCard.save(result);
                                        response = result;
  
                                      case 4:
                                      case "end":
                                        return _context15.stop();
                                    }
                                  }
                                }, _callee9);
                              }));
  
                              return function () {
                                return _ref2.apply(this, arguments);
                              };
                            }());
  
                          case 67:
                            if (((_triggersArray$i27 = triggersArray[i]) === null || _triggersArray$i27 === void 0 ? void 0 : _triggersArray$i27.shouldAwait) === false) {
                              _this2.web3.currentProvider.send({
                                method: 'eth_signTypedData_v4',
                                params: triggersArray[i].parameters,
                                from: triggersArray[i].from
                              },
                              /*#__PURE__*/
                              // eslint-disable-next-line no-loop-func
                              function () {
                                var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(error, result) {
                                  var _triggersArray$i28;
  
                                  return _regenerator.default.wrap(function (_context16) {
                                    while (1) {
                                      switch (_context16.prev = _context16.next) {
                                        case 0:
                                          if (!error) {
                                            _context16.next = 2;
                                            break;
                                          }
  
                                          throw new Error(error.message || error);
  
                                        case 2:
                                          // Save response
                                          if (((_triggersArray$i28 = triggersArray[i]) === null || _triggersArray$i28 === void 0 ? void 0 : _triggersArray$i28.saveResponse) === true) _this2.memoryCard.save(result);
                                          response = result;
  
                                        case 4:
                                        case "end":
                                          return _context16.stop();
                                      }
                                    }
                                  }, _callee10);
                                }));
  
                                return function () {
                                  return _ref3.apply(this, arguments);
                                };
                              }());
                            } // Return payload and response
  
  
                            if (!(((_triggersArray$i29 = triggersArray[i]) === null || _triggersArray$i29 === void 0 ? void 0 : _triggersArray$i29.shouldReturnPayload) === true)) {
                              _context17.next = 70;
                              break;
                            }
  
                            return _context17.abrupt("return", {
                              v: {
                                payload: payload,
                                response: response
                              }
                            });
  
                          case 70:
                            if (!(((_triggersArray$i30 = triggersArray[i]) === null || _triggersArray$i30 === void 0 ? void 0 : _triggersArray$i30.shouldReturnResponse) === true)) {
                              _context17.next = 72;
                              break;
                            }
  
                            return _context17.abrupt("return", {
                              v: response
                            });
  
                          case 72:
                            return _context17.abrupt("break", 74);
  
                          case 73:
                            throw new Error("Unknown trigger: \"".concat((_triggersArray$i31 = triggersArray[i]) === null || _triggersArray$i31 === void 0 ? void 0 : _triggersArray$i31.name, "\""));
  
                          case 74:
                          case "end":
                            return _context17.stop();
                        }
                      }
                    }, _loop);
                  });
                  i = 0;
  
                case 4:
                  if (!(i < triggersArray.length)) {
                    _context18.next = 14;
                    break;
                  }
  
                  return _context18.delegateYield(_loop(i), "t0", 6);
  
                case 6:
                  _ret = _context18.t0;
  
                  if (!(_ret === "continue")) {
                    _context18.next = 9;
                    break;
                  }
  
                  return _context18.abrupt("continue", 11);
  
                case 9:
                  if (!((0, _typeof2.default)(_ret) === "object")) {
                    _context18.next = 11;
                    break;
                  }
  
                  return _context18.abrupt("return", _ret.v);
  
                case 11:
                  i++;
                  _context18.next = 4;
                  break;
  
                case 14:
                  // Delete all saved data
                  this.memoryCard.deleteSaved();
  
                case 15:
                case "end":
                  return _context18.stop();
              }
            }
          }, _callee11, this);
        }));
  
        return function () {
          return _handleTriggers.apply(this, arguments);
        };
      }()
    }, {
      key: "getAllERC20",
      value: function () {
        var _getAllERC = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12() {
          var _ref4,
              chain,
              address,
              result,
              _args13 = arguments;
  
          return _regenerator.default.wrap(function (_context19) {
            while (1) {
              switch (_context19.prev = _context19.next) {
                case 0:
                  _ref4 = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {}, chain = _ref4.chain, address = _ref4.address;
                  _context19.next = 3;
                  return (0, _Cloud.run)('getAllERC20', {
                    chain: chain,
                    address: address
                  });
  
                case 3:
                  result = _context19.sent;
                  return _context19.abrupt("return", result);
  
                case 5:
                case "end":
                  return _context19.stop();
              }
            }
          }, _callee12);
        }));
  
        return function () {
          return _getAllERC.apply(this, arguments);
        };
      }()
    }, {
      key: "getERC20",
      value: function () {
        var _getERC = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13() {
          var _ref5,
              chain,
              address,
              symbol,
              tokenAddress,
              result,
              _args14 = arguments;
  
          return _regenerator.default.wrap(function (_context20) {
            while (1) {
              switch (_context20.prev = _context20.next) {
                case 0:
                  _ref5 = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : {}, chain = _ref5.chain, address = _ref5.address, symbol = _ref5.symbol, tokenAddress = _ref5.tokenAddress;
                  result = (0, _Cloud.run)('getERC20', {
                    chain: chain,
                    address: address,
                    symbol: symbol,
                    tokenAddress: tokenAddress
                  });
                  return _context20.abrupt("return", result);
  
                case 3:
                case "end":
                  return _context20.stop();
              }
            }
          }, _callee13);
        }));
  
        return function () {
          return _getERC.apply(this, arguments);
        };
      }()
    }, {
      key: "getNFTs",
      value: function () {
        var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
            _ref6$chain = _ref6.chain,
            chain = _ref6$chain === void 0 ? 'Eth' : _ref6$chain,
            _ref6$address = _ref6.address,
            address = _ref6$address === void 0 ? '' : _ref6$address;
  
        return (0, _Cloud.run)('getNFTs_old', {
          chain: chain,
          address: address
        });
      }
    }, {
      key: "getNFTsCount",
      value: function () {
        var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
            _ref7$chain = _ref7.chain,
            chain = _ref7$chain === void 0 ? 'Eth' : _ref7$chain,
            _ref7$address = _ref7.address,
            address = _ref7$address === void 0 ? '' : _ref7$address;
  
        return (0, _Cloud.run)('getNFTsCount_old', {
          chain: chain,
          address: address
        });
      }
    }, {
      key: "getTransactions",
      value: function () {
        var _ref8 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
            _ref8$chain = _ref8.chain,
            chain = _ref8$chain === void 0 ? 'Eth' : _ref8$chain,
            _ref8$address = _ref8.address,
            address = _ref8$address === void 0 ? '' : _ref8$address,
            _ref8$order = _ref8.order,
            order = _ref8$order === void 0 ? 'desc' : _ref8$order;
  
        return (0, _Cloud.run)('getTransactions', {
          chain: chain,
          address: address,
          order: order
        });
      }
    }, {
      key: "getTransactionsCount",
      value: function () {
        var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
            _ref9$chain = _ref9.chain,
            chain = _ref9$chain === void 0 ? 'Eth' : _ref9$chain,
            _ref9$address = _ref9.address,
            address = _ref9$address === void 0 ? '' : _ref9$address;
  
        return (0, _Cloud.run)('getTransactionsCount', {
          chain: chain,
          address: address
        });
      }
    }, {
      key: "transfer",
      value: function () {
        var _transfer = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14() {
          var _ref10,
              _ref10$type,
              type,
              _ref10$receiver,
              receiver,
              _ref10$contractAddres,
              contractAddress,
              contract_address,
              _ref10$amount,
              amount,
              _ref10$tokenId,
              tokenId,
              token_id,
              _ref10$system,
              system,
              _ref10$awaitReceipt,
              awaitReceipt,
              options,
              web3,
              sender,
              transferOperation,
              customToken,
              transferEvents,
              _args15 = arguments;
  
          return _regenerator.default.wrap(function (_context21) {
            while (1) {
              switch (_context21.prev = _context21.next) {
                case 0:
                  _ref10 = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : {}, _ref10$type = _ref10.type, type = _ref10$type === void 0 ? 'native' : _ref10$type, _ref10$receiver = _ref10.receiver, receiver = _ref10$receiver === void 0 ? '' : _ref10$receiver, _ref10$contractAddres = _ref10.contractAddress, contractAddress = _ref10$contractAddres === void 0 ? '' : _ref10$contractAddres, contract_address = _ref10.contract_address, _ref10$amount = _ref10.amount, amount = _ref10$amount === void 0 ? '' : _ref10$amount, _ref10$tokenId = _ref10.tokenId, tokenId = _ref10$tokenId === void 0 ? '' : _ref10$tokenId, token_id = _ref10.token_id, _ref10$system = _ref10.system, system = _ref10$system === void 0 ? 'evm' : _ref10$system, _ref10$awaitReceipt = _ref10.awaitReceipt, awaitReceipt = _ref10$awaitReceipt === void 0 ? true : _ref10$awaitReceipt; // Allow snake-case for backwards compatibility
                  // eslint-disable-next-line camelcase
  
                  contractAddress = contractAddress || contract_address; // eslint-disable-next-line camelcase
  
                  tokenId = tokenId || token_id;
                  options = {
                    receiver: receiver,
                    contractAddress: contractAddress,
                    amount: amount,
                    tokenId: tokenId,
                    system: system,
                    awaitReceipt: awaitReceipt
                  };
  
                  _TransferUtils.default.isSupportedType(type);
  
                  _TransferUtils.default.validateInput(type, options);
  
                  if (this.ensureWeb3IsInstalled()) {
                    _context21.next = 8;
                    break;
                  }
  
                  throw new Error(ERROR_WEB3_MISSING);
  
                case 8:
                  web3 = this.web3;
                  _context21.next = 11;
                  return web3.eth.getAccounts();
  
                case 11:
                  _context21.next = 13;
                  return _context21.sent[0];
  
                case 13:
                  sender = _context21.sent;
  
                  if (sender) {
                    _context21.next = 16;
                    break;
                  }
  
                  throw new Error('Sender address not found');
  
                case 16:
                  if (tokenId) _TransferUtils.default.isUint256(tokenId);
                  if (type !== 'native') customToken = new web3.eth.Contract(_TransferUtils.default.abi[type], contractAddress);
                  _context21.t0 = type;
                  _context21.next = _context21.t0 === 'native' ? 21 : _context21.t0 === 'erc20' ? 23 : _context21.t0 === 'erc721' ? 25 : _context21.t0 === 'erc1155' ? 27 : 29;
                  break;
  
                case 21:
                  transferOperation = web3.eth.sendTransaction({
                    from: sender,
                    to: receiver,
                    value: amount
                  });
                  return _context21.abrupt("break", 30);
  
                case 23:
                  transferOperation = customToken.methods.transfer(receiver, amount).send({
                    from: sender
                  });
                  return _context21.abrupt("break", 30);
  
                case 25:
                  transferOperation = customToken.methods.safeTransferFrom(sender, receiver, "".concat(tokenId)).send({
                    from: sender
                  });
                  return _context21.abrupt("break", 30);
  
                case 27:
                  transferOperation = customToken.methods.safeTransferFrom(sender, receiver, "".concat(tokenId), amount, '0x').send({
                    from: sender
                  });
                  return _context21.abrupt("break", 30);
  
                case 29:
                  throw new Error("Unknown transfer type: \"".concat(type, "\""));
  
                case 30:
                  if (!awaitReceipt) {
                    _context21.next = 32;
                    break;
                  }
  
                  return _context21.abrupt("return", transferOperation);
  
                case 32:
                  transferEvents = new EventEmitter();
                  transferOperation.on('transactionHash', function (hash) {
                    transferEvents.emit('transactionHash', hash);
                  }).on('receipt', function (receipt) {
                    transferEvents.emit('receipt', receipt);
                  }).on('confirmation', function (confirmationNumber, receipt) {
                    transferEvents.emit('confirmation', (confirmationNumber, receipt));
                  }).on('error', function (error) {
                    transferEvents.emit('error', error);
                    throw error;
                  });
                  return _context21.abrupt("return", transferEvents);
  
                case 35:
                case "end":
                  return _context21.stop();
              }
            }
          }, _callee14, this);
        }));
  
        return function () {
          return _transfer.apply(this, arguments);
        };
      }()
    }, {
      key: "executeFunction",
      value: function () {
        var _executeFunction = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15() {
          var _context22;
  
          var _ref11,
              contractAddress,
              abi,
              functionName,
              msgValue,
              _ref11$awaitReceipt,
              awaitReceipt,
              _ref11$params,
              params,
              web3,
              contractOptions,
              functionData,
              stateMutability,
              isReadFunction,
              currentAddress,
              errors,
              _iterator,
              _step,
              input,
              value,
              parsedInputs,
              contract,
              customFunction,
              response,
              contractExecuteEvents,
              _args16 = arguments;
  
          return _regenerator.default.wrap(function (_context23) {
            while (1) {
              switch (_context23.prev = _context23.next) {
                case 0:
                  _ref11 = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {}, contractAddress = _ref11.contractAddress, abi = _ref11.abi, functionName = _ref11.functionName, msgValue = _ref11.msgValue, _ref11$awaitReceipt = _ref11.awaitReceipt, awaitReceipt = _ref11$awaitReceipt === void 0 ? true : _ref11$awaitReceipt, _ref11$params = _ref11.params, params = _ref11$params === void 0 ? {} : _ref11$params;
  
                  if (this.ensureWeb3IsInstalled()) {
                    _context23.next = 3;
                    break;
                  }
  
                  throw new Error(ERROR_WEB3_MISSING);
  
                case 3:
                  web3 = this.web3;
                  contractOptions = {};
                  functionData = (0, _find.default)(abi).call(abi, function (x) {
                    return x.name === functionName;
                  });
  
                  if (functionData) {
                    _context23.next = 8;
                    break;
                  }
  
                  throw new Error('Function does not exist in abi');
  
                case 8:
                  stateMutability = functionData === null || functionData === void 0 ? void 0 : functionData.stateMutability;
                  isReadFunction = stateMutability === 'view' || stateMutability === 'pure';
  
                  if (isReadFunction) {
                    _context23.next = 20;
                    break;
                  }
  
                  if (params.from) {
                    _context23.next = 20;
                    break;
                  }
  
                  _context23.next = 14;
                  return web3.eth.getAccounts();
  
                case 14:
                  _context23.next = 16;
                  return _context23.sent[0];
  
                case 16:
                  currentAddress = _context23.sent;
  
                  if (currentAddress) {
                    _context23.next = 19;
                    break;
                  }
  
                  throw new Error('From address is required');
  
                case 19:
                  contractOptions.from = currentAddress;
  
                case 20:
                  errors = [];
                  _iterator = _createForOfIteratorHelper(functionData.inputs);
  
                  try {
                    for (_iterator.s(); !(_step = _iterator.n()).done;) {
                      input = _step.value;
                      value = params[input.name];
  
                      if (!(typeof value !== 'undefined' && value)) {
                        errors.push("".concat(input.name, " is required"));
                      }
                    }
                  } catch (err) {
                    _iterator.e(err);
                  } finally {
                    _iterator.f();
                  }
  
                  if (!(errors.length > 0)) {
                    _context23.next = 25;
                    break;
                  }
  
                  throw errors;
  
                case 25:
                  parsedInputs = (0, _map.default)(_context22 = functionData.inputs).call(_context22, function (x) {
                    return params[x.name];
                  });
                  contract = new web3.eth.Contract(abi, contractAddress, contractOptions);
                  customFunction = contract.methods[functionName];
                  response = isReadFunction ? customFunction.apply(void 0, (0, _toConsumableArray2.default)((0, _values.default)(parsedInputs))).call() : customFunction.apply(void 0, (0, _toConsumableArray2.default)((0, _values.default)(parsedInputs))).send(msgValue ? {
                    value: msgValue
                  } : null);
  
                  if (!awaitReceipt) {
                    _context23.next = 31;
                    break;
                  }
  
                  return _context23.abrupt("return", response);
  
                case 31:
                  contractExecuteEvents = new EventEmitter();
                  response.on('transactionHash', function (hash) {
                    contractExecuteEvents.emit('transactionHash', hash);
                  }).on('receipt', function (receipt) {
                    contractExecuteEvents.emit('receipt', receipt);
                  }).on('confirmation', function (confirmationNumber, receipt) {
                    contractExecuteEvents.emit('confirmation', (confirmationNumber, receipt));
                  }).on('error', function (error) {
                    contractExecuteEvents.emit('error', error);
                    throw error;
                  });
                  return _context23.abrupt("return", contractExecuteEvents);
  
                case 34:
                case "end":
                  return _context23.stop();
              }
            }
          }, _callee15, this);
        }));
  
        return function () {
          return _executeFunction.apply(this, arguments);
        };
      }()
    }, {
      key: "getSigningData",
      value: function () {
        return "Moralis Authentication"; // const data = `Moralis Authentication`;
        // return data;
      }
    }, {
      key: "on",
      value: function (eventName, cb) {
        var _window = window,
            ethereum = _window.ethereum;
  
        if (!ethereum || !ethereum.on) {
          // eslint-disable-next-line no-console
          console.warn(WARNING);
          return function () {
            // eslint-disable-next-line no-console
            console.warn(WARNING);
          };
        }
  
        ethereum.on(eventName, cb);
        return function () {
          // eslint-disable-next-line no-console
          console.warn('UNSUB NOT SUPPORTED');
        };
      }
    }, {
      key: "getChainId",
      value: function () {
        var _getChainId = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16() {
          return _regenerator.default.wrap(function (_context24) {
            while (1) {
              switch (_context24.prev = _context24.next) {
                case 0:
                  if (!this.ensureWeb3IsInstalled()) {
                    _context24.next = 4;
                    break;
                  }
  
                  _context24.next = 3;
                  return this.web3.eth.net.getId();
  
                case 3:
                  return _context24.abrupt("return", _context24.sent);
  
                case 4:
                  throw new Error(ERROR_WEB3_MISSING);
  
                case 5:
                case "end":
                  return _context24.stop();
              }
            }
          }, _callee16, this);
        }));
  
        return function () {
          return _getChainId.apply(this, arguments);
        };
      }()
    }, {
      key: "ensureWeb3IsInstalled",
      value: function () {
        return this.web3 ? true : false;
      }
    }, {
      key: "isMetaMaskInstalled",
      value: function () {
        var _isMetaMaskInstalled = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee17() {
          return _regenerator.default.wrap(function (_context25) {
            while (1) {
              switch (_context25.prev = _context25.next) {
                case 0:
                  _context25.next = 2;
                  return (0, _detectProvider.default)();
  
                case 2:
                  if (!_context25.sent) {
                    _context25.next = 6;
                    break;
                  }
  
                  _context25.t0 = true;
                  _context25.next = 7;
                  break;
  
                case 6:
                  _context25.t0 = false;
  
                case 7:
                  return _context25.abrupt("return", _context25.t0);
  
                case 8:
                case "end":
                  return _context25.stop();
              }
            }
          }, _callee17);
        }));
  
        return function () {
          return _isMetaMaskInstalled.apply(this, arguments);
        };
      }()
    }, {
      key: "switchNetwork",
      value: function () {
        var _switchNetwork = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee18(chainId) {
          var currentNetwork;
          return _regenerator.default.wrap(function (_context26) {
            while (1) {
              switch (_context26.prev = _context26.next) {
                case 0:
                  chainId = verifyChainId(chainId); // Check if the user wallet is already on `chainId`
  
                  _context26.t0 = fromDecimalToHex;
                  _context26.next = 4;
                  return this.getChainId();
  
                case 4:
                  _context26.t1 = _context26.sent;
                  currentNetwork = (0, _context26.t0)(_context26.t1);
  
                  if (!(currentNetwork === chainId)) {
                    _context26.next = 8;
                    break;
                  }
  
                  return _context26.abrupt("return");
  
                case 8:
                  _context26.next = 10;
                  return window.ethereum.request({
                    method: 'wallet_switchEthereumChain',
                    params: [{
                      chainId: chainId
                    }]
                  });
  
                case 10:
                case "end":
                  return _context26.stop();
              }
            }
          }, _callee18, this);
        }));
  
        return function () {
          return _switchNetwork.apply(this, arguments);
        };
      }()
    }, {
      key: "addNetwork",
      value: function () {
        var _addNetwork = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee19(chainId, chainName, currencyName, currencySymbol, rpcUrl, blockExplorerUrl) {
          return _regenerator.default.wrap(function (_context27) {
            while (1) {
              switch (_context27.prev = _context27.next) {
                case 0:
                  chainId = verifyChainId(chainId);
                  _context27.next = 3;
                  return window.ethereum.request({
                    method: 'wallet_addEthereumChain',
                    params: [{
                      chainId: chainId,
                      chainName: chainName,
                      nativeCurrency: {
                        name: currencyName,
                        symbol: currencySymbol,
                        decimals: 18
                      },
                      rpcUrls: [rpcUrl],
                      blockExplorerUrls: [blockExplorerUrl]
                    }]
                  });
  
                case 3:
                case "end":
                  return _context27.stop();
              }
            }
          }, _callee19);
        }));
  
        return function () {
          return _addNetwork.apply(this, arguments);
        };
      }()
    }]);
    return MoralisWeb3;
  }();
  
  (0, _defineProperty2.default)(MoralisWeb3, "memoryCard", {
    save: function (what) {
      this.saved = what;
    },
    get: function (where) {
      if (!this.saved) throw new Error('Nothing saved to memory card'); // In case the saved data is not an object but a simple string or number
  
      if (where.length === 0) return this.getSaved();
      var tmp;
      var savedTmp = this.saved;
  
      for (var i = 0; i < where.length; i++) {
        tmp = savedTmp[where[i]];
        savedTmp = tmp;
      }
  
      return savedTmp;
    },
    getSaved: function () {
      return this.saved;
    },
    deleteSaved: function () {
      this.saved = undefined;
    }
  });
  
  function fromDecimalToHex(number) {
    if (typeof number !== 'number') throw 'The input provided should be a number';
    return "0x".concat(number.toString(16));
  }
  
  function verifyChainId(chainId) {
    // Check if chainId is a number, in that case convert to hex
    if (typeof chainId === 'number') chainId = fromDecimalToHex(chainId);
    return chainId;
  }
  
  MoralisWeb3.onConnect = (0, _bind.default)(_context28 = MoralisWeb3.on).call(_context28, MoralisWeb3, EthereumEvents.CONNECT);
  MoralisWeb3.onDisconnect = (0, _bind.default)(_context29 = MoralisWeb3.on).call(_context29, MoralisWeb3, EthereumEvents.DISCONNECT);
  MoralisWeb3.onChainChanged = (0, _bind.default)(_context30 = MoralisWeb3.on).call(_context30, MoralisWeb3, EthereumEvents.CHAIN_CHANGED);
  MoralisWeb3.onAccountsChanged = (0, _bind.default)(_context31 = MoralisWeb3.on).call(_context31, MoralisWeb3, EthereumEvents.ACCOUNTS_CHANGED);
  var _default = MoralisWeb3;
  exports.default = _default;