UNPKG

@nexex/api

Version:
49 lines 1.88 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var ethers_1 = require("ethers"); var isUndefined_1 = __importDefault(require("lodash/isUndefined")); var constants_1 = require("../constants"); var BaseContract = /** @class */ (function () { function BaseContract(eth, network, addressIfExists) { this.eth = eth; this.addressIfExists = addressIfExists; this.network = network; } BaseContract.prototype.getContractAddress = function () { var networkId = constants_1.constants.NETWORK_ID[this.network.toUpperCase()]; if (isUndefined_1.default(this.addressIfExists)) { var artifact = this.getArtifact(); var contractAddress = artifact.networks[networkId.toString()].address; if (isUndefined_1.default(contractAddress)) { throw new Error('ContractDoesNotExist'); } return contractAddress; } else { return this.addressIfExists; } }; Object.defineProperty(BaseContract.prototype, "contract", { get: function () { if (!this._contract) { var addr = this.getContractAddress(); if (!addr) { throw new Error('addr not found'); } this._contract = new ethers_1.ethers.Contract(addr, this.getAbiDefinition(), this.eth); } return this._contract; }, enumerable: true, configurable: true }); BaseContract.prototype.getAbiDefinition = function () { return this.getArtifact().abi; }; return BaseContract; }()); exports.BaseContract = BaseContract; //# sourceMappingURL=BaseContract.js.map