starknet 3.18.2 → 4.0.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 +70 -0
- package/README.md +1 -2
- package/__tests__/account.test.ts +11 -56
- package/__tests__/contract.test.ts +11 -49
- package/__tests__/defaultProvider.test.ts +321 -0
- package/__tests__/fixtures.ts +32 -11
- package/__tests__/jest.setup.ts +2 -3
- package/__tests__/rpcProvider.test.ts +17 -0
- package/__tests__/sequencerProvider.test.ts +45 -0
- package/account/default.d.ts +54 -77
- package/account/default.js +271 -596
- package/account/index.js +18 -31
- package/account/interface.d.ts +66 -95
- package/account/interface.js +20 -30
- package/constants.d.ts +17 -19
- package/constants.js +2038 -2059
- package/contract/contractFactory.d.ts +25 -29
- package/contract/contractFactory.js +94 -210
- package/contract/default.d.ts +117 -146
- package/contract/default.js +582 -776
- package/contract/index.js +19 -32
- package/contract/interface.d.ts +72 -92
- package/contract/interface.js +6 -5
- package/dist/account/default.d.ts +5 -9
- package/dist/account/default.js +35 -169
- package/dist/account/interface.d.ts +3 -15
- package/dist/contract/contractFactory.js +4 -4
- package/dist/contract/default.d.ts +3 -3
- package/dist/contract/default.js +3 -2
- package/dist/contract/interface.d.ts +2 -2
- package/dist/provider/default.d.ts +18 -134
- package/dist/provider/default.js +47 -411
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +2 -0
- package/dist/provider/interface.d.ts +45 -50
- package/dist/provider/rpc.d.ts +57 -0
- package/dist/provider/rpc.js +364 -0
- package/dist/provider/sequencer.d.ts +66 -0
- package/dist/provider/sequencer.js +444 -0
- package/dist/types/account.d.ts +2 -3
- package/dist/types/api/index.d.ts +16 -0
- package/dist/types/api/index.js +18 -0
- package/dist/types/api/rpc.d.ts +221 -0
- package/dist/types/{api.js → api/rpc.js} +0 -0
- package/dist/types/api/sequencer.d.ts +289 -0
- package/dist/types/api/sequencer.js +2 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.js +15 -1
- package/dist/types/lib.d.ts +3 -1
- package/dist/types/provider.d.ts +86 -0
- package/dist/types/provider.js +2 -0
- package/dist/utils/fetchPonyfill.d.ts +2 -0
- package/dist/utils/fetchPonyfill.js +6 -0
- package/dist/utils/provider.d.ts +4 -0
- package/dist/utils/provider.js +38 -0
- package/dist/utils/responseParser/index.d.ts +11 -0
- package/dist/utils/responseParser/index.js +9 -0
- package/dist/utils/responseParser/rpc.d.ts +13 -0
- package/dist/utils/responseParser/rpc.js +96 -0
- package/dist/utils/responseParser/sequencer.d.ts +13 -0
- package/dist/utils/responseParser/sequencer.js +124 -0
- package/index.js +42 -75
- package/package.json +2 -3
- package/provider/default.d.ts +21 -175
- package/provider/default.js +139 -704
- package/provider/errors.d.ts +4 -4
- package/provider/errors.js +30 -40
- package/provider/index.d.ts +2 -0
- package/provider/index.js +22 -33
- package/provider/interface.d.ts +104 -131
- package/provider/interface.js +6 -5
- package/provider/rpc.d.ts +57 -0
- package/provider/rpc.js +364 -0
- package/provider/sequencer.d.ts +66 -0
- package/provider/sequencer.js +444 -0
- package/provider/utils.d.ts +7 -9
- package/provider/utils.js +39 -44
- package/signer/default.d.ts +5 -9
- package/signer/default.js +72 -177
- package/signer/index.js +18 -31
- package/signer/interface.d.ts +29 -33
- package/signer/interface.js +6 -5
- package/src/account/default.ts +26 -146
- package/src/account/interface.ts +5 -20
- package/src/contract/contractFactory.ts +3 -6
- package/src/contract/default.ts +6 -4
- package/src/contract/interface.ts +2 -2
- package/src/provider/default.ts +63 -395
- package/src/provider/index.ts +2 -0
- package/src/provider/interface.ts +68 -63
- package/src/provider/rpc.ts +299 -0
- package/src/provider/sequencer.ts +385 -0
- package/src/types/account.ts +2 -3
- package/src/types/api/index.ts +17 -0
- package/src/types/api/rpc.ts +247 -0
- package/src/types/api/sequencer.ts +331 -0
- package/src/types/index.ts +3 -1
- package/src/types/lib.ts +3 -1
- package/src/types/provider.ts +108 -0
- package/src/utils/fetchPonyfill.ts +4 -0
- package/src/utils/provider.ts +28 -0
- package/src/utils/responseParser/index.ts +28 -0
- package/src/utils/responseParser/rpc.ts +93 -0
- package/src/utils/responseParser/sequencer.ts +127 -0
- package/types/account.d.ts +5 -7
- package/types/account.js +2 -2
- package/types/api/index.d.ts +16 -0
- package/types/api/index.js +18 -0
- package/types/api/rpc.d.ts +221 -0
- package/types/api/rpc.js +2 -0
- package/types/api/sequencer.d.ts +289 -0
- package/types/api/sequencer.js +2 -0
- package/types/contract.d.ts +1 -1
- package/types/contract.js +2 -2
- package/types/index.d.ts +3 -1
- package/types/index.js +35 -34
- package/types/lib.d.ts +36 -41
- package/types/lib.js +2 -2
- package/types/provider.d.ts +86 -0
- package/types/provider.js +2 -0
- package/types/signer.d.ts +2 -2
- package/types/signer.js +2 -2
- package/utils/address.js +26 -37
- package/utils/ellipticCurve.d.ts +1 -6
- package/utils/ellipticCurve.js +73 -137
- package/utils/encode.js +49 -85
- package/utils/fetchPonyfill.d.ts +2 -0
- package/utils/fetchPonyfill.js +6 -0
- package/utils/hash.d.ts +4 -31
- package/utils/hash.js +76 -141
- package/utils/json.d.ts +13 -45
- package/utils/json.js +15 -22
- package/utils/number.d.ts +2 -9
- package/utils/number.js +47 -81
- package/utils/provider.d.ts +4 -0
- package/utils/provider.js +38 -0
- package/utils/responseParser/index.d.ts +11 -0
- package/utils/responseParser/index.js +9 -0
- package/utils/responseParser/rpc.d.ts +13 -0
- package/utils/responseParser/rpc.js +96 -0
- package/utils/responseParser/sequencer.d.ts +13 -0
- package/utils/responseParser/sequencer.js +124 -0
- package/utils/shortString.js +13 -21
- package/utils/stark.d.ts +0 -1
- package/utils/stark.js +59 -93
- package/utils/transaction.d.ts +3 -6
- package/utils/transaction.js +50 -81
- package/utils/typedData/index.d.ts +3 -15
- package/utils/typedData/index.js +109 -175
- package/utils/typedData/types.d.ts +9 -9
- package/utils/typedData/types.js +2 -2
- package/utils/typedData/utils.js +6 -6
- package/utils/uint256.d.ts +5 -5
- package/utils/uint256.js +16 -26
- package/www/docs/API/account.md +3 -4
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/contractFactory.md +2 -2
- package/www/docs/API/provider.md +185 -74
- package/www/guides/account.md +1 -8
- package/www/guides/erc20.md +3 -0
- package/__tests__/provider.test.ts +0 -168
- package/dist/types/api.d.ts +0 -261
- package/src/types/api.ts +0 -303
- package/types/api.d.ts +0 -287
- package/types/api.js +0 -2
package/www/docs/API/provider.md
CHANGED
|
@@ -14,17 +14,18 @@ Typically, these are _read_ calls on the blockchain.
|
|
|
14
14
|
|
|
15
15
|
The options for the provider depends from the network. The structure of the options object is:
|
|
16
16
|
|
|
17
|
-
- options.**
|
|
18
|
-
- options.**
|
|
19
|
-
- options.**gatewayUrl** - Gateway Endpoint
|
|
17
|
+
- options.**sequencer** - Options for sequencer provider
|
|
18
|
+
- options.**rpc** - Options for RPC provider
|
|
20
19
|
|
|
21
20
|
Example:
|
|
22
21
|
|
|
23
22
|
```
|
|
24
23
|
const provider = new starknet.Provider({
|
|
24
|
+
sequencer: {
|
|
25
25
|
baseUrl: 'https://alpha4.starknet.io',
|
|
26
26
|
feederGatewayUrl: 'feeder_gateway',
|
|
27
27
|
gatewayUrl: 'gateway',
|
|
28
|
+
}
|
|
28
29
|
})
|
|
29
30
|
```
|
|
30
31
|
|
|
@@ -32,20 +33,9 @@ const provider = new starknet.Provider({
|
|
|
32
33
|
|
|
33
34
|
## Methods
|
|
34
35
|
|
|
35
|
-
Gets the smart contract address on the network
|
|
36
|
-
|
|
37
|
-
provider.**getContractAddresses**() => _Promise < GetContractAddressesResponse >_
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
{
|
|
41
|
-
Starknet: string;
|
|
42
|
-
GpsStatementVerifier: string;
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
36
|
<hr/>
|
|
47
37
|
|
|
48
|
-
provider.**callContract**(call [ ,
|
|
38
|
+
provider.**callContract**(call [ , blockIdentifier ]) => _Promise < CallContractResponse >_
|
|
49
39
|
|
|
50
40
|
Calls a function on the StarkNet contract.
|
|
51
41
|
|
|
@@ -55,10 +45,6 @@ The call object structure:
|
|
|
55
45
|
- call.**entrypoint** - Entrypoint of the call (method name)
|
|
56
46
|
- call.**calldata** - Payload for the invoking the method
|
|
57
47
|
|
|
58
|
-
The options object structure:
|
|
59
|
-
|
|
60
|
-
- options.**blockIdentifier**
|
|
61
|
-
|
|
62
48
|
###### CallContractResponse
|
|
63
49
|
|
|
64
50
|
```
|
|
@@ -69,7 +55,7 @@ The options object structure:
|
|
|
69
55
|
|
|
70
56
|
<hr/>
|
|
71
57
|
|
|
72
|
-
provider.**getBlock**(
|
|
58
|
+
provider.**getBlock**(blockIdentifier) => _Promise < GetBlockResponse >_
|
|
73
59
|
|
|
74
60
|
Gets the block information.
|
|
75
61
|
|
|
@@ -77,95 +63,178 @@ Gets the block information.
|
|
|
77
63
|
|
|
78
64
|
```
|
|
79
65
|
{
|
|
66
|
+
accepted_time: number;
|
|
80
67
|
block_hash: string;
|
|
81
|
-
parent_block_hash: string;
|
|
82
68
|
block_number: number;
|
|
83
|
-
|
|
69
|
+
gas_price: string;
|
|
70
|
+
new_root: string;
|
|
71
|
+
old_root?: string;
|
|
72
|
+
parent_hash: string;
|
|
73
|
+
sequencer: string;
|
|
84
74
|
status: 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
transaction_receipts: [];
|
|
88
|
-
starknet_version: string;
|
|
75
|
+
transactions: Array<string>;
|
|
76
|
+
starknet_version?: string;
|
|
89
77
|
}
|
|
90
78
|
```
|
|
91
79
|
|
|
92
80
|
<hr/>
|
|
93
81
|
|
|
94
|
-
provider.**
|
|
82
|
+
provider.**getClassAt**(contractAddress, blockIdentifier) => _Promise < ContractClass >_
|
|
95
83
|
|
|
96
|
-
Gets the
|
|
84
|
+
Gets the contract class of the deployed contract.
|
|
97
85
|
|
|
98
|
-
######
|
|
86
|
+
###### _ContractClass_
|
|
99
87
|
|
|
100
88
|
```
|
|
101
89
|
{
|
|
102
|
-
|
|
103
|
-
|
|
90
|
+
program: CompressedProgram;
|
|
91
|
+
entry_points_by_type: EntryPointsByType;
|
|
92
|
+
abi?: Abi;
|
|
104
93
|
}
|
|
105
94
|
```
|
|
106
95
|
|
|
107
96
|
<hr/>
|
|
108
97
|
|
|
109
|
-
provider.**getStorageAt**(contractAddress, key,
|
|
98
|
+
provider.**getStorageAt**(contractAddress, key, blockHashOrTag) => _Promise < string >_
|
|
110
99
|
|
|
111
100
|
Gets the contract's storage variable at a specific key
|
|
112
101
|
|
|
113
102
|
<hr/>
|
|
114
103
|
|
|
115
|
-
provider.**
|
|
104
|
+
provider.**getTransactionReceipt**(txHash) => _Promise < GetTransactionReceiptResponse >_
|
|
116
105
|
|
|
117
106
|
Gets the status of a transaction.
|
|
118
107
|
|
|
119
|
-
######
|
|
108
|
+
###### _GetTransactionReceiptResponse_
|
|
120
109
|
|
|
121
110
|
```
|
|
122
111
|
{
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
112
|
+
transaction_hash: string;
|
|
113
|
+
status: 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
114
|
+
actual_fee?: string;
|
|
115
|
+
status_data?: string;
|
|
116
|
+
messages_sent?: Array<MessageToL1>;
|
|
117
|
+
events?: Array<Event>;
|
|
118
|
+
l1_origin_message?: MessageToL2;
|
|
130
119
|
}
|
|
131
120
|
```
|
|
132
121
|
|
|
133
122
|
<hr/>
|
|
134
123
|
|
|
135
|
-
provider.**
|
|
124
|
+
provider.**getTransaction**(txHash) => _Promise < GetTransactionResponse >_
|
|
136
125
|
|
|
137
|
-
Gets the
|
|
126
|
+
Gets the transaction information from a tx hash.
|
|
138
127
|
|
|
139
|
-
######
|
|
128
|
+
###### _GetTransactionResponse_
|
|
140
129
|
|
|
141
130
|
```
|
|
142
131
|
{
|
|
143
|
-
status: 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
144
132
|
transaction_hash: string;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
133
|
+
version?: string;
|
|
134
|
+
signature?: Signature;
|
|
135
|
+
max_fee?: string;
|
|
136
|
+
nonce?: string;
|
|
137
|
+
contract_address?: string;
|
|
138
|
+
entry_point_selector?: string;
|
|
139
|
+
calldata?: RawCalldata;
|
|
140
|
+
contract_class?: ContractClass;
|
|
141
|
+
sender_address?: string;
|
|
150
142
|
}
|
|
151
143
|
```
|
|
152
144
|
|
|
153
145
|
<hr/>
|
|
154
146
|
|
|
155
|
-
provider.**
|
|
147
|
+
provider.**declareContract**(payload) => _Promise < DeclareContractResponse >_
|
|
156
148
|
|
|
157
|
-
|
|
149
|
+
Declares a contract on Starknet
|
|
158
150
|
|
|
159
|
-
######
|
|
151
|
+
###### _DeclareContractResponse_
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
{
|
|
155
|
+
transaction_hash: string;
|
|
156
|
+
class_hash: string;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
<hr/>
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
provider.**deployContract**(payload [ , abi ]) => _Promise < DeployContractResponse >_
|
|
164
|
+
|
|
165
|
+
Deploys a contract on Starknet
|
|
166
|
+
|
|
167
|
+
###### _DeployContractResponse_
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
{
|
|
171
|
+
transaction_hash: string;
|
|
172
|
+
contract_address?: string;
|
|
173
|
+
};
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
<hr/>
|
|
177
|
+
|
|
178
|
+
provider.**waitForTransaction**(txHash [ , retryInterval]) => _Promise < void >_
|
|
179
|
+
|
|
180
|
+
Wait for the transaction to be accepted on L2 or L1.
|
|
181
|
+
|
|
182
|
+
# SequencerProvider
|
|
183
|
+
|
|
184
|
+
## Creating an instance
|
|
185
|
+
|
|
186
|
+
`new starknet.SequencerProvider(optionsOrProvider)`
|
|
187
|
+
|
|
188
|
+
The options for the provider depends from the network. The structure of the options object is:
|
|
189
|
+
|
|
190
|
+
- options.**baseUrl** - Base URL of the network
|
|
191
|
+
- options.**feederGatewayUrl** - Feeder Gateway Endpoint of the network
|
|
192
|
+
- options.**gatewayUrl** - Gateway Endpoint
|
|
193
|
+
|
|
194
|
+
or
|
|
195
|
+
|
|
196
|
+
- options.**network** - One of 'mainnet-alpha' or 'goerli-alpha'
|
|
197
|
+
|
|
198
|
+
Example:
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
const provider = new starknet.Provider({
|
|
202
|
+
baseUrl: 'https://alpha4.starknet.io',
|
|
203
|
+
feederGatewayUrl: 'feeder_gateway',
|
|
204
|
+
gatewayUrl: 'gateway',
|
|
205
|
+
})
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Methods
|
|
209
|
+
|
|
210
|
+
Gets the smart contract address on the network
|
|
211
|
+
|
|
212
|
+
provider.**getContractAddresses**() => _Promise < GetContractAddressesResponse >_
|
|
160
213
|
|
|
161
214
|
```
|
|
162
215
|
{
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
216
|
+
Starknet: string;
|
|
217
|
+
GpsStatementVerifier: string;
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
<hr/>
|
|
222
|
+
|
|
223
|
+
provider.**getTransactionStatus**(txHash) => _Promise < GetTransactionStatusResponse >_
|
|
224
|
+
|
|
225
|
+
Gets the status of a transaction.
|
|
226
|
+
|
|
227
|
+
###### _GetTransactionStatusResponse_
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
{
|
|
231
|
+
tx_status: 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
232
|
+
block_hash: string;
|
|
233
|
+
tx_failure_reason?: {
|
|
234
|
+
tx_id: number;
|
|
235
|
+
code: string;
|
|
236
|
+
error_message: string;
|
|
237
|
+
}
|
|
169
238
|
}
|
|
170
239
|
```
|
|
171
240
|
|
|
@@ -197,35 +266,77 @@ Gets the transaction trace from a tx hash.
|
|
|
197
266
|
}
|
|
198
267
|
```
|
|
199
268
|
|
|
269
|
+
# RpcProvider
|
|
270
|
+
|
|
271
|
+
## Creating an instance
|
|
272
|
+
|
|
273
|
+
`new starknet.RpcProvider(options)`
|
|
274
|
+
|
|
275
|
+
- options.**nodeUrl** - Starknet RPC node url
|
|
276
|
+
|
|
277
|
+
Example:
|
|
278
|
+
|
|
279
|
+
```
|
|
280
|
+
const provider = new starknet.RpcProvider({
|
|
281
|
+
nodeUrl: 'URL_TO_STARKNET_RPC_NODE',
|
|
282
|
+
})
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Methods
|
|
286
|
+
|
|
287
|
+
provider.**getTransactionCount**(blockIdentifier) => _Promise < number >_
|
|
288
|
+
|
|
289
|
+
Gets the transaction count from a block.
|
|
290
|
+
|
|
200
291
|
<hr/>
|
|
201
292
|
|
|
202
|
-
provider.**
|
|
293
|
+
provider.**getBlockNumber**() => _Promise < number >_
|
|
203
294
|
|
|
204
|
-
|
|
295
|
+
Gets the latest block number
|
|
205
296
|
|
|
206
|
-
|
|
297
|
+
<hr/>
|
|
298
|
+
|
|
299
|
+
provider.**getSyncingStats**() => _Promise < GetSyncingStatsResponse >_
|
|
300
|
+
|
|
301
|
+
Gets syncing status of the node
|
|
302
|
+
|
|
303
|
+
###### GetSyncingStatsResponse
|
|
207
304
|
|
|
208
305
|
```
|
|
306
|
+
boolean |
|
|
209
307
|
{
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
308
|
+
starting_block_hash: string;
|
|
309
|
+
starting_block_num: string;
|
|
310
|
+
current_block_hash: string;
|
|
311
|
+
current_block_num: string;
|
|
312
|
+
highest_block_hash: string;
|
|
313
|
+
highest_block_num: string;
|
|
314
|
+
}
|
|
315
|
+
```
|
|
214
316
|
|
|
215
317
|
<hr/>
|
|
216
318
|
|
|
217
|
-
|
|
319
|
+
provider.**getEvents**(eventFilter) => _Promise < GetEventsResponse >_
|
|
218
320
|
|
|
219
|
-
|
|
321
|
+
##### EventFilter
|
|
220
322
|
|
|
221
|
-
|
|
323
|
+
```
|
|
324
|
+
type EventFilter = {
|
|
325
|
+
fromBlock: string;
|
|
326
|
+
toBlock: string;
|
|
327
|
+
address: string;
|
|
328
|
+
keys: string[];
|
|
329
|
+
page_size: number;
|
|
330
|
+
page_number: number;
|
|
331
|
+
};
|
|
332
|
+
```
|
|
222
333
|
|
|
223
|
-
######
|
|
334
|
+
###### GetSyncingStatsResponse
|
|
224
335
|
|
|
225
336
|
```
|
|
226
337
|
{
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
338
|
+
events: StarknetEmittedEvent[];
|
|
339
|
+
page_number: number;
|
|
340
|
+
is_last_page: number;
|
|
341
|
+
}
|
|
231
342
|
```
|
package/www/guides/account.md
CHANGED
|
@@ -54,16 +54,9 @@ Wait for the deployment transaction to be accepted and assign the address of the
|
|
|
54
54
|
|
|
55
55
|
```javascript
|
|
56
56
|
await defaultProvider.waitForTransaction(accountResponse.transaction_hash);
|
|
57
|
-
const accountContract = new Contract(
|
|
58
|
-
compiledAccount.abi,
|
|
59
|
-
accountResponse.address
|
|
60
|
-
);
|
|
61
|
-
const initializeResponse = await accountContract.initialize(starkKeyPub, "0");
|
|
62
|
-
|
|
63
|
-
await defaultProvider.waitForTransaction(initializeResponse.transaction_hash);
|
|
64
57
|
```
|
|
65
58
|
|
|
66
|
-
Once account contract is
|
|
59
|
+
Once account contract is deployed [Account](../docs/API/account.md) instance can be created. Use your new account instance to sign transactions, messages or verify signatures! Make sure your Account has enough funds to execute invocations.
|
|
67
60
|
|
|
68
61
|
```js
|
|
69
62
|
const account = new Account(
|
package/www/guides/erc20.md
CHANGED
|
@@ -29,10 +29,13 @@ const erc20 = new Contract(compiledErc20.abi, erc20Address);
|
|
|
29
29
|
Make sure you created the `Account` instance following the [Creating an Account](./account.md) guide.
|
|
30
30
|
|
|
31
31
|
```javascript
|
|
32
|
+
erc20.connect(account);
|
|
33
|
+
|
|
32
34
|
const { transaction_hash: mintTxHash } = await erc20.mint(
|
|
33
35
|
account.address,
|
|
34
36
|
"1000"
|
|
35
37
|
);
|
|
38
|
+
|
|
36
39
|
console.log(`Waiting for Tx to be Accepted on Starknet - Minting...`);
|
|
37
40
|
await defaultProvider.waitForTransaction(mintTxHash);
|
|
38
41
|
```
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { BlockNumber, stark } from '../src';
|
|
2
|
-
import { toBN } from '../src/utils/number';
|
|
3
|
-
import {
|
|
4
|
-
IS_DEVNET,
|
|
5
|
-
compiledErc20,
|
|
6
|
-
compiledOpenZeppelinAccount,
|
|
7
|
-
getTestProvider,
|
|
8
|
-
testIfNotDevnet,
|
|
9
|
-
} from './fixtures';
|
|
10
|
-
|
|
11
|
-
const { compileCalldata } = stark;
|
|
12
|
-
|
|
13
|
-
const provider = getTestProvider();
|
|
14
|
-
|
|
15
|
-
describe('defaultProvider', () => {
|
|
16
|
-
let exampleTransactionHash: string;
|
|
17
|
-
let exampleContractAddress: string;
|
|
18
|
-
let exampleBlockHash: string;
|
|
19
|
-
let exampleBlockNumber: BlockNumber;
|
|
20
|
-
beforeAll(async () => {
|
|
21
|
-
const { code, transaction_hash, address } = await provider.deployContract({
|
|
22
|
-
contract: compiledErc20,
|
|
23
|
-
});
|
|
24
|
-
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
25
|
-
await provider.waitForTransaction(transaction_hash);
|
|
26
|
-
exampleTransactionHash = transaction_hash;
|
|
27
|
-
exampleContractAddress = address!;
|
|
28
|
-
const transaction = await provider.getTransaction(transaction_hash);
|
|
29
|
-
|
|
30
|
-
if (transaction.status !== 'REJECTED') {
|
|
31
|
-
exampleBlockHash = transaction.block_hash;
|
|
32
|
-
exampleBlockNumber = transaction.block_number;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('feeder gateway endpoints', () => {
|
|
37
|
-
testIfNotDevnet('getContractAddresses()', async () => {
|
|
38
|
-
// not supported in starknet-devnet
|
|
39
|
-
const { GpsStatementVerifier, Starknet } = await provider.getContractAddresses();
|
|
40
|
-
expect(typeof GpsStatementVerifier).toBe('string');
|
|
41
|
-
expect(typeof Starknet).toBe('string');
|
|
42
|
-
});
|
|
43
|
-
test(`getBlock(blockHash=${exampleBlockHash}, blockNumber=undefined)`, () => {
|
|
44
|
-
return expect(provider.getBlock(exampleBlockHash)).resolves.not.toThrow();
|
|
45
|
-
});
|
|
46
|
-
test(`getBlock(blockHash=undefined, blockNumber=${exampleBlockNumber})`, () => {
|
|
47
|
-
return expect(provider.getBlock(exampleBlockNumber)).resolves.not.toThrow();
|
|
48
|
-
});
|
|
49
|
-
test('getBlock(blockHash=undefined, blockNumber=null)', async () => {
|
|
50
|
-
const block = await provider.getBlock();
|
|
51
|
-
|
|
52
|
-
expect(block).not.toBeNull();
|
|
53
|
-
|
|
54
|
-
const { block_number, timestamp } = block;
|
|
55
|
-
|
|
56
|
-
expect(typeof block_number).toEqual('number');
|
|
57
|
-
|
|
58
|
-
return expect(typeof timestamp).toEqual('number');
|
|
59
|
-
});
|
|
60
|
-
test('getBlock() -> { blockNumber }', async () => {
|
|
61
|
-
const block = await provider.getBlock();
|
|
62
|
-
return expect(block).toHaveProperty('block_number');
|
|
63
|
-
});
|
|
64
|
-
test('getCode()', () => {
|
|
65
|
-
return expect(provider.getCode(exampleContractAddress, 36663)).resolves.not.toThrow();
|
|
66
|
-
});
|
|
67
|
-
test('getCode(blockHash=undefined, blockNumber=null)', () => {
|
|
68
|
-
return expect(provider.getCode(exampleContractAddress)).resolves.not.toThrow();
|
|
69
|
-
});
|
|
70
|
-
test('getStorageAt() with "key" type of number', () => {
|
|
71
|
-
return expect(provider.getStorageAt(exampleContractAddress, 0, 36663)).resolves.not.toThrow();
|
|
72
|
-
});
|
|
73
|
-
test('getStorageAt() with "key" type of string', () => {
|
|
74
|
-
return expect(
|
|
75
|
-
provider.getStorageAt(exampleContractAddress, '0', 36663)
|
|
76
|
-
).resolves.not.toThrow();
|
|
77
|
-
});
|
|
78
|
-
test('getStorageAt() with "key" type of BN', () => {
|
|
79
|
-
return expect(
|
|
80
|
-
provider.getStorageAt(exampleContractAddress, toBN('0x0'), 36663)
|
|
81
|
-
).resolves.not.toThrow();
|
|
82
|
-
});
|
|
83
|
-
test('getStorageAt(blockHash=undefined, blockNumber=null)', () => {
|
|
84
|
-
return expect(provider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow();
|
|
85
|
-
});
|
|
86
|
-
test('getTransactionStatus()', async () => {
|
|
87
|
-
return expect(provider.getTransactionStatus(exampleTransactionHash)).resolves.not.toThrow();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test('getTransaction() - successful transaction', async () => {
|
|
91
|
-
const transaction = await provider.getTransaction(exampleTransactionHash);
|
|
92
|
-
|
|
93
|
-
expect(transaction).not.toHaveProperty('transaction_failure_reason');
|
|
94
|
-
|
|
95
|
-
expect(transaction.transaction).toHaveProperty('transaction_hash');
|
|
96
|
-
|
|
97
|
-
return expect(transaction.status).not.toEqual('REJECTED');
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('getTransactionReceipt() - successful transaction', async () => {
|
|
101
|
-
const transactionReceipt = await provider.getTransactionReceipt(exampleTransactionHash);
|
|
102
|
-
|
|
103
|
-
return expect(transactionReceipt).toHaveProperty('actual_fee');
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test('callContract()', () => {
|
|
107
|
-
return expect(
|
|
108
|
-
provider.callContract({
|
|
109
|
-
contractAddress: exampleContractAddress,
|
|
110
|
-
entrypoint: 'balance_of',
|
|
111
|
-
calldata: compileCalldata({
|
|
112
|
-
user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b',
|
|
113
|
-
}),
|
|
114
|
-
})
|
|
115
|
-
).resolves.not.toThrow();
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test('callContract() - gateway error', async () => {
|
|
119
|
-
const promise = provider.callContract({
|
|
120
|
-
contractAddress: exampleContractAddress,
|
|
121
|
-
entrypoint: 'non_existent_entrypoint',
|
|
122
|
-
calldata: compileCalldata({
|
|
123
|
-
user: '0xdeadbeef',
|
|
124
|
-
}),
|
|
125
|
-
});
|
|
126
|
-
expect(promise).rejects.toHaveProperty('errorCode');
|
|
127
|
-
expect(promise).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
128
|
-
`"Entry point 0x23b0c8b3d98aa73d8a35f5303fe77d132c6d04279e63f6e1d6aac5946e04612 not found in contract with class hash 0x2864c45bd4ba3e66d8f7855adcadf07205c88f43806ffca664f1f624765207e."`
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
await promise;
|
|
133
|
-
} catch (e) {
|
|
134
|
-
expect(e.errorCode).toMatchInlineSnapshot(
|
|
135
|
-
IS_DEVNET ? `500` : `"StarknetErrorCode.ENTRY_POINT_NOT_FOUND_IN_CONTRACT"`
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
test('transaction trace', async () => {
|
|
141
|
-
const transactionTrace = await provider.getTransactionTrace(exampleTransactionHash);
|
|
142
|
-
expect(transactionTrace).toHaveProperty('function_invocation');
|
|
143
|
-
expect(transactionTrace).toHaveProperty('signature');
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe('addTransaction()', () => {
|
|
148
|
-
test('declareContract()', async () => {
|
|
149
|
-
const response = await provider.declareContract({
|
|
150
|
-
contract: compiledErc20,
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
expect(response.code).toBe('TRANSACTION_RECEIVED');
|
|
154
|
-
expect(response.transaction_hash).toBeDefined();
|
|
155
|
-
expect(response.class_hash).toBeDefined();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test('deployContract()', async () => {
|
|
159
|
-
const response = await provider.deployContract({
|
|
160
|
-
contract: compiledOpenZeppelinAccount,
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
expect(response.code).toBe('TRANSACTION_RECEIVED');
|
|
164
|
-
expect(response.transaction_hash).toBeDefined();
|
|
165
|
-
expect(response.address).toBeDefined();
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
});
|