starknet 4.1.0 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/__tests__/defaultProvider.test.ts +11 -24
- package/__tests__/rpcProvider.test.ts +3 -3
- package/__tests__/sequencerProvider.test.ts +40 -2
- package/__tests__/utils/address.test.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/provider/default.d.ts +2 -2
- package/dist/provider/default.js +3 -3
- package/dist/provider/interface.d.ts +6 -3
- package/dist/provider/rpc.d.ts +9 -4
- package/dist/provider/rpc.js +67 -25
- package/dist/provider/sequencer.d.ts +2 -2
- package/dist/provider/sequencer.js +9 -9
- package/dist/provider/utils.d.ts +12 -0
- package/dist/provider/utils.js +17 -1
- package/dist/types/api/openrpc.d.ts +151 -0
- package/dist/types/api/openrpc.js +9 -0
- package/dist/types/api/rpc.d.ts +22 -43
- package/dist/types/provider.d.ts +5 -5
- package/dist/utils/address.js +1 -1
- package/dist/utils/ellipticCurve.d.ts +13 -0
- package/dist/utils/ellipticCurve.js +20 -16
- package/dist/utils/hash.d.ts +1 -0
- package/dist/utils/hash.js +8 -1
- package/dist/utils/responseParser/rpc.d.ts +13 -3
- package/dist/utils/responseParser/rpc.js +2 -10
- package/dist/utils/responseParser/sequencer.d.ts +4 -1
- package/dist/utils/responseParser/sequencer.js +1 -7
- package/dist/utils/url.d.ts +7 -0
- package/dist/utils/url.js +49 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/provider/default.d.ts +2 -2
- package/provider/default.js +3 -3
- package/provider/interface.d.ts +6 -3
- package/provider/rpc.d.ts +9 -4
- package/provider/rpc.js +67 -25
- package/provider/sequencer.d.ts +2 -2
- package/provider/sequencer.js +9 -9
- package/provider/utils.d.ts +12 -0
- package/provider/utils.js +17 -1
- package/src/index.ts +1 -0
- package/src/provider/default.ts +2 -3
- package/src/provider/interface.ts +5 -3
- package/src/provider/rpc.ts +56 -34
- package/src/provider/sequencer.ts +11 -9
- package/src/provider/utils.ts +22 -1
- package/src/types/api/openrpc.ts +168 -0
- package/src/types/api/rpc.ts +22 -45
- package/src/types/provider.ts +5 -5
- package/src/utils/address.ts +2 -2
- package/src/utils/ellipticCurve.ts +20 -16
- package/src/utils/hash.ts +8 -1
- package/src/utils/responseParser/rpc.ts +16 -13
- package/src/utils/responseParser/sequencer.ts +5 -8
- package/src/utils/url.ts +53 -0
- package/types/api/openrpc.d.ts +151 -0
- package/types/api/openrpc.js +9 -0
- package/types/api/rpc.d.ts +22 -43
- package/types/provider.d.ts +5 -5
- package/utils/address.js +1 -1
- package/utils/ellipticCurve.d.ts +13 -0
- package/utils/ellipticCurve.js +20 -16
- package/utils/hash.d.ts +1 -0
- package/utils/hash.js +8 -1
- package/utils/responseParser/rpc.d.ts +13 -3
- package/utils/responseParser/rpc.js +2 -10
- package/utils/responseParser/sequencer.d.ts +4 -1
- package/utils/responseParser/sequencer.js +1 -7
- package/utils/url.d.ts +7 -0
- package/utils/url.js +49 -0
- package/www/docs/API/account.md +20 -18
- package/www/docs/API/contract.md +10 -10
- package/www/docs/API/contractFactory.md +14 -11
- package/www/docs/API/provider.md +60 -37
- package/www/docs/API/signer.md +8 -10
- package/www/docs/API/utils.md +151 -74
- package/www/guides/account.md +25 -3
- package/www/guides/erc20.md +20 -4
- package/www/guides/intro.md +3 -1
package/provider/default.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import {
|
|
2
|
+
import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import { BigNumberish } from '../utils/number';
|
|
4
4
|
import { ProviderInterface } from './interface';
|
|
5
5
|
import { RpcProviderOptions } from './rpc';
|
|
@@ -16,7 +16,7 @@ export declare class Provider implements ProviderInterface {
|
|
|
16
16
|
getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
17
17
|
getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
|
|
18
18
|
getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
|
|
19
|
-
getStorageAt(contractAddress: string, key: BigNumberish,
|
|
19
|
+
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
20
20
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
21
21
|
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
22
22
|
callContract(request: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
package/provider/default.js
CHANGED
|
@@ -86,11 +86,11 @@ var Provider = /** @class */ (function () {
|
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
};
|
|
89
|
-
Provider.prototype.getStorageAt = function (contractAddress, key,
|
|
90
|
-
if (
|
|
89
|
+
Provider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
90
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
91
91
|
return __awaiter(this, void 0, void 0, function () {
|
|
92
92
|
return __generator(this, function (_a) {
|
|
93
|
-
return [2 /*return*/, this.provider.getStorageAt(contractAddress, key,
|
|
93
|
+
return [2 /*return*/, this.provider.getStorageAt(contractAddress, key, blockIdentifier)];
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
96
|
};
|
package/provider/interface.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import type { BigNumberish } from '../utils/number';
|
|
4
4
|
import { BlockIdentifier } from './utils';
|
|
5
5
|
export declare abstract class ProviderInterface {
|
|
@@ -19,6 +19,9 @@ export declare abstract class ProviderInterface {
|
|
|
19
19
|
* @returns the block object
|
|
20
20
|
*/
|
|
21
21
|
abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated The method should not be used
|
|
24
|
+
*/
|
|
22
25
|
abstract getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
23
26
|
/**
|
|
24
27
|
* Gets the contract class of the deployed contract.
|
|
@@ -33,10 +36,10 @@ export declare abstract class ProviderInterface {
|
|
|
33
36
|
*
|
|
34
37
|
* @param contractAddress
|
|
35
38
|
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
36
|
-
* @param
|
|
39
|
+
* @param blockIdentifier - block identifier
|
|
37
40
|
* @returns the value of the storage variable
|
|
38
41
|
*/
|
|
39
|
-
abstract getStorageAt(contractAddress: string, key: BigNumberish,
|
|
42
|
+
abstract getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier: BlockIdentifier): Promise<BigNumberish>;
|
|
40
43
|
/**
|
|
41
44
|
* Gets the transaction information from a tx id.
|
|
42
45
|
*
|
package/provider/rpc.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import {
|
|
2
|
+
import { Call, CallContractResponse, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import { RPC } from '../types/api';
|
|
4
4
|
import { BigNumberish } from '../utils/number';
|
|
5
5
|
import { ProviderInterface } from './interface';
|
|
@@ -15,16 +15,21 @@ export declare class RpcProvider implements ProviderInterface {
|
|
|
15
15
|
protected fetchEndpoint<T extends keyof RPC.Methods>(method: T, request?: RPC.Methods[T]['REQUEST']): Promise<RPC.Methods[T]['RESPONSE']>;
|
|
16
16
|
getChainId(): Promise<StarknetChainId>;
|
|
17
17
|
getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
18
|
-
|
|
18
|
+
getBlockWithTxHashes(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxHashesResponse>;
|
|
19
|
+
getBlockWithTxs(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxs>;
|
|
20
|
+
getNonce(contractAddress: string): Promise<any>;
|
|
21
|
+
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
19
22
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
23
|
+
getTransactionByHash(txHash: BigNumberish): Promise<RPC.GetTransactionByHashResponse>;
|
|
24
|
+
getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
|
|
20
25
|
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
21
|
-
getClassAt(contractAddress: string,
|
|
26
|
+
getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<any>;
|
|
22
27
|
getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
|
|
23
28
|
declareContract({ contract, version, }: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
24
29
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
25
30
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
26
31
|
callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
27
|
-
getCode(
|
|
32
|
+
getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
28
33
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
29
34
|
/**
|
|
30
35
|
* Gets the transaction count from a block.
|
package/provider/rpc.js
CHANGED
|
@@ -47,6 +47,7 @@ var number_1 = require("../utils/number");
|
|
|
47
47
|
var provider_1 = require("../utils/provider");
|
|
48
48
|
var rpc_1 = require("../utils/responseParser/rpc");
|
|
49
49
|
var stark_1 = require("../utils/stark");
|
|
50
|
+
var utils_1 = require("./utils");
|
|
50
51
|
var RpcProvider = /** @class */ (function () {
|
|
51
52
|
function RpcProvider(optionsOrProvider) {
|
|
52
53
|
var _this = this;
|
|
@@ -112,36 +113,78 @@ var RpcProvider = /** @class */ (function () {
|
|
|
112
113
|
});
|
|
113
114
|
});
|
|
114
115
|
};
|
|
116
|
+
// Common Interface
|
|
115
117
|
RpcProvider.prototype.getBlock = function (blockIdentifier) {
|
|
116
118
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
117
119
|
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
-
var method;
|
|
119
120
|
return __generator(this, function (_a) {
|
|
120
|
-
|
|
121
|
-
? 'starknet_getBlockByHash'
|
|
122
|
-
: 'starknet_getBlockByNumber';
|
|
123
|
-
return [2 /*return*/, this.fetchEndpoint(method, [blockIdentifier]).then(this.responseParser.parseGetBlockResponse)];
|
|
121
|
+
return [2 /*return*/, this.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseGetBlockResponse)];
|
|
124
122
|
});
|
|
125
123
|
});
|
|
126
124
|
};
|
|
127
|
-
RpcProvider.prototype.
|
|
128
|
-
if (
|
|
125
|
+
RpcProvider.prototype.getBlockWithTxHashes = function (blockIdentifier) {
|
|
126
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
127
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
+
var blockIdentifierGetter;
|
|
129
|
+
return __generator(this, function (_a) {
|
|
130
|
+
blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
|
|
131
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxHashes', [
|
|
132
|
+
blockIdentifierGetter.getIdentifier(),
|
|
133
|
+
])];
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
RpcProvider.prototype.getBlockWithTxs = function (blockIdentifier) {
|
|
138
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
139
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
+
var blockIdentifierGetter;
|
|
141
|
+
return __generator(this, function (_a) {
|
|
142
|
+
blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
|
|
143
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxs', [blockIdentifierGetter.getIdentifier()])];
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
RpcProvider.prototype.getNonce = function (contractAddress) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
return __generator(this, function (_a) {
|
|
150
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getNonce', [contractAddress])];
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
RpcProvider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
155
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
129
156
|
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
-
var parsedKey;
|
|
157
|
+
var parsedKey, blockIdentifierGetter;
|
|
131
158
|
return __generator(this, function (_a) {
|
|
132
159
|
parsedKey = (0, number_1.toHex)((0, number_1.toBN)(key));
|
|
160
|
+
blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
|
|
133
161
|
return [2 /*return*/, this.fetchEndpoint('starknet_getStorageAt', [
|
|
134
162
|
contractAddress,
|
|
135
163
|
parsedKey,
|
|
136
|
-
|
|
164
|
+
blockIdentifierGetter.getIdentifier(),
|
|
137
165
|
])];
|
|
138
166
|
});
|
|
139
167
|
});
|
|
140
168
|
};
|
|
169
|
+
// common interface
|
|
141
170
|
RpcProvider.prototype.getTransaction = function (txHash) {
|
|
142
171
|
return __awaiter(this, void 0, void 0, function () {
|
|
143
172
|
return __generator(this, function (_a) {
|
|
144
|
-
return [2 /*return*/, this.
|
|
173
|
+
return [2 /*return*/, this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse)];
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
RpcProvider.prototype.getTransactionByHash = function (txHash) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
179
|
+
return __generator(this, function (_a) {
|
|
180
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByHash', [txHash])];
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
RpcProvider.prototype.getTransactionByBlockIdAndIndex = function (blockIdentifier, index) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
+
return __generator(this, function (_a) {
|
|
187
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByHash', [blockIdentifier, index])];
|
|
145
188
|
});
|
|
146
189
|
});
|
|
147
190
|
};
|
|
@@ -152,11 +195,15 @@ var RpcProvider = /** @class */ (function () {
|
|
|
152
195
|
});
|
|
153
196
|
});
|
|
154
197
|
};
|
|
155
|
-
RpcProvider.prototype.getClassAt = function (contractAddress,
|
|
156
|
-
if (_blockIdentifier === void 0) { _blockIdentifier = 'pending'; }
|
|
198
|
+
RpcProvider.prototype.getClassAt = function (contractAddress, blockIdentifier) {
|
|
157
199
|
return __awaiter(this, void 0, void 0, function () {
|
|
200
|
+
var blockIdentifierGetter;
|
|
158
201
|
return __generator(this, function (_a) {
|
|
159
|
-
|
|
202
|
+
blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
|
|
203
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getClassAt', [
|
|
204
|
+
blockIdentifierGetter.getIdentifier(),
|
|
205
|
+
contractAddress,
|
|
206
|
+
])];
|
|
160
207
|
});
|
|
161
208
|
});
|
|
162
209
|
};
|
|
@@ -248,16 +295,10 @@ var RpcProvider = /** @class */ (function () {
|
|
|
248
295
|
});
|
|
249
296
|
});
|
|
250
297
|
};
|
|
251
|
-
RpcProvider.prototype.getCode = function (
|
|
298
|
+
RpcProvider.prototype.getCode = function (_contractAddress, _blockIdentifier) {
|
|
252
299
|
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
-
var result;
|
|
254
300
|
return __generator(this, function (_a) {
|
|
255
|
-
|
|
256
|
-
case 0: return [4 /*yield*/, this.fetchEndpoint('starknet_getCode', [contractAddress])];
|
|
257
|
-
case 1:
|
|
258
|
-
result = _a.sent();
|
|
259
|
-
return [2 /*return*/, this.responseParser.parseGetCodeResponse(result)];
|
|
260
|
-
}
|
|
301
|
+
throw new Error('RPC 0.1.0 does not implement getCode function');
|
|
261
302
|
});
|
|
262
303
|
});
|
|
263
304
|
};
|
|
@@ -325,11 +366,12 @@ var RpcProvider = /** @class */ (function () {
|
|
|
325
366
|
*/
|
|
326
367
|
RpcProvider.prototype.getTransactionCount = function (blockIdentifier) {
|
|
327
368
|
return __awaiter(this, void 0, void 0, function () {
|
|
369
|
+
var blockIdentifierGetter;
|
|
328
370
|
return __generator(this, function (_a) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
371
|
+
blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
|
|
372
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockTransactionCount', [
|
|
373
|
+
blockIdentifierGetter.getIdentifier(),
|
|
374
|
+
])];
|
|
333
375
|
});
|
|
334
376
|
});
|
|
335
377
|
};
|
package/provider/sequencer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import {
|
|
2
|
+
import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import { GetContractAddressesResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Sequencer } from '../types/api';
|
|
4
4
|
import { BigNumberish } from '../utils/number';
|
|
5
5
|
import { ProviderInterface } from './interface';
|
|
@@ -29,7 +29,7 @@ export declare class SequencerProvider implements ProviderInterface {
|
|
|
29
29
|
protected fetchEndpoint<T extends keyof Sequencer.Endpoints>(endpoint: T, ...[query, request]: Sequencer.Endpoints[T]['QUERY'] extends never ? Sequencer.Endpoints[T]['REQUEST'] extends never ? [] : [undefined, Sequencer.Endpoints[T]['REQUEST']] : Sequencer.Endpoints[T]['REQUEST'] extends never ? [Sequencer.Endpoints[T]['QUERY']] : [Sequencer.Endpoints[T]['QUERY'], Sequencer.Endpoints[T]['REQUEST']]): Promise<Sequencer.Endpoints[T]['RESPONSE']>;
|
|
30
30
|
callContract({ contractAddress, entrypoint: entryPointSelector, calldata }: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
31
31
|
getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
32
|
-
getStorageAt(contractAddress: string, key: BigNumberish,
|
|
32
|
+
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
33
33
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
34
34
|
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
35
35
|
getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
|
package/provider/sequencer.js
CHANGED
|
@@ -65,6 +65,7 @@ var number_1 = require("../utils/number");
|
|
|
65
65
|
var provider_1 = require("../utils/provider");
|
|
66
66
|
var sequencer_1 = require("../utils/responseParser/sequencer");
|
|
67
67
|
var stark_1 = require("../utils/stark");
|
|
68
|
+
var url_1 = require("../utils/url");
|
|
68
69
|
var errors_1 = require("./errors");
|
|
69
70
|
var utils_1 = require("./utils");
|
|
70
71
|
function isEmptyQueryObject(obj) {
|
|
@@ -79,7 +80,7 @@ function isEmptyQueryObject(obj) {
|
|
|
79
80
|
var SequencerProvider = /** @class */ (function () {
|
|
80
81
|
function SequencerProvider(optionsOrProvider) {
|
|
81
82
|
if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha' }; }
|
|
82
|
-
var _a
|
|
83
|
+
var _a;
|
|
83
84
|
this.responseParser = new sequencer_1.SequencerAPIResponseParser();
|
|
84
85
|
if ('network' in optionsOrProvider) {
|
|
85
86
|
this.baseUrl = SequencerProvider.getNetworkFromName(optionsOrProvider.network);
|
|
@@ -89,11 +90,10 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
89
90
|
}
|
|
90
91
|
else {
|
|
91
92
|
this.baseUrl = optionsOrProvider.baseUrl;
|
|
92
|
-
this.feederGatewayUrl =
|
|
93
|
-
|
|
94
|
-
this.gatewayUrl = (_b = optionsOrProvider.gatewayUrl) !== null && _b !== void 0 ? _b : (0, url_join_1.default)(this.baseUrl, 'gateway');
|
|
93
|
+
this.feederGatewayUrl = (0, url_1.buildUrl)(this.baseUrl, 'feeder_gateway', optionsOrProvider.feederGatewayUrl);
|
|
94
|
+
this.gatewayUrl = (0, url_1.buildUrl)(this.baseUrl, 'gateway', optionsOrProvider.gatewayUrl);
|
|
95
95
|
this.chainId =
|
|
96
|
-
(
|
|
96
|
+
(_a = optionsOrProvider.chainId) !== null && _a !== void 0 ? _a : SequencerProvider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
SequencerProvider.getNetworkFromName = function (name) {
|
|
@@ -249,14 +249,14 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
249
249
|
});
|
|
250
250
|
});
|
|
251
251
|
};
|
|
252
|
-
SequencerProvider.prototype.getStorageAt = function (contractAddress, key,
|
|
253
|
-
if (
|
|
252
|
+
SequencerProvider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
253
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
254
254
|
return __awaiter(this, void 0, void 0, function () {
|
|
255
255
|
var parsedKey;
|
|
256
256
|
return __generator(this, function (_a) {
|
|
257
257
|
parsedKey = (0, number_1.toBN)(key).toString(10);
|
|
258
258
|
return [2 /*return*/, this.fetchEndpoint('get_storage_at', {
|
|
259
|
-
blockIdentifier:
|
|
259
|
+
blockIdentifier: blockIdentifier,
|
|
260
260
|
contractAddress: contractAddress,
|
|
261
261
|
key: parsedKey,
|
|
262
262
|
})];
|
|
@@ -359,7 +359,7 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
359
359
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
360
360
|
return __awaiter(this, void 0, void 0, function () {
|
|
361
361
|
return __generator(this, function (_a) {
|
|
362
|
-
return [2 /*return*/, this.fetchEndpoint('get_code', { contractAddress: contractAddress, blockIdentifier: blockIdentifier })
|
|
362
|
+
return [2 /*return*/, this.fetchEndpoint('get_code', { contractAddress: contractAddress, blockIdentifier: blockIdentifier })];
|
|
363
363
|
});
|
|
364
364
|
});
|
|
365
365
|
};
|
package/provider/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import type { BlockNumber } from '../types';
|
|
2
3
|
import { BigNumberish } from '../utils/number';
|
|
3
4
|
/**
|
|
@@ -23,6 +24,17 @@ declare type BlockIdentifierObject = {
|
|
|
23
24
|
type: 'BLOCK_HASH';
|
|
24
25
|
data: BigNumberish;
|
|
25
26
|
};
|
|
27
|
+
export declare class BlockIdentifierClass {
|
|
28
|
+
blockIdentifier: BlockIdentifier;
|
|
29
|
+
constructor(blockIdentifier: BlockIdentifier);
|
|
30
|
+
getIdentifier(): string | import("bn.js") | {
|
|
31
|
+
block_hash: string;
|
|
32
|
+
block_number?: undefined;
|
|
33
|
+
} | {
|
|
34
|
+
block_number: number;
|
|
35
|
+
block_hash?: undefined;
|
|
36
|
+
} | null;
|
|
37
|
+
}
|
|
26
38
|
/**
|
|
27
39
|
* Identifies the block to be queried.
|
|
28
40
|
*
|
package/provider/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFormattedBlockIdentifier = exports.getBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
|
|
3
|
+
exports.getFormattedBlockIdentifier = exports.getBlockIdentifier = exports.BlockIdentifierClass = exports.txIdentifier = exports.formatHash = void 0;
|
|
4
4
|
var number_1 = require("../utils/number");
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
@@ -29,6 +29,22 @@ function txIdentifier(txHash, txId) {
|
|
|
29
29
|
return "transactionHash=".concat(hashString);
|
|
30
30
|
}
|
|
31
31
|
exports.txIdentifier = txIdentifier;
|
|
32
|
+
var BlockIdentifierClass = /** @class */ (function () {
|
|
33
|
+
function BlockIdentifierClass(blockIdentifier) {
|
|
34
|
+
this.blockIdentifier = blockIdentifier;
|
|
35
|
+
}
|
|
36
|
+
BlockIdentifierClass.prototype.getIdentifier = function () {
|
|
37
|
+
if (typeof this.blockIdentifier === 'string' && (0, number_1.isHex)(this.blockIdentifier)) {
|
|
38
|
+
return { block_hash: this.blockIdentifier };
|
|
39
|
+
}
|
|
40
|
+
if (typeof this.blockIdentifier === 'number') {
|
|
41
|
+
return { block_number: this.blockIdentifier };
|
|
42
|
+
}
|
|
43
|
+
return this.blockIdentifier;
|
|
44
|
+
};
|
|
45
|
+
return BlockIdentifierClass;
|
|
46
|
+
}());
|
|
47
|
+
exports.BlockIdentifierClass = BlockIdentifierClass;
|
|
32
48
|
/**
|
|
33
49
|
* Identifies the block to be queried.
|
|
34
50
|
*
|
package/src/index.ts
CHANGED
package/src/provider/default.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
2
|
import {
|
|
3
|
-
BlockTag,
|
|
4
3
|
Call,
|
|
5
4
|
CallContractResponse,
|
|
6
5
|
ContractClass,
|
|
@@ -69,9 +68,9 @@ export class Provider implements ProviderInterface {
|
|
|
69
68
|
public async getStorageAt(
|
|
70
69
|
contractAddress: string,
|
|
71
70
|
key: BigNumberish,
|
|
72
|
-
|
|
71
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
73
72
|
): Promise<BigNumberish> {
|
|
74
|
-
return this.provider.getStorageAt(contractAddress, key,
|
|
73
|
+
return this.provider.getStorageAt(contractAddress, key, blockIdentifier);
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
public async getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse> {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
2
|
import type {
|
|
3
|
-
BlockTag,
|
|
4
3
|
Call,
|
|
5
4
|
CallContractResponse,
|
|
6
5
|
ContractClass,
|
|
@@ -43,6 +42,9 @@ export abstract class ProviderInterface {
|
|
|
43
42
|
*/
|
|
44
43
|
public abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
|
|
45
44
|
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated The method should not be used
|
|
47
|
+
*/
|
|
46
48
|
public abstract getCode(
|
|
47
49
|
contractAddress: string,
|
|
48
50
|
blockIdentifier?: BlockIdentifier
|
|
@@ -65,13 +67,13 @@ export abstract class ProviderInterface {
|
|
|
65
67
|
*
|
|
66
68
|
* @param contractAddress
|
|
67
69
|
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
68
|
-
* @param
|
|
70
|
+
* @param blockIdentifier - block identifier
|
|
69
71
|
* @returns the value of the storage variable
|
|
70
72
|
*/
|
|
71
73
|
public abstract getStorageAt(
|
|
72
74
|
contractAddress: string,
|
|
73
75
|
key: BigNumberish,
|
|
74
|
-
|
|
76
|
+
blockIdentifier: BlockIdentifier
|
|
75
77
|
): Promise<BigNumberish>;
|
|
76
78
|
|
|
77
79
|
/**
|
package/src/provider/rpc.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
2
|
import {
|
|
3
|
-
BlockTag,
|
|
4
3
|
Call,
|
|
5
4
|
CallContractResponse,
|
|
6
5
|
DeclareContractPayload,
|
|
@@ -9,6 +8,7 @@ import {
|
|
|
9
8
|
DeployContractResponse,
|
|
10
9
|
EstimateFeeResponse,
|
|
11
10
|
GetBlockResponse,
|
|
11
|
+
GetCodeResponse,
|
|
12
12
|
GetTransactionReceiptResponse,
|
|
13
13
|
GetTransactionResponse,
|
|
14
14
|
Invocation,
|
|
@@ -19,18 +19,12 @@ import { RPC } from '../types/api';
|
|
|
19
19
|
import fetch from '../utils/fetchPonyfill';
|
|
20
20
|
import { getSelectorFromName } from '../utils/hash';
|
|
21
21
|
import { stringify } from '../utils/json';
|
|
22
|
-
import {
|
|
23
|
-
BigNumberish,
|
|
24
|
-
bigNumberishArrayToDecimalStringArray,
|
|
25
|
-
isHex,
|
|
26
|
-
toBN,
|
|
27
|
-
toHex,
|
|
28
|
-
} from '../utils/number';
|
|
22
|
+
import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number';
|
|
29
23
|
import { parseCalldata, parseContract, wait } from '../utils/provider';
|
|
30
24
|
import { RPCResponseParser } from '../utils/responseParser/rpc';
|
|
31
25
|
import { randomAddress } from '../utils/stark';
|
|
32
26
|
import { ProviderInterface } from './interface';
|
|
33
|
-
import { BlockIdentifier } from './utils';
|
|
27
|
+
import { BlockIdentifier, BlockIdentifierClass } from './utils';
|
|
34
28
|
|
|
35
29
|
export type RpcProviderOptions = { nodeUrl: string };
|
|
36
30
|
|
|
@@ -89,34 +83,63 @@ export class RpcProvider implements ProviderInterface {
|
|
|
89
83
|
return this.fetchEndpoint('starknet_chainId');
|
|
90
84
|
}
|
|
91
85
|
|
|
86
|
+
// Common Interface
|
|
92
87
|
public async getBlock(blockIdentifier: BlockIdentifier = 'pending'): Promise<GetBlockResponse> {
|
|
93
|
-
|
|
94
|
-
typeof blockIdentifier === 'string' && isHex(blockIdentifier)
|
|
95
|
-
? 'starknet_getBlockByHash'
|
|
96
|
-
: 'starknet_getBlockByNumber';
|
|
97
|
-
|
|
98
|
-
return this.fetchEndpoint(method, [blockIdentifier]).then(
|
|
88
|
+
return this.getBlockWithTxHashes(blockIdentifier).then(
|
|
99
89
|
this.responseParser.parseGetBlockResponse
|
|
100
90
|
);
|
|
101
91
|
}
|
|
102
92
|
|
|
93
|
+
public async getBlockWithTxHashes(
|
|
94
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
95
|
+
): Promise<RPC.GetBlockWithTxHashesResponse> {
|
|
96
|
+
const blockIdentifierGetter = new BlockIdentifierClass(blockIdentifier);
|
|
97
|
+
return this.fetchEndpoint('starknet_getBlockWithTxHashes', [
|
|
98
|
+
blockIdentifierGetter.getIdentifier(),
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public async getBlockWithTxs(
|
|
103
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
104
|
+
): Promise<RPC.GetBlockWithTxs> {
|
|
105
|
+
const blockIdentifierGetter = new BlockIdentifierClass(blockIdentifier);
|
|
106
|
+
return this.fetchEndpoint('starknet_getBlockWithTxs', [blockIdentifierGetter.getIdentifier()]);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public async getNonce(contractAddress: string): Promise<any> {
|
|
110
|
+
return this.fetchEndpoint('starknet_getNonce', [contractAddress]);
|
|
111
|
+
}
|
|
112
|
+
|
|
103
113
|
public async getStorageAt(
|
|
104
114
|
contractAddress: string,
|
|
105
115
|
key: BigNumberish,
|
|
106
|
-
|
|
116
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
107
117
|
): Promise<BigNumberish> {
|
|
108
118
|
const parsedKey = toHex(toBN(key));
|
|
119
|
+
const blockIdentifierGetter = new BlockIdentifierClass(blockIdentifier);
|
|
109
120
|
return this.fetchEndpoint('starknet_getStorageAt', [
|
|
110
121
|
contractAddress,
|
|
111
122
|
parsedKey,
|
|
112
|
-
|
|
123
|
+
blockIdentifierGetter.getIdentifier(),
|
|
113
124
|
]);
|
|
114
125
|
}
|
|
115
126
|
|
|
127
|
+
// common interface
|
|
116
128
|
public async getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse> {
|
|
117
|
-
return this.
|
|
118
|
-
|
|
119
|
-
|
|
129
|
+
return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public async getTransactionByHash(
|
|
133
|
+
txHash: BigNumberish
|
|
134
|
+
): Promise<RPC.GetTransactionByHashResponse> {
|
|
135
|
+
return this.fetchEndpoint('starknet_getTransactionByHash', [txHash]);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public async getTransactionByBlockIdAndIndex(
|
|
139
|
+
blockIdentifier: BlockIdentifier,
|
|
140
|
+
index: number
|
|
141
|
+
): Promise<RPC.GetTransactionByBlockIdAndIndex> {
|
|
142
|
+
return this.fetchEndpoint('starknet_getTransactionByHash', [blockIdentifier, index]);
|
|
120
143
|
}
|
|
121
144
|
|
|
122
145
|
public async getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse> {
|
|
@@ -125,11 +148,12 @@ export class RpcProvider implements ProviderInterface {
|
|
|
125
148
|
);
|
|
126
149
|
}
|
|
127
150
|
|
|
128
|
-
public async getClassAt(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
151
|
+
public async getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<any> {
|
|
152
|
+
const blockIdentifierGetter = new BlockIdentifierClass(blockIdentifier);
|
|
153
|
+
return this.fetchEndpoint('starknet_getClassAt', [
|
|
154
|
+
blockIdentifierGetter.getIdentifier(),
|
|
155
|
+
contractAddress,
|
|
156
|
+
]);
|
|
133
157
|
}
|
|
134
158
|
|
|
135
159
|
public async getEstimateFee(
|
|
@@ -214,12 +238,10 @@ export class RpcProvider implements ProviderInterface {
|
|
|
214
238
|
}
|
|
215
239
|
|
|
216
240
|
public async getCode(
|
|
217
|
-
|
|
241
|
+
_contractAddress: string,
|
|
218
242
|
_blockIdentifier?: BlockIdentifier
|
|
219
|
-
): Promise<
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return this.responseParser.parseGetCodeResponse(result);
|
|
243
|
+
): Promise<GetCodeResponse> {
|
|
244
|
+
throw new Error('RPC 0.1.0 does not implement getCode function');
|
|
223
245
|
}
|
|
224
246
|
|
|
225
247
|
public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
|
|
@@ -270,10 +292,10 @@ export class RpcProvider implements ProviderInterface {
|
|
|
270
292
|
public async getTransactionCount(
|
|
271
293
|
blockIdentifier: BlockIdentifier
|
|
272
294
|
): Promise<RPC.GetTransactionCountResponse> {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
295
|
+
const blockIdentifierGetter = new BlockIdentifierClass(blockIdentifier);
|
|
296
|
+
return this.fetchEndpoint('starknet_getBlockTransactionCount', [
|
|
297
|
+
blockIdentifierGetter.getIdentifier(),
|
|
298
|
+
]);
|
|
277
299
|
}
|
|
278
300
|
|
|
279
301
|
/**
|