MoralisWeb3Api.js 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
  7. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  8. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  9. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  10. var axios = require('axios');
  11. var Web3Api = function () {
  12. function Web3Api() {
  13. (0, _classCallCheck2.default)(this, Web3Api);
  14. }
  15. (0, _createClass2.default)(Web3Api, null, [{
  16. key: "initialize",
  17. value: function (_ref) {
  18. var apiKey = _ref.apiKey,
  19. serverUrl = _ref.serverUrl,
  20. _ref$Moralis = _ref.Moralis,
  21. Moralis = _ref$Moralis === void 0 ? null : _ref$Moralis;
  22. if (!serverUrl && !apiKey) {
  23. throw new Error('Web3Api.initialize failed: initialize with apiKey or serverUrl');
  24. }
  25. if (apiKey) this.apiKey = apiKey;
  26. if (serverUrl) this.serverUrl = serverUrl;
  27. this.Moralis = Moralis;
  28. }
  29. }, {
  30. key: "getBody",
  31. value: function (params, bodyParams) {
  32. var _this = this;
  33. if (!params || !bodyParams || !bodyParams.length) {
  34. return undefined;
  35. }
  36. var body = {};
  37. bodyParams.forEach(function (_ref2) {
  38. var key = _ref2.key,
  39. type = _ref2.type,
  40. required = _ref2.required;
  41. if (params[key] === undefined) {
  42. if (required) throw new Error("param " + key + " is required!");
  43. } else if (type === _this.BodyParamTypes.setBody) {
  44. body = params[key];
  45. } else {
  46. body[key] = params[key];
  47. }
  48. delete params[key];
  49. });
  50. return body;
  51. }
  52. }, {
  53. key: "getParameterizedUrl",
  54. value: function (url, params) {
  55. if (!Object.keys(params).length) return url;
  56. var requiredParams = url.split('/').filter(function (s) {
  57. return s && s.includes(':');
  58. });
  59. if (!requiredParams.length) return url;
  60. var parameterizedUrl = url;
  61. requiredParams.forEach(function (p) {
  62. var key = p.substr(1);
  63. var value = params[key];
  64. if (!value) {
  65. throw new Error("required param " + key + " not provided");
  66. }
  67. parameterizedUrl = parameterizedUrl.replace(p, value);
  68. delete params[key];
  69. });
  70. return parameterizedUrl;
  71. }
  72. }, {
  73. key: "getApiRateLimitInfo",
  74. value: function (headers) {
  75. return {
  76. 'x-rate-limit-limit': headers['x-rate-limit-limit'],
  77. 'x-rate-limit-remaining-ttl': headers['x-rate-limit-remaining-ttl'],
  78. 'x-rate-limit-used': headers['x-rate-limit-used'],
  79. 'x-rate-limit-remaining-ip-ttl': headers['x-rate-limit-remaining-ip-ttl'],
  80. 'x-rate-limit-ip-used': headers['x-rate-limit-ip-used']
  81. };
  82. }
  83. }, {
  84. key: "getApiErrorMessage",
  85. value: function (error, url) {
  86. var _error$response, _error$response$data;
  87. return (error == null ? void 0 : (_error$response = error.response) == null ? void 0 : (_error$response$data = _error$response.data) == null ? void 0 : _error$response$data.message) || (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "Web3 API error while calling " + url;
  88. }
  89. }, {
  90. key: "fetch",
  91. value: function (_ref3) {
  92. var endpoint, providedParams, params, _this$Moralis, User, account, user;
  93. return _regenerator.default.async(function (_context) {
  94. while (1) {
  95. switch (_context.prev = _context.next) {
  96. case 0:
  97. endpoint = _ref3.endpoint, providedParams = _ref3.params;
  98. params = (0, _extends2.default)({}, providedParams);
  99. if (this.Moralis) {
  100. _this$Moralis = this.Moralis, User = _this$Moralis.User, account = _this$Moralis.account;
  101. user = User.current();
  102. if (!params.address) {
  103. if (user) {
  104. params.address = user.get('ethAddress');
  105. } else if (account) {
  106. params.address = account;
  107. }
  108. }
  109. }
  110. if (this.apiKey) {
  111. _context.next = 5;
  112. break;
  113. }
  114. return _context.abrupt("return", this.fetchFromServer(endpoint.name, params));
  115. case 5:
  116. return _context.abrupt("return", this.fetchFromApi(endpoint, params));
  117. case 6:
  118. case "end":
  119. return _context.stop();
  120. }
  121. }
  122. }, null, this, null, Promise);
  123. }
  124. }, {
  125. key: "fetchFromApi",
  126. value: function (endpoint, params) {
  127. var _endpoint$method, method, url, bodyParams, parameterizedUrl, body, response, _error$response2, status, headers, data, msg;
  128. return _regenerator.default.async(function (_context2) {
  129. while (1) {
  130. switch (_context2.prev = _context2.next) {
  131. case 0:
  132. _endpoint$method = endpoint.method, method = _endpoint$method === void 0 ? 'GET' : _endpoint$method, url = endpoint.url, bodyParams = endpoint.bodyParams;
  133. _context2.prev = 1;
  134. parameterizedUrl = this.getParameterizedUrl(url, params);
  135. body = this.getBody(params, bodyParams);
  136. _context2.next = 6;
  137. return _regenerator.default.awrap(axios(this.baseURL + parameterizedUrl, {
  138. params: params,
  139. method: method,
  140. body: body,
  141. headers: {
  142. Accept: 'application/json',
  143. 'Content-Type': 'application/json',
  144. 'x-api-key': this.apiKey
  145. }
  146. }));
  147. case 6:
  148. response = _context2.sent;
  149. return _context2.abrupt("return", response.data);
  150. case 10:
  151. _context2.prev = 10;
  152. _context2.t0 = _context2["catch"](1);
  153. _error$response2 = _context2.t0.response, status = _error$response2.status, headers = _error$response2.headers, data = _error$response2.data;
  154. if (status === 429) {
  155. msg = "This Moralis Server is rate-limited because of the plan restrictions. See the details about the current rate and throttle limits: " + JSON.stringify(this.getApiRateLimitInfo(headers));
  156. } else {
  157. msg = this.getApiErrorMessage(_context2.t0, url);
  158. }
  159. throw new Error(msg);
  160. case 15:
  161. case "end":
  162. return _context2.stop();
  163. }
  164. }
  165. }, null, this, [[1, 10]], Promise);
  166. }
  167. }, {
  168. key: "fetchFromServer",
  169. value: function (name, options) {
  170. var http, user, response, _error$response3, _error$response3$data;
  171. return _regenerator.default.async(function (_context3) {
  172. while (1) {
  173. switch (_context3.prev = _context3.next) {
  174. case 0:
  175. if (this.serverUrl) {
  176. _context3.next = 2;
  177. break;
  178. }
  179. throw new Error('Web3Api not initialized, run Moralis.start() first');
  180. case 2:
  181. _context3.prev = 2;
  182. http = axios.create({
  183. baseURL: this.serverUrl
  184. });
  185. if (!options.chain) options.chain = 'eth';
  186. user = this.Moralis.User.current();
  187. if (user) {
  188. options._SessionToken = user.attributes.sessionToken;
  189. options._ApplicationId = this.Moralis.applicationId;
  190. }
  191. _context3.next = 9;
  192. return _regenerator.default.awrap(http.post("/functions/" + name, options, {
  193. headers: {
  194. Accept: 'application/json',
  195. 'Content-Type': 'application/json'
  196. }
  197. }));
  198. case 9:
  199. response = _context3.sent;
  200. return _context3.abrupt("return", response.data.result);
  201. case 13:
  202. _context3.prev = 13;
  203. _context3.t0 = _context3["catch"](2);
  204. if (!((_error$response3 = _context3.t0.response) != null && (_error$response3$data = _error$response3.data) != null && _error$response3$data.error)) {
  205. _context3.next = 17;
  206. break;
  207. }
  208. throw new Error(_context3.t0.response.data.error);
  209. case 17:
  210. throw _context3.t0;
  211. case 18:
  212. case "end":
  213. return _context3.stop();
  214. }
  215. }
  216. }, null, this, [[2, 13]], Promise);
  217. }
  218. }]);
  219. return Web3Api;
  220. }();
  221. Web3Api.baseURL = 'https://deep-index.moralis.io/api/v2';
  222. Web3Api.BodyParamTypes = {
  223. setBody: 'set body',
  224. property: 'property'
  225. };
  226. Web3Api.native = {
  227. getBlock: function () {
  228. var options,
  229. _args4 = arguments;
  230. return _regenerator.default.async(function (_context4) {
  231. while (1) {
  232. switch (_context4.prev = _context4.next) {
  233. case 0:
  234. options = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
  235. return _context4.abrupt("return", Web3Api.fetch({
  236. endpoint: {
  237. "method": "GET",
  238. "group": "native",
  239. "name": "getBlock",
  240. "url": "/block/:block_number_or_hash"
  241. },
  242. params: options
  243. }));
  244. case 2:
  245. case "end":
  246. return _context4.stop();
  247. }
  248. }
  249. }, null, null, null, Promise);
  250. },
  251. getDateToBlock: function () {
  252. var options,
  253. _args5 = arguments;
  254. return _regenerator.default.async(function (_context5) {
  255. while (1) {
  256. switch (_context5.prev = _context5.next) {
  257. case 0:
  258. options = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {};
  259. return _context5.abrupt("return", Web3Api.fetch({
  260. endpoint: {
  261. "method": "GET",
  262. "group": "native",
  263. "name": "getDateToBlock",
  264. "url": "/dateToBlock"
  265. },
  266. params: options
  267. }));
  268. case 2:
  269. case "end":
  270. return _context5.stop();
  271. }
  272. }
  273. }, null, null, null, Promise);
  274. },
  275. getLogsByAddress: function () {
  276. var options,
  277. _args6 = arguments;
  278. return _regenerator.default.async(function (_context6) {
  279. while (1) {
  280. switch (_context6.prev = _context6.next) {
  281. case 0:
  282. options = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {};
  283. return _context6.abrupt("return", Web3Api.fetch({
  284. endpoint: {
  285. "method": "GET",
  286. "group": "native",
  287. "name": "getLogsByAddress",
  288. "url": "/:address/logs"
  289. },
  290. params: options
  291. }));
  292. case 2:
  293. case "end":
  294. return _context6.stop();
  295. }
  296. }
  297. }, null, null, null, Promise);
  298. },
  299. getNFTTransfersByBlock: function () {
  300. var options,
  301. _args7 = arguments;
  302. return _regenerator.default.async(function (_context7) {
  303. while (1) {
  304. switch (_context7.prev = _context7.next) {
  305. case 0:
  306. options = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
  307. return _context7.abrupt("return", Web3Api.fetch({
  308. endpoint: {
  309. "method": "GET",
  310. "group": "native",
  311. "name": "getNFTTransfersByBlock",
  312. "url": "/block/:block_number_or_hash/nft/transfers"
  313. },
  314. params: options
  315. }));
  316. case 2:
  317. case "end":
  318. return _context7.stop();
  319. }
  320. }
  321. }, null, null, null, Promise);
  322. },
  323. getTransaction: function () {
  324. var options,
  325. _args8 = arguments;
  326. return _regenerator.default.async(function (_context8) {
  327. while (1) {
  328. switch (_context8.prev = _context8.next) {
  329. case 0:
  330. options = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
  331. return _context8.abrupt("return", Web3Api.fetch({
  332. endpoint: {
  333. "method": "GET",
  334. "group": "native",
  335. "name": "getTransaction",
  336. "url": "/transaction/:transaction_hash"
  337. },
  338. params: options
  339. }));
  340. case 2:
  341. case "end":
  342. return _context8.stop();
  343. }
  344. }
  345. }, null, null, null, Promise);
  346. },
  347. getContractEvents: function () {
  348. var options,
  349. _args9 = arguments;
  350. return _regenerator.default.async(function (_context9) {
  351. while (1) {
  352. switch (_context9.prev = _context9.next) {
  353. case 0:
  354. options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
  355. return _context9.abrupt("return", Web3Api.fetch({
  356. endpoint: {
  357. "method": "POST",
  358. "group": "native",
  359. "name": "getContractEvents",
  360. "url": "/:address/events",
  361. "bodyParams": [{
  362. "key": "data",
  363. "type": "set body",
  364. "required": false
  365. }]
  366. },
  367. params: options
  368. }));
  369. case 2:
  370. case "end":
  371. return _context9.stop();
  372. }
  373. }
  374. }, null, null, null, Promise);
  375. },
  376. runContractFunction: function () {
  377. var options,
  378. _args10 = arguments;
  379. return _regenerator.default.async(function (_context10) {
  380. while (1) {
  381. switch (_context10.prev = _context10.next) {
  382. case 0:
  383. options = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
  384. return _context10.abrupt("return", Web3Api.fetch({
  385. endpoint: {
  386. "method": "POST",
  387. "group": "native",
  388. "name": "runContractFunction",
  389. "url": "/:address/function",
  390. "bodyParams": [{
  391. "key": "abi",
  392. "type": "property",
  393. "required": true
  394. }, {
  395. "key": "params",
  396. "type": "property",
  397. "required": false
  398. }]
  399. },
  400. params: options
  401. }));
  402. case 2:
  403. case "end":
  404. return _context10.stop();
  405. }
  406. }
  407. }, null, null, null, Promise);
  408. }
  409. };
  410. Web3Api.account = {
  411. getTransactions: function () {
  412. var options,
  413. _args11 = arguments;
  414. return _regenerator.default.async(function (_context11) {
  415. while (1) {
  416. switch (_context11.prev = _context11.next) {
  417. case 0:
  418. options = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : {};
  419. return _context11.abrupt("return", Web3Api.fetch({
  420. endpoint: {
  421. "method": "GET",
  422. "group": "account",
  423. "name": "getTransactions",
  424. "url": "/:address"
  425. },
  426. params: options
  427. }));
  428. case 2:
  429. case "end":
  430. return _context11.stop();
  431. }
  432. }
  433. }, null, null, null, Promise);
  434. },
  435. getNativeBalance: function () {
  436. var options,
  437. _args12 = arguments;
  438. return _regenerator.default.async(function (_context12) {
  439. while (1) {
  440. switch (_context12.prev = _context12.next) {
  441. case 0:
  442. options = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
  443. return _context12.abrupt("return", Web3Api.fetch({
  444. endpoint: {
  445. "method": "GET",
  446. "group": "account",
  447. "name": "getNativeBalance",
  448. "url": "/:address/balance"
  449. },
  450. params: options
  451. }));
  452. case 2:
  453. case "end":
  454. return _context12.stop();
  455. }
  456. }
  457. }, null, null, null, Promise);
  458. },
  459. getTokenBalances: function () {
  460. var options,
  461. _args13 = arguments;
  462. return _regenerator.default.async(function (_context13) {
  463. while (1) {
  464. switch (_context13.prev = _context13.next) {
  465. case 0:
  466. options = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {};
  467. return _context13.abrupt("return", Web3Api.fetch({
  468. endpoint: {
  469. "method": "GET",
  470. "group": "account",
  471. "name": "getTokenBalances",
  472. "url": "/:address/erc20"
  473. },
  474. params: options
  475. }));
  476. case 2:
  477. case "end":
  478. return _context13.stop();
  479. }
  480. }
  481. }, null, null, null, Promise);
  482. },
  483. getTokenTransfers: function () {
  484. var options,
  485. _args14 = arguments;
  486. return _regenerator.default.async(function (_context14) {
  487. while (1) {
  488. switch (_context14.prev = _context14.next) {
  489. case 0:
  490. options = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : {};
  491. return _context14.abrupt("return", Web3Api.fetch({
  492. endpoint: {
  493. "method": "GET",
  494. "group": "account",
  495. "name": "getTokenTransfers",
  496. "url": "/:address/erc20/transfers"
  497. },
  498. params: options
  499. }));
  500. case 2:
  501. case "end":
  502. return _context14.stop();
  503. }
  504. }
  505. }, null, null, null, Promise);
  506. },
  507. getNFTs: function () {
  508. var options,
  509. _args15 = arguments;
  510. return _regenerator.default.async(function (_context15) {
  511. while (1) {
  512. switch (_context15.prev = _context15.next) {
  513. case 0:
  514. options = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : {};
  515. return _context15.abrupt("return", Web3Api.fetch({
  516. endpoint: {
  517. "method": "GET",
  518. "group": "account",
  519. "name": "getNFTs",
  520. "url": "/:address/nft"
  521. },
  522. params: options
  523. }));
  524. case 2:
  525. case "end":
  526. return _context15.stop();
  527. }
  528. }
  529. }, null, null, null, Promise);
  530. },
  531. getNFTTransfers: function () {
  532. var options,
  533. _args16 = arguments;
  534. return _regenerator.default.async(function (_context16) {
  535. while (1) {
  536. switch (_context16.prev = _context16.next) {
  537. case 0:
  538. options = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {};
  539. return _context16.abrupt("return", Web3Api.fetch({
  540. endpoint: {
  541. "method": "GET",
  542. "group": "account",
  543. "name": "getNFTTransfers",
  544. "url": "/:address/nft/transfers"
  545. },
  546. params: options
  547. }));
  548. case 2:
  549. case "end":
  550. return _context16.stop();
  551. }
  552. }
  553. }, null, null, null, Promise);
  554. },
  555. getNFTsForContract: function () {
  556. var options,
  557. _args17 = arguments;
  558. return _regenerator.default.async(function (_context17) {
  559. while (1) {
  560. switch (_context17.prev = _context17.next) {
  561. case 0:
  562. options = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : {};
  563. return _context17.abrupt("return", Web3Api.fetch({
  564. endpoint: {
  565. "method": "GET",
  566. "group": "account",
  567. "name": "getNFTsForContract",
  568. "url": "/:address/nft/:token_address"
  569. },
  570. params: options
  571. }));
  572. case 2:
  573. case "end":
  574. return _context17.stop();
  575. }
  576. }
  577. }, null, null, null, Promise);
  578. }
  579. };
  580. Web3Api.token = {
  581. getTokenMetadata: function () {
  582. var options,
  583. _args18 = arguments;
  584. return _regenerator.default.async(function (_context18) {
  585. while (1) {
  586. switch (_context18.prev = _context18.next) {
  587. case 0:
  588. options = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : {};
  589. return _context18.abrupt("return", Web3Api.fetch({
  590. endpoint: {
  591. "method": "GET",
  592. "group": "token",
  593. "name": "getTokenMetadata",
  594. "url": "/erc20/metadata"
  595. },
  596. params: options
  597. }));
  598. case 2:
  599. case "end":
  600. return _context18.stop();
  601. }
  602. }
  603. }, null, null, null, Promise);
  604. },
  605. getNFTTrades: function () {
  606. var options,
  607. _args19 = arguments;
  608. return _regenerator.default.async(function (_context19) {
  609. while (1) {
  610. switch (_context19.prev = _context19.next) {
  611. case 0:
  612. options = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : {};
  613. return _context19.abrupt("return", Web3Api.fetch({
  614. endpoint: {
  615. "method": "GET",
  616. "group": "token",
  617. "name": "getNFTTrades",
  618. "url": "/nft/:address/trades"
  619. },
  620. params: options
  621. }));
  622. case 2:
  623. case "end":
  624. return _context19.stop();
  625. }
  626. }
  627. }, null, null, null, Promise);
  628. },
  629. getNFTLowestPrice: function () {
  630. var options,
  631. _args20 = arguments;
  632. return _regenerator.default.async(function (_context20) {
  633. while (1) {
  634. switch (_context20.prev = _context20.next) {
  635. case 0:
  636. options = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : {};
  637. return _context20.abrupt("return", Web3Api.fetch({
  638. endpoint: {
  639. "method": "GET",
  640. "group": "token",
  641. "name": "getNFTLowestPrice",
  642. "url": "/nft/:address/lowestprice"
  643. },
  644. params: options
  645. }));
  646. case 2:
  647. case "end":
  648. return _context20.stop();
  649. }
  650. }
  651. }, null, null, null, Promise);
  652. },
  653. getTokenMetadataBySymbol: function () {
  654. var options,
  655. _args21 = arguments;
  656. return _regenerator.default.async(function (_context21) {
  657. while (1) {
  658. switch (_context21.prev = _context21.next) {
  659. case 0:
  660. options = _args21.length > 0 && _args21[0] !== undefined ? _args21[0] : {};
  661. return _context21.abrupt("return", Web3Api.fetch({
  662. endpoint: {
  663. "method": "GET",
  664. "group": "token",
  665. "name": "getTokenMetadataBySymbol",
  666. "url": "/erc20/metadata/symbols"
  667. },
  668. params: options
  669. }));
  670. case 2:
  671. case "end":
  672. return _context21.stop();
  673. }
  674. }
  675. }, null, null, null, Promise);
  676. },
  677. getTokenPrice: function () {
  678. var options,
  679. _args22 = arguments;
  680. return _regenerator.default.async(function (_context22) {
  681. while (1) {
  682. switch (_context22.prev = _context22.next) {
  683. case 0:
  684. options = _args22.length > 0 && _args22[0] !== undefined ? _args22[0] : {};
  685. return _context22.abrupt("return", Web3Api.fetch({
  686. endpoint: {
  687. "method": "GET",
  688. "group": "token",
  689. "name": "getTokenPrice",
  690. "url": "/erc20/:address/price"
  691. },
  692. params: options
  693. }));
  694. case 2:
  695. case "end":
  696. return _context22.stop();
  697. }
  698. }
  699. }, null, null, null, Promise);
  700. },
  701. getTokenAddressTransfers: function () {
  702. var options,
  703. _args23 = arguments;
  704. return _regenerator.default.async(function (_context23) {
  705. while (1) {
  706. switch (_context23.prev = _context23.next) {
  707. case 0:
  708. options = _args23.length > 0 && _args23[0] !== undefined ? _args23[0] : {};
  709. return _context23.abrupt("return", Web3Api.fetch({
  710. endpoint: {
  711. "method": "GET",
  712. "group": "token",
  713. "name": "getTokenAddressTransfers",
  714. "url": "/erc20/:address/transfers"
  715. },
  716. params: options
  717. }));
  718. case 2:
  719. case "end":
  720. return _context23.stop();
  721. }
  722. }
  723. }, null, null, null, Promise);
  724. },
  725. getTokenAllowance: function () {
  726. var options,
  727. _args24 = arguments;
  728. return _regenerator.default.async(function (_context24) {
  729. while (1) {
  730. switch (_context24.prev = _context24.next) {
  731. case 0:
  732. options = _args24.length > 0 && _args24[0] !== undefined ? _args24[0] : {};
  733. return _context24.abrupt("return", Web3Api.fetch({
  734. endpoint: {
  735. "method": "GET",
  736. "group": "token",
  737. "name": "getTokenAllowance",
  738. "url": "/erc20/:address/allowance"
  739. },
  740. params: options
  741. }));
  742. case 2:
  743. case "end":
  744. return _context24.stop();
  745. }
  746. }
  747. }, null, null, null, Promise);
  748. },
  749. searchNFTs: function () {
  750. var options,
  751. _args25 = arguments;
  752. return _regenerator.default.async(function (_context25) {
  753. while (1) {
  754. switch (_context25.prev = _context25.next) {
  755. case 0:
  756. options = _args25.length > 0 && _args25[0] !== undefined ? _args25[0] : {};
  757. return _context25.abrupt("return", Web3Api.fetch({
  758. endpoint: {
  759. "method": "GET",
  760. "group": "token",
  761. "name": "searchNFTs",
  762. "url": "/nft/search"
  763. },
  764. params: options
  765. }));
  766. case 2:
  767. case "end":
  768. return _context25.stop();
  769. }
  770. }
  771. }, null, null, null, Promise);
  772. },
  773. getNftTransfersFromToBlock: function () {
  774. var options,
  775. _args26 = arguments;
  776. return _regenerator.default.async(function (_context26) {
  777. while (1) {
  778. switch (_context26.prev = _context26.next) {
  779. case 0:
  780. options = _args26.length > 0 && _args26[0] !== undefined ? _args26[0] : {};
  781. return _context26.abrupt("return", Web3Api.fetch({
  782. endpoint: {
  783. "method": "GET",
  784. "group": "token",
  785. "name": "getNftTransfersFromToBlock",
  786. "url": "/nft/transfers"
  787. },
  788. params: options
  789. }));
  790. case 2:
  791. case "end":
  792. return _context26.stop();
  793. }
  794. }
  795. }, null, null, null, Promise);
  796. },
  797. getAllTokenIds: function () {
  798. var options,
  799. _args27 = arguments;
  800. return _regenerator.default.async(function (_context27) {
  801. while (1) {
  802. switch (_context27.prev = _context27.next) {
  803. case 0:
  804. options = _args27.length > 0 && _args27[0] !== undefined ? _args27[0] : {};
  805. return _context27.abrupt("return", Web3Api.fetch({
  806. endpoint: {
  807. "method": "GET",
  808. "group": "token",
  809. "name": "getAllTokenIds",
  810. "url": "/nft/:address"
  811. },
  812. params: options
  813. }));
  814. case 2:
  815. case "end":
  816. return _context27.stop();
  817. }
  818. }
  819. }, null, null, null, Promise);
  820. },
  821. getContractNFTTransfers: function () {
  822. var options,
  823. _args28 = arguments;
  824. return _regenerator.default.async(function (_context28) {
  825. while (1) {
  826. switch (_context28.prev = _context28.next) {
  827. case 0:
  828. options = _args28.length > 0 && _args28[0] !== undefined ? _args28[0] : {};
  829. return _context28.abrupt("return", Web3Api.fetch({
  830. endpoint: {
  831. "method": "GET",
  832. "group": "token",
  833. "name": "getContractNFTTransfers",
  834. "url": "/nft/:address/transfers"
  835. },
  836. params: options
  837. }));
  838. case 2:
  839. case "end":
  840. return _context28.stop();
  841. }
  842. }
  843. }, null, null, null, Promise);
  844. },
  845. getNFTOwners: function () {
  846. var options,
  847. _args29 = arguments;
  848. return _regenerator.default.async(function (_context29) {
  849. while (1) {
  850. switch (_context29.prev = _context29.next) {
  851. case 0:
  852. options = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
  853. return _context29.abrupt("return", Web3Api.fetch({
  854. endpoint: {
  855. "method": "GET",
  856. "group": "token",
  857. "name": "getNFTOwners",
  858. "url": "/nft/:address/owners"
  859. },
  860. params: options
  861. }));
  862. case 2:
  863. case "end":
  864. return _context29.stop();
  865. }
  866. }
  867. }, null, null, null, Promise);
  868. },
  869. getNFTMetadata: function () {
  870. var options,
  871. _args30 = arguments;
  872. return _regenerator.default.async(function (_context30) {
  873. while (1) {
  874. switch (_context30.prev = _context30.next) {
  875. case 0:
  876. options = _args30.length > 0 && _args30[0] !== undefined ? _args30[0] : {};
  877. return _context30.abrupt("return", Web3Api.fetch({
  878. endpoint: {
  879. "method": "GET",
  880. "group": "token",
  881. "name": "getNFTMetadata",
  882. "url": "/nft/:address/metadata"
  883. },
  884. params: options
  885. }));
  886. case 2:
  887. case "end":
  888. return _context30.stop();
  889. }
  890. }
  891. }, null, null, null, Promise);
  892. },
  893. reSyncMetadata: function () {
  894. var options,
  895. _args31 = arguments;
  896. return _regenerator.default.async(function (_context31) {
  897. while (1) {
  898. switch (_context31.prev = _context31.next) {
  899. case 0:
  900. options = _args31.length > 0 && _args31[0] !== undefined ? _args31[0] : {};
  901. return _context31.abrupt("return", Web3Api.fetch({
  902. endpoint: {
  903. "method": "GET",
  904. "group": "token",
  905. "name": "reSyncMetadata",
  906. "url": "/nft/:address/:token_id/metadata/resync"
  907. },
  908. params: options
  909. }));
  910. case 2:
  911. case "end":
  912. return _context31.stop();
  913. }
  914. }
  915. }, null, null, null, Promise);
  916. },
  917. syncNFTContract: function () {
  918. var options,
  919. _args32 = arguments;
  920. return _regenerator.default.async(function (_context32) {
  921. while (1) {
  922. switch (_context32.prev = _context32.next) {
  923. case 0:
  924. options = _args32.length > 0 && _args32[0] !== undefined ? _args32[0] : {};
  925. return _context32.abrupt("return", Web3Api.fetch({
  926. endpoint: {
  927. "method": "PUT",
  928. "group": "token",
  929. "name": "syncNFTContract",
  930. "url": "/nft/:address/sync"
  931. },
  932. params: options
  933. }));
  934. case 2:
  935. case "end":
  936. return _context32.stop();
  937. }
  938. }
  939. }, null, null, null, Promise);
  940. },
  941. getTokenIdMetadata: function () {
  942. var options,
  943. _args33 = arguments;
  944. return _regenerator.default.async(function (_context33) {
  945. while (1) {
  946. switch (_context33.prev = _context33.next) {
  947. case 0:
  948. options = _args33.length > 0 && _args33[0] !== undefined ? _args33[0] : {};
  949. return _context33.abrupt("return", Web3Api.fetch({
  950. endpoint: {
  951. "method": "GET",
  952. "group": "token",
  953. "name": "getTokenIdMetadata",
  954. "url": "/nft/:address/:token_id"
  955. },
  956. params: options
  957. }));
  958. case 2:
  959. case "end":
  960. return _context33.stop();
  961. }
  962. }
  963. }, null, null, null, Promise);
  964. },
  965. getTokenIdOwners: function () {
  966. var options,
  967. _args34 = arguments;
  968. return _regenerator.default.async(function (_context34) {
  969. while (1) {
  970. switch (_context34.prev = _context34.next) {
  971. case 0:
  972. options = _args34.length > 0 && _args34[0] !== undefined ? _args34[0] : {};
  973. return _context34.abrupt("return", Web3Api.fetch({
  974. endpoint: {
  975. "method": "GET",
  976. "group": "token",
  977. "name": "getTokenIdOwners",
  978. "url": "/nft/:address/:token_id/owners"
  979. },
  980. params: options
  981. }));
  982. case 2:
  983. case "end":
  984. return _context34.stop();
  985. }
  986. }
  987. }, null, null, null, Promise);
  988. },
  989. getWalletTokenIdTransfers: function () {
  990. var options,
  991. _args35 = arguments;
  992. return _regenerator.default.async(function (_context35) {
  993. while (1) {
  994. switch (_context35.prev = _context35.next) {
  995. case 0:
  996. options = _args35.length > 0 && _args35[0] !== undefined ? _args35[0] : {};
  997. return _context35.abrupt("return", Web3Api.fetch({
  998. endpoint: {
  999. "method": "GET",
  1000. "group": "token",
  1001. "name": "getWalletTokenIdTransfers",
  1002. "url": "/nft/:address/:token_id/transfers"
  1003. },
  1004. params: options
  1005. }));
  1006. case 2:
  1007. case "end":
  1008. return _context35.stop();
  1009. }
  1010. }
  1011. }, null, null, null, Promise);
  1012. }
  1013. };
  1014. Web3Api.resolve = {
  1015. resolveDomain: function () {
  1016. var options,
  1017. _args36 = arguments;
  1018. return _regenerator.default.async(function (_context36) {
  1019. while (1) {
  1020. switch (_context36.prev = _context36.next) {
  1021. case 0:
  1022. options = _args36.length > 0 && _args36[0] !== undefined ? _args36[0] : {};
  1023. return _context36.abrupt("return", Web3Api.fetch({
  1024. endpoint: {
  1025. "method": "GET",
  1026. "group": "resolve",
  1027. "name": "resolveDomain",
  1028. "url": "/resolve/:domain"
  1029. },
  1030. params: options
  1031. }));
  1032. case 2:
  1033. case "end":
  1034. return _context36.stop();
  1035. }
  1036. }
  1037. }, null, null, null, Promise);
  1038. },
  1039. resolveAddress: function () {
  1040. var options,
  1041. _args37 = arguments;
  1042. return _regenerator.default.async(function (_context37) {
  1043. while (1) {
  1044. switch (_context37.prev = _context37.next) {
  1045. case 0:
  1046. options = _args37.length > 0 && _args37[0] !== undefined ? _args37[0] : {};
  1047. return _context37.abrupt("return", Web3Api.fetch({
  1048. endpoint: {
  1049. "method": "GET",
  1050. "group": "resolve",
  1051. "name": "resolveAddress",
  1052. "url": "/resolve/:address/reverse"
  1053. },
  1054. params: options
  1055. }));
  1056. case 2:
  1057. case "end":
  1058. return _context37.stop();
  1059. }
  1060. }
  1061. }, null, null, null, Promise);
  1062. }
  1063. };
  1064. Web3Api.defi = {
  1065. getPairReserves: function () {
  1066. var options,
  1067. _args38 = arguments;
  1068. return _regenerator.default.async(function (_context38) {
  1069. while (1) {
  1070. switch (_context38.prev = _context38.next) {
  1071. case 0:
  1072. options = _args38.length > 0 && _args38[0] !== undefined ? _args38[0] : {};
  1073. return _context38.abrupt("return", Web3Api.fetch({
  1074. endpoint: {
  1075. "method": "GET",
  1076. "group": "defi",
  1077. "name": "getPairReserves",
  1078. "url": "/:pair_address/reserves"
  1079. },
  1080. params: options
  1081. }));
  1082. case 2:
  1083. case "end":
  1084. return _context38.stop();
  1085. }
  1086. }
  1087. }, null, null, null, Promise);
  1088. },
  1089. getPairAddress: function () {
  1090. var options,
  1091. _args39 = arguments;
  1092. return _regenerator.default.async(function (_context39) {
  1093. while (1) {
  1094. switch (_context39.prev = _context39.next) {
  1095. case 0:
  1096. options = _args39.length > 0 && _args39[0] !== undefined ? _args39[0] : {};
  1097. return _context39.abrupt("return", Web3Api.fetch({
  1098. endpoint: {
  1099. "method": "GET",
  1100. "group": "defi",
  1101. "name": "getPairAddress",
  1102. "url": "/:token0_address/:token1_address/pairAddress"
  1103. },
  1104. params: options
  1105. }));
  1106. case 2:
  1107. case "end":
  1108. return _context39.stop();
  1109. }
  1110. }
  1111. }, null, null, null, Promise);
  1112. }
  1113. };
  1114. Web3Api.storage = {
  1115. uploadFolder: function () {
  1116. var options,
  1117. _args40 = arguments;
  1118. return _regenerator.default.async(function (_context40) {
  1119. while (1) {
  1120. switch (_context40.prev = _context40.next) {
  1121. case 0:
  1122. options = _args40.length > 0 && _args40[0] !== undefined ? _args40[0] : {};
  1123. return _context40.abrupt("return", Web3Api.fetch({
  1124. endpoint: {
  1125. "method": "POST",
  1126. "group": "storage",
  1127. "name": "uploadFolder",
  1128. "url": "/ipfs/uploadFolder",
  1129. "bodyParams": [{
  1130. "key": "data",
  1131. "type": "set body",
  1132. "required": false
  1133. }]
  1134. },
  1135. params: options
  1136. }));
  1137. case 2:
  1138. case "end":
  1139. return _context40.stop();
  1140. }
  1141. }
  1142. }, null, null, null, Promise);
  1143. }
  1144. };
  1145. Web3Api.info = {
  1146. web3ApiVersion: function () {
  1147. var options,
  1148. _args41 = arguments;
  1149. return _regenerator.default.async(function (_context41) {
  1150. while (1) {
  1151. switch (_context41.prev = _context41.next) {
  1152. case 0:
  1153. options = _args41.length > 0 && _args41[0] !== undefined ? _args41[0] : {};
  1154. return _context41.abrupt("return", Web3Api.fetch({
  1155. endpoint: {
  1156. "method": "GET",
  1157. "group": "info",
  1158. "name": "web3ApiVersion",
  1159. "url": "/web3/version"
  1160. },
  1161. params: options
  1162. }));
  1163. case 2:
  1164. case "end":
  1165. return _context41.stop();
  1166. }
  1167. }
  1168. }, null, null, null, Promise);
  1169. },
  1170. endpointWeights: function () {
  1171. var options,
  1172. _args42 = arguments;
  1173. return _regenerator.default.async(function (_context42) {
  1174. while (1) {
  1175. switch (_context42.prev = _context42.next) {
  1176. case 0:
  1177. options = _args42.length > 0 && _args42[0] !== undefined ? _args42[0] : {};
  1178. return _context42.abrupt("return", Web3Api.fetch({
  1179. endpoint: {
  1180. "method": "GET",
  1181. "group": "info",
  1182. "name": "endpointWeights",
  1183. "url": "/info/endpointWeights"
  1184. },
  1185. params: options
  1186. }));
  1187. case 2:
  1188. case "end":
  1189. return _context42.stop();
  1190. }
  1191. }
  1192. }, null, null, null, Promise);
  1193. }
  1194. };
  1195. var _default = Web3Api;
  1196. exports.default = _default;