123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- function ownKeys(object, enumerableOnly) {
- var keys = Object.keys(object);
- if (Object.getOwnPropertySymbols) {
- var symbols = Object.getOwnPropertySymbols(object);
- enumerableOnly && (symbols = symbols.filter(function (sym) {
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
- })), keys.push.apply(keys, symbols);
- }
- return keys;
- }
- function _objectSpread(target) {
- for (var i = 1; i < arguments.length; i++) {
- var source = null != arguments[i] ? arguments[i] : {};
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
- _defineProperty(target, key, source[key]);
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
- });
- }
- return target;
- }
- function _defineProperty(obj, key, value) {
- if (key in obj) {
- Object.defineProperty(obj, key, {
- value: value,
- enumerable: true,
- configurable: true,
- writable: true
- });
- } else {
- obj[key] = value;
- }
- return obj;
- }
- /**
- * Automatically generated code, via genWeb3API.js
- * Do not modify manually
- */
- const axios = require('axios');
- class Web3Api {
- static initialize({
- apiKey,
- serverUrl,
- Moralis = null
- }) {
- if (!serverUrl && !apiKey) {
- throw new Error('Web3Api.initialize failed: initialize with apiKey or serverUrl');
- }
- if (apiKey) this.apiKey = apiKey;
- if (serverUrl) this.serverUrl = serverUrl;
- this.Moralis = Moralis;
- }
- static getBody(params, bodyParams) {
- if (!params || !bodyParams || !bodyParams.length) {
- return undefined;
- }
- let body = {};
- bodyParams.forEach(({
- key,
- type,
- required
- }) => {
- if (params[key] === undefined) {
- if (required) throw new Error(`param ${key} is required!`);
- } else if (type === this.BodyParamTypes.setBody) {
- body = params[key];
- } else {
- body[key] = params[key];
- } // remove the param so it doesn't also get added as a query param
- delete params[key];
- });
- return body;
- }
- static getParameterizedUrl(url, params) {
- if (!Object.keys(params).length) return url; // find url params, they start with :
- const requiredParams = url.split('/').filter(s => s && s.includes(':'));
- if (!requiredParams.length) return url;
- let parameterizedUrl = url;
- requiredParams.forEach(p => {
- // strip the : and replace with param value
- const key = p.substr(1);
- const value = params[key];
- if (!value) {
- throw new Error(`required param ${key} not provided`);
- }
- parameterizedUrl = parameterizedUrl.replace(p, value); // remove required param from param list
- // so it doesn't become part of the query params
- delete params[key];
- });
- return parameterizedUrl;
- }
- static getApiRateLimitInfo(headers) {
- return {
- 'x-rate-limit-limit': headers['x-rate-limit-limit'],
- 'x-rate-limit-remaining-ttl': headers['x-rate-limit-remaining-ttl'],
- 'x-rate-limit-used': headers['x-rate-limit-used'],
- 'x-rate-limit-remaining-ip-ttl': headers['x-rate-limit-remaining-ip-ttl'],
- 'x-rate-limit-ip-used': headers['x-rate-limit-ip-used']
- };
- }
- static getApiErrorMessage(error, url) {
- var _error$response, _error$response$data;
- return (error === null || error === void 0 ? void 0 : (_error$response = error.response) === null || _error$response === void 0 ? void 0 : (_error$response$data = _error$response.data) === null || _error$response$data === void 0 ? void 0 : _error$response$data.message) || (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString()) || `Web3 API error while calling ${url}`;
- }
- static async fetch({
- endpoint,
- params: providedParams
- }) {
- // Make a shallow copy to prevent modification of original params
- const params = _objectSpread({}, providedParams);
- if (this.Moralis) {
- const {
- User,
- account
- } = this.Moralis;
- const user = User.current();
- if (!params.address) {
- if (user) {
- params.address = user.get('ethAddress');
- } else if (account) {
- params.address = account;
- }
- }
- }
- if (!this.apiKey) {
- return this.fetchFromServer(endpoint.name, params);
- }
- return this.fetchFromApi(endpoint, params);
- }
- static async fetchFromApi(endpoint, params) {
- const {
- method = 'GET',
- url,
- bodyParams
- } = endpoint;
- try {
- const parameterizedUrl = this.getParameterizedUrl(url, params);
- const body = this.getBody(params, bodyParams);
- const response = await axios(this.baseURL + parameterizedUrl, {
- params,
- method,
- body,
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- 'x-api-key': this.apiKey
- }
- });
- return response.data;
- } catch (error) {
- const {
- status,
- headers,
- data
- } = error.response;
- let msg;
- if (status === 429) {
- 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))}`;
- } else {
- msg = this.getApiErrorMessage(error, url);
- }
- throw new Error(msg);
- }
- }
- static async fetchFromServer(name, options) {
- if (!this.serverUrl) {
- throw new Error('Web3Api not initialized, run Moralis.start() first');
- }
- try {
- const http = axios.create({
- baseURL: this.serverUrl
- });
- if (!options.chain) options.chain = 'eth';
- const user = this.Moralis.User.current();
- if (user) {
- options._SessionToken = user.attributes.sessionToken;
- options._ApplicationId = this.Moralis.applicationId;
- }
- const response = await http.post(`/functions/${name}`, options, {
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json'
- }
- });
- return response.data.result;
- } catch (error) {
- var _error$response2, _error$response2$data;
- if ((_error$response2 = error.response) !== null && _error$response2 !== void 0 && (_error$response2$data = _error$response2.data) !== null && _error$response2$data !== void 0 && _error$response2$data.error) {
- throw new Error(error.response.data.error);
- }
- throw error;
- }
- }
- }
- _defineProperty(Web3Api, "baseURL", 'https://deep-index.moralis.io/api/v2');
- _defineProperty(Web3Api, "BodyParamTypes", {
- setBody: 'set body',
- property: 'property'
- });
- _defineProperty(Web3Api, "native", {
- getBlock: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "native",
- "name": "getBlock",
- "url": "/block/:block_number_or_hash"
- },
- params: options
- }),
- getDateToBlock: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "native",
- "name": "getDateToBlock",
- "url": "/dateToBlock"
- },
- params: options
- }),
- getLogsByAddress: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "native",
- "name": "getLogsByAddress",
- "url": "/:address/logs"
- },
- params: options
- }),
- getNFTTransfersByBlock: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "native",
- "name": "getNFTTransfersByBlock",
- "url": "/block/:block_number_or_hash/nft/transfers"
- },
- params: options
- }),
- getTransaction: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "native",
- "name": "getTransaction",
- "url": "/transaction/:transaction_hash"
- },
- params: options
- }),
- getContractEvents: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "POST",
- "group": "native",
- "name": "getContractEvents",
- "url": "/:address/events",
- "bodyParams": [{
- "key": "data",
- "type": "set body",
- "required": false
- }]
- },
- params: options
- }),
- runContractFunction: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "POST",
- "group": "native",
- "name": "runContractFunction",
- "url": "/:address/function",
- "bodyParams": [{
- "key": "abi",
- "type": "property",
- "required": true
- }, {
- "key": "params",
- "type": "property",
- "required": false
- }]
- },
- params: options
- })
- });
- _defineProperty(Web3Api, "account", {
- getTransactions: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "account",
- "name": "getTransactions",
- "url": "/:address"
- },
- params: options
- }),
- getNativeBalance: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "account",
- "name": "getNativeBalance",
- "url": "/:address/balance"
- },
- params: options
- }),
- getTokenBalances: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "account",
- "name": "getTokenBalances",
- "url": "/:address/erc20"
- },
- params: options
- }),
- getTokenTransfers: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "account",
- "name": "getTokenTransfers",
- "url": "/:address/erc20/transfers"
- },
- params: options
- }),
- getNFTs: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "account",
- "name": "getNFTs",
- "url": "/:address/nft"
- },
- params: options
- }),
- getNFTTransfers: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "account",
- "name": "getNFTTransfers",
- "url": "/:address/nft/transfers"
- },
- params: options
- }),
- getNFTsForContract: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "account",
- "name": "getNFTsForContract",
- "url": "/:address/nft/:token_address"
- },
- params: options
- })
- });
- _defineProperty(Web3Api, "token", {
- getTokenMetadata: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getTokenMetadata",
- "url": "/erc20/metadata"
- },
- params: options
- }),
- getNFTTrades: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getNFTTrades",
- "url": "/nft/:address/trades"
- },
- params: options
- }),
- getNFTLowestPrice: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getNFTLowestPrice",
- "url": "/nft/:address/lowestprice"
- },
- params: options
- }),
- getTokenMetadataBySymbol: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getTokenMetadataBySymbol",
- "url": "/erc20/metadata/symbols"
- },
- params: options
- }),
- getTokenPrice: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getTokenPrice",
- "url": "/erc20/:address/price"
- },
- params: options
- }),
- getTokenAddressTransfers: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getTokenAddressTransfers",
- "url": "/erc20/:address/transfers"
- },
- params: options
- }),
- getTokenAllowance: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getTokenAllowance",
- "url": "/erc20/:address/allowance"
- },
- params: options
- }),
- searchNFTs: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "searchNFTs",
- "url": "/nft/search"
- },
- params: options
- }),
- getNftTransfersFromToBlock: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getNftTransfersFromToBlock",
- "url": "/nft/transfers"
- },
- params: options
- }),
- getAllTokenIds: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getAllTokenIds",
- "url": "/nft/:address"
- },
- params: options
- }),
- getContractNFTTransfers: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getContractNFTTransfers",
- "url": "/nft/:address/transfers"
- },
- params: options
- }),
- getNFTOwners: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getNFTOwners",
- "url": "/nft/:address/owners"
- },
- params: options
- }),
- getNFTMetadata: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getNFTMetadata",
- "url": "/nft/:address/metadata"
- },
- params: options
- }),
- reSyncMetadata: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "reSyncMetadata",
- "url": "/nft/:address/:token_id/metadata/resync"
- },
- params: options
- }),
- syncNFTContract: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "PUT",
- "group": "token",
- "name": "syncNFTContract",
- "url": "/nft/:address/sync"
- },
- params: options
- }),
- getTokenIdMetadata: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getTokenIdMetadata",
- "url": "/nft/:address/:token_id"
- },
- params: options
- }),
- getTokenIdOwners: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getTokenIdOwners",
- "url": "/nft/:address/:token_id/owners"
- },
- params: options
- }),
- getWalletTokenIdTransfers: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "token",
- "name": "getWalletTokenIdTransfers",
- "url": "/nft/:address/:token_id/transfers"
- },
- params: options
- })
- });
- _defineProperty(Web3Api, "resolve", {
- resolveDomain: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "resolve",
- "name": "resolveDomain",
- "url": "/resolve/:domain"
- },
- params: options
- }),
- resolveAddress: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "resolve",
- "name": "resolveAddress",
- "url": "/resolve/:address/reverse"
- },
- params: options
- })
- });
- _defineProperty(Web3Api, "defi", {
- getPairReserves: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "defi",
- "name": "getPairReserves",
- "url": "/:pair_address/reserves"
- },
- params: options
- }),
- getPairAddress: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "defi",
- "name": "getPairAddress",
- "url": "/:token0_address/:token1_address/pairAddress"
- },
- params: options
- })
- });
- _defineProperty(Web3Api, "storage", {
- uploadFolder: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "POST",
- "group": "storage",
- "name": "uploadFolder",
- "url": "/ipfs/uploadFolder",
- "bodyParams": [{
- "key": "data",
- "type": "set body",
- "required": false
- }]
- },
- params: options
- })
- });
- _defineProperty(Web3Api, "info", {
- web3ApiVersion: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "info",
- "name": "web3ApiVersion",
- "url": "/web3/version"
- },
- params: options
- }),
- endpointWeights: async (options = {}) => Web3Api.fetch({
- endpoint: {
- "method": "GET",
- "group": "info",
- "name": "endpointWeights",
- "url": "/info/endpointWeights"
- },
- params: options
- })
- });
- var _default = Web3Api;
- exports.default = _default;
|