Skip to content

Commit d110055

Browse files
authored
Merge pull request #1361 from starknet-io/feat/fetch-remove
Remove fetch dependencies
2 parents 5b7fdf1 + c60be42 commit d110055

File tree

9 files changed

+2206
-1375
lines changed

9 files changed

+2206
-1375
lines changed

__tests__/utils/batch.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fetch from '../../src/utils/fetchPonyfill';
1+
import fetch from '../../src/utils/fetch';
22
import { BatchClient } from '../../src/utils/batch';
33
import { createBlockForDevnet, createTestProvider } from '../config/fixtures';
44
import { initializeMatcher } from '../config/schema';

package-lock.json

+2,178-1,074
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"fetch-intercept": "^2.4.0",
8484
"husky": "^9.0.11",
8585
"import-sort-style-module": "^6.0.0",
86+
"isomorphic-fetch": "~3.0.0",
8687
"jest": "^29.5.0",
8788
"jest-environment-jsdom": "^29.5.0",
8889
"jest-json-schema": "^6.1.0",
@@ -101,9 +102,7 @@
101102
"@noble/hashes": "1.6.0",
102103
"@scure/base": "1.2.1",
103104
"@scure/starknet": "1.1.0",
104-
"abi-wan-kanabi": "^2.2.3",
105-
"fetch-cookie": "~3.0.0",
106-
"isomorphic-fetch": "~3.0.0",
105+
"abi-wan-kanabi": "2.2.4",
107106
"isows": "^1.0.6",
108107
"lossless-json": "^4.0.1",
109108
"pako": "^2.0.4",

src/channel/rpc_0_7.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { BatchClient } from '../utils/batch';
2828
import { CallData } from '../utils/calldata';
2929
import { isSierra } from '../utils/contract';
3030
import { validateAndParseEthAddress } from '../utils/eth';
31-
import fetch from '../utils/fetchPonyfill';
31+
import fetch from '../utils/fetch';
3232
import { getSelector, getSelectorFromName } from '../utils/hash';
3333
import { stringify } from '../utils/json';
3434
import { getHexStringArray, toHex, toStorageKey } from '../utils/num';

src/channel/rpc_0_8.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { BatchClient } from '../utils/batch';
2828
import { CallData } from '../utils/calldata';
2929
import { isSierra } from '../utils/contract';
3030
import { validateAndParseEthAddress } from '../utils/eth';
31-
import fetch from '../utils/fetchPonyfill';
31+
import fetch from '../utils/fetch';
3232
import { getSelector, getSelectorFromName } from '../utils/hash';
3333
import { stringify } from '../utils/json';
3434
import {

src/utils/fetch.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { IS_BROWSER } from './encode';
2+
import { LibraryError } from './errors';
3+
import { isUndefined } from './typed';
4+
5+
export default (IS_BROWSER && window.fetch.bind(window)) || // use built-in fetch in browser if available
6+
(!isUndefined(global) && global.fetch) || // use built-in fetch in node, react-native and service worker if available
7+
// throw with instructions when no fetch is detected
8+
((() => {
9+
throw new LibraryError(
10+
"'fetch()' not detected, use the 'baseFetch' constructor parameter to set it"
11+
);
12+
}) as WindowOrWorkerGlobalScope['fetch']);

src/utils/fetchPonyfill.ts

-10
This file was deleted.

www/docs/guides/migrate.md

+11-90
Original file line numberDiff line numberDiff line change
@@ -2,104 +2,25 @@
22
sidebar_position: 101
33
---
44

5-
# Migrate from v5 to v6
5+
# Migrate from v6 to v7
66

7-
This document only covers the features present in v5 which have changed in some significant way in v6.
7+
This document only covers the features present in v6 which have changed in some significant way in v7.
88

99
If you encounter any missing changes, please let us know and we will update this guide.
1010

11-
## Transaction receipt
11+
## Fetch dependencies
1212

13-
When sending a transaction, the receipt type has changed.
14-
In V5, it's an object that can have varied definitions, depending on the status and the type of transaction.
15-
In V6, this object is in `TxR.value`, and several helpers are available (`.statusReceipt`, `isSuccess()`, `isRejected()`, `isReverted()`, `.isError()`, `match`, ...)
13+
`isomorphic-fetch` and `fetch-cookie` have been removed as dependencies.
1614

17-
```typescript
18-
const response = await ethContract.approve(swapContractAddress, cairo.uint256(100000));
19-
const transactionReceipt = await provider.waitForTransaction(response.transaction_hash);
20-
21-
// v5 : transactionReceipt is just an object
22-
{
23-
type: 'INVOKE',
24-
transaction_hash: '0x5286217518c621581ac85505a99ffe182ce1114abaa8fce8b418d2b27c3c04c',
25-
actual_fee: { unit: 'WEI', amount: '0x1c1902fe99800' },
26-
messages_sent: [],
27-
execution_status: 'SUCCEEDED',
28-
finality_status: 'ACCEPTED_ON_L2',
29-
// ...
30-
}
31-
// v6 : transactionReceipt is an object + helpers
32-
const receipt = transactionReceipt.value;
33-
const status: boolean = transactionReceipt.isSuccess();
34-
35-
```
36-
37-
> See this [guide](./interact.md#transaction-receipt-response)
38-
39-
## Long strings
40-
41-
Starknet.js v6 is compatible with Cairo v2.4.0. It means that long strings (>31 characters) are automatically handled and converted to the Cairo `ByteArray` type.
42-
This means that the approach to convert a long string to an array of felts (for Cairo 0 contracts for example) has changed:
15+
For users who might require the features of either library, a `baseFetch` override parameter has been enabled for the `RpcProvider` and `RpcChannel` classes, including classes that inherit from them such as `Account` and `WalletAccount`.
4316

4417
```typescript
45-
// v5
46-
const feltArray: BigNumberish[] = CallData.compile(
47-
'http://addressOfMyERC721pictures/storage/image1.jpg'
48-
);
18+
import makeFetchCookie from 'fetch-cookie';
19+
import isomorphicFetch from 'isomorphic-fetch';
4920

50-
// v6
51-
const feltArray: BigNumberish[] = CallData.compile(
52-
shortString.splitLongString('http://addressOfMyERC721pictures/storage/image1.jpg')
53-
);
21+
const provider = new RpcProvider({
22+
baseFetch: makeFetchCookie(isomorphicFetch),
23+
});
5424
```
5525

56-
## Fees
57-
58-
All functions related to gas price and fee estimation have changed output types.
59-
60-
For example, if you read the content of a block with v5 the ETH gas price was a top level property, with v6 the same information is nested a level deeper:
61-
62-
```typescript
63-
const resp: GetBlockResponse = await myProvider.getBlock('latest');
64-
65-
// v5
66-
const gasPrice = resp.gas_price;
67-
68-
// v6
69-
const gasPrice = resp.l1_gas_price.price_in_wei;
70-
```
71-
72-
Another example is `estimateDeclareFee()` where the response object has changed:
73-
74-
```typescript
75-
const fee = await account0.estimateDeclareFee({ contract: compiledContract });
76-
77-
// v5 response
78-
fee = {
79-
overall_fee: 247700000000000n,
80-
gas_consumed: 2477n,
81-
gas_price: 100000000000n,
82-
suggestedMaxFee: 371550000000000n,
83-
};
84-
85-
// v6 response
86-
fee = {
87-
overall_fee: 247700000000000n,
88-
gas_consumed: 2477n,
89-
gas_price: 100000000000n,
90-
unit: undefined,
91-
suggestedMaxFee: 371550000000000n,
92-
resourceBounds: {
93-
l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
94-
l1_gas: { max_amount: '0xaa4', max_price_per_unit: '0x22ecb25c00' },
95-
},
96-
};
97-
```
98-
99-
You have to adapt your code to all these new entries.
100-
In general, pay attention to the result types of methods that return a response from an RPC node.
101-
102-
<br/>
103-
<hr/>
104-
105-
For the old v4 to v5 migration instructions check [here](./migrate_v4).
26+
## ...

www/docs/guides/migrate_v4.md

-195
This file was deleted.

0 commit comments

Comments
 (0)