UNPKG

zodor-protocol-web3

Version:

SDK to interact with zodor protocol

69 lines 2.75 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Merc20 = void 0; const ethers_1 = require("ethers"); const Merc20_json_1 = __importDefault(require("../abi/Merc20.json")); const ContractFactory_1 = require("../factories/ContractFactory"); const utils_1 = require("../utils"); const WalletFactory_1 = require("../factories/WalletFactory"); class Merc20 { contract; network; constructor(options) { const { network, contractRunner, contractAddress, privateKey, customRpcUrl } = options; if (!network) throw new Error('network is required'); if (contractRunner) { const contractFactory = new ContractFactory_1.ContractFactory(); this.contract = contractFactory.createContract(contractAddress, Merc20_json_1.default.abi, contractRunner); } else { const rpcProvider = (0, utils_1.getRpcProvider)(network, customRpcUrl); let wallet; if (privateKey) { const walletFactory = new WalletFactory_1.WalletFactory(rpcProvider); wallet = walletFactory.createWallet(privateKey); } const contractFactory = new ContractFactory_1.ContractFactory(); this.contract = contractFactory.createContract(contractAddress, Merc20_json_1.default.abi, wallet || rpcProvider); } this.network = network; } async name() { return (await this.contract.name()); } async symbol() { return (await this.contract.symbol()); } async decimals() { const decimalValue = await this.contract.decimals(); return Number(decimalValue); } async totalSupply() { const decimalValue = await this.contract.totalSupply(); return Number((0, ethers_1.formatEther)(decimalValue.toString())); } async balanceOf(walletAddress) { return (await this.contract.balanceOf(walletAddress)); } async allowance(walletAdress, spender) { return await this.contract.allowance(walletAdress, spender); } async requiredClaims() { return await this.contract.requiredClaims(); } async approve(spender, amount, signature) { return await this.contract.approve(spender, amount, signature); } async transfer(to, amount, signature) { return await this.contract.transfer(to, amount, signature); } async transferFrom(from, to, amount, signature) { return await this.contract.transfer(from, to, amount, signature); } } exports.Merc20 = Merc20; //# sourceMappingURL=merc20.js.map