diff --git a/__tests__/jest.setup.ts b/__tests__/jest.setup.ts index 7183664bb..339df0c36 100644 --- a/__tests__/jest.setup.ts +++ b/__tests__/jest.setup.ts @@ -1,6 +1,6 @@ -/* eslint-disable no-console */ -import 'isomorphic-unfetch'; +import 'isomorphic-fetch'; +/* eslint-disable no-console */ import { register } from 'fetch-intercept'; jest.setTimeout(50 * 60 * 1000); diff --git a/package-lock.json b/package-lock.json index 8e79bb96c..d6e5f4280 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "elliptic": "^6.5.4", "ethereum-cryptography": "^1.0.3", "hash.js": "^1.1.7", - "isomorphic-unfetch": "^3.1.0", + "isomorphic-fetch": "^3.0.0", "json-bigint": "^1.0.0", "minimalistic-assert": "^1.0.1", "pako": "^2.0.4", @@ -7669,13 +7669,13 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, - "node_modules/isomorphic-unfetch": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/isomorphic-unfetch/-/isomorphic-unfetch-3.1.0.tgz", - "integrity": "sha512-geDJjpoZ8N0kWexiwkX8F9NkTsXhetLPVbZFQ+JTW239QNOwvB0gniuR1Wc6f0AMTn7/mFGyXvHTifrCp/GH8Q==", + "node_modules/isomorphic-fetch": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz", + "integrity": "sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==", "dependencies": { "node-fetch": "^2.6.1", - "unfetch": "^4.2.0" + "whatwg-fetch": "^3.4.1" } }, "node_modules/issue-parser": { @@ -15599,11 +15599,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/unfetch": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/unfetch/-/unfetch-4.2.0.tgz", - "integrity": "sha512-F9p7yYCn6cIW9El1zi0HI6vqpeIvBsr3dSuRO6Xuppb1u5rXpCPmMvLSyECLhybr9isec8Ohl0hPekMVrEinDA==" - }, "node_modules/unicode-canonical-property-names-ecmascript": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", @@ -15794,8 +15789,7 @@ "node_modules/whatwg-fetch": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz", - "integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==", - "dev": true + "integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==" }, "node_modules/whatwg-mimetype": { "version": "3.0.0", @@ -21821,13 +21815,13 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, - "isomorphic-unfetch": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/isomorphic-unfetch/-/isomorphic-unfetch-3.1.0.tgz", - "integrity": "sha512-geDJjpoZ8N0kWexiwkX8F9NkTsXhetLPVbZFQ+JTW239QNOwvB0gniuR1Wc6f0AMTn7/mFGyXvHTifrCp/GH8Q==", + "isomorphic-fetch": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz", + "integrity": "sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==", "requires": { "node-fetch": "^2.6.1", - "unfetch": "^4.2.0" + "whatwg-fetch": "^3.4.1" } }, "issue-parser": { @@ -27721,11 +27715,6 @@ "which-boxed-primitive": "^1.0.2" } }, - "unfetch": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/unfetch/-/unfetch-4.2.0.tgz", - "integrity": "sha512-F9p7yYCn6cIW9El1zi0HI6vqpeIvBsr3dSuRO6Xuppb1u5rXpCPmMvLSyECLhybr9isec8Ohl0hPekMVrEinDA==" - }, "unicode-canonical-property-names-ecmascript": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", @@ -27886,8 +27875,7 @@ "whatwg-fetch": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz", - "integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==", - "dev": true + "integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==" }, "whatwg-mimetype": { "version": "3.0.0", diff --git a/package.json b/package.json index 869994566..4258ccd84 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "elliptic": "^6.5.4", "ethereum-cryptography": "^1.0.3", "hash.js": "^1.1.7", - "isomorphic-unfetch": "^3.1.0", + "isomorphic-fetch": "^3.0.0", "json-bigint": "^1.0.0", "minimalistic-assert": "^1.0.1", "pako": "^2.0.4", diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index 29e8f37d8..fc9c585cb 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -1,5 +1,3 @@ -import fetch from 'isomorphic-unfetch'; - import { StarknetChainId } from '../constants'; import { BlockTag, @@ -18,6 +16,7 @@ import { InvokeFunctionResponse, } from '../types'; import { RPC } from '../types/api'; +import fetch from '../utils/fetchPonyfill'; import { getSelectorFromName } from '../utils/hash'; import { stringify } from '../utils/json'; import { diff --git a/src/provider/sequencer.ts b/src/provider/sequencer.ts index ff764be70..224075a0e 100644 --- a/src/provider/sequencer.ts +++ b/src/provider/sequencer.ts @@ -1,4 +1,3 @@ -import fetch from 'isomorphic-unfetch'; import urljoin from 'url-join'; import { ONE, StarknetChainId, ZERO } from '../constants'; @@ -25,6 +24,7 @@ import { GetTransactionTraceResponse, Sequencer, } from '../types/api'; +import fetch from '../utils/fetchPonyfill'; import { getSelectorFromName } from '../utils/hash'; import { parse, parseAlwaysAsBig, stringify } from '../utils/json'; import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number'; diff --git a/src/utils/fetchPonyfill.ts b/src/utils/fetchPonyfill.ts new file mode 100644 index 000000000..dbb815814 --- /dev/null +++ b/src/utils/fetchPonyfill.ts @@ -0,0 +1,4 @@ +export default (typeof window !== 'undefined' && window.fetch) || // use buildin fetch in browser if available + (typeof global !== 'undefined' && global.fetch) || // use buildin fetch in node, react-native and service worker if available + // eslint-disable-next-line global-require + require('isomorphic-fetch'); // ponyfill fetch in node and browsers that don't have it diff --git a/www/docs/API/contract.md b/www/docs/API/contract.md index 35e9b3832..0fd3f4fa1 100644 --- a/www/docs/API/contract.md +++ b/www/docs/API/contract.md @@ -22,7 +22,7 @@ contract.**address** => _string_ The address the contract was constructed/connected with -contract.**providerOrAcount** => ProviderInterface | AccountInterface_ +contract.**providerOrAccount** => _ProviderInterface | AccountInterface_ Provider or account that are used to interact with the network