starknet 2.0.1 → 2.2.0
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 +48 -0
- package/README.md +44 -4
- package/__tests__/provider.test.ts +3 -3
- package/__tests__/utils/ellipticalCurve.test.ts +1 -1
- package/constants.d.ts +5 -5
- package/contract.d.ts +5 -1
- package/contract.js +32 -7
- package/dist/constants.d.ts +5 -5
- package/dist/contract.d.ts +5 -1
- package/dist/contract.js +29 -7
- package/dist/provider/default.d.ts +7 -5
- package/dist/provider/default.js +24 -19
- package/dist/types.d.ts +21 -14
- package/package.json +4 -2
- package/provider/default.d.ts +11 -5
- package/provider/default.js +62 -38
- package/src/constants.ts +6 -4
- package/src/contract.ts +42 -11
- package/src/provider/default.ts +45 -27
- package/src/types.ts +20 -8
- package/tsconfig.json +3 -2
- package/types.d.ts +21 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
+
# [2.2.0](https://github.com/seanjameshan/starknet.js/compare/v2.1.0...v2.2.0) (2021-11-30)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- bump version ([02c8d07](https://github.com/seanjameshan/starknet.js/commit/02c8d0772e42c81e35a3a841169eb25cde68716e))
|
|
6
|
+
- correctly parse structs in Starknet return types ([5a4a318](https://github.com/seanjameshan/starknet.js/commit/5a4a318dad4c78fe84540ad92063fc1879317ac1))
|
|
7
|
+
- make Typescript compiler happy with constant types ([aedd895](https://github.com/seanjameshan/starknet.js/commit/aedd895a62e6018dd1d7330b004d54360007967f))
|
|
8
|
+
- use urljoin ([4f1a040](https://github.com/seanjameshan/starknet.js/commit/4f1a04090f26f8e8565c516921d5d3332b6a4649))
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
- bump version ([fd22f41](https://github.com/seanjameshan/starknet.js/commit/fd22f41e39ec1c7f71c32019309f82ad0f4d66a9))
|
|
13
|
+
|
|
14
|
+
## [2.1.1](https://github.com/seanjameshan/starknet.js/compare/v2.1.0...v2.1.1) (2021-11-30)
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
- bump version ([02c8d07](https://github.com/seanjameshan/starknet.js/commit/02c8d0772e42c81e35a3a841169eb25cde68716e))
|
|
19
|
+
- correctly parse structs in Starknet return types ([5a4a318](https://github.com/seanjameshan/starknet.js/commit/5a4a318dad4c78fe84540ad92063fc1879317ac1))
|
|
20
|
+
- make Typescript compiler happy with constant types ([aedd895](https://github.com/seanjameshan/starknet.js/commit/aedd895a62e6018dd1d7330b004d54360007967f))
|
|
21
|
+
- use urljoin ([4f1a040](https://github.com/seanjameshan/starknet.js/commit/4f1a04090f26f8e8565c516921d5d3332b6a4649))
|
|
22
|
+
|
|
23
|
+
## [2.1.1](https://github.com/seanjameshan/starknet.js/compare/v2.1.0...v2.1.1) (2021-11-30)
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
- correctly parse structs in Starknet return types ([5a4a318](https://github.com/seanjameshan/starknet.js/commit/5a4a318dad4c78fe84540ad92063fc1879317ac1))
|
|
28
|
+
- make Typescript compiler happy with constant types ([aedd895](https://github.com/seanjameshan/starknet.js/commit/aedd895a62e6018dd1d7330b004d54360007967f))
|
|
29
|
+
- use urljoin ([4f1a040](https://github.com/seanjameshan/starknet.js/commit/4f1a04090f26f8e8565c516921d5d3332b6a4649))
|
|
30
|
+
|
|
31
|
+
# [2.1.0](https://github.com/seanjameshan/starknet.js/compare/v2.0.1...v2.1.0) (2021-11-30)
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
- deps ([020ba39](https://github.com/seanjameshan/starknet.js/commit/020ba3948f03e41fc96c7c002b613250d73fbda6))
|
|
36
|
+
- transaction status pending ([198d82b](https://github.com/seanjameshan/starknet.js/commit/198d82b30dd8c0c978cfdd2d56cb5a7e5131cb6a))
|
|
37
|
+
|
|
38
|
+
### Features
|
|
39
|
+
|
|
40
|
+
- support mainnet ([de07149](https://github.com/seanjameshan/starknet.js/commit/de07149ad6521edc9f79e2b0e9c82bf40f32fe02))
|
|
41
|
+
|
|
42
|
+
## [2.0.2](https://github.com/seanjameshan/starknet.js/compare/v2.0.1...v2.0.2) (2021-11-22)
|
|
43
|
+
|
|
44
|
+
### Bug Fixes
|
|
45
|
+
|
|
46
|
+
- correctly parse structs in Starknet return types ([5a4a318](https://github.com/seanjameshan/starknet.js/commit/5a4a318dad4c78fe84540ad92063fc1879317ac1))
|
|
47
|
+
- make Typescript compiler happy with constant types ([aedd895](https://github.com/seanjameshan/starknet.js/commit/aedd895a62e6018dd1d7330b004d54360007967f))
|
|
48
|
+
|
|
1
49
|
## [2.0.1](https://github.com/seanjameshan/starknet.js/compare/v2.0.0...v2.0.1) (2021-11-18)
|
|
2
50
|
|
|
3
51
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -44,14 +44,53 @@ $ npm install starknet
|
|
|
44
44
|
|
|
45
45
|
Import `starknet` and use the [API](https://www.starknetjs.com/modules.html)
|
|
46
46
|
|
|
47
|
+
The following code is used to build a [simple AMM example](https://starkfin.netlify.app/) from the [cairo docs](https://www.cairo-lang.org/docs/hello_starknet/amm.html)
|
|
48
|
+
|
|
47
49
|
```javascript
|
|
48
|
-
import { defaultProvider } from 'starknet';
|
|
50
|
+
import { defaultProvider, stark } from 'starknet';
|
|
51
|
+
const { getSelectorFromName } = stark;
|
|
52
|
+
|
|
53
|
+
const CONTRACT_ADDRESS =
|
|
54
|
+
"0x03e19baa6cb2078631bcdb34844f3f7879449a544c9ce722681a54af08cff4b9";
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* addTransaction() example
|
|
58
|
+
**/
|
|
59
|
+
|
|
60
|
+
/** Reset the liquidity pool **/
|
|
61
|
+
const addTokenResponse = await provider.addTransaction({
|
|
62
|
+
type: "INVOKE_FUNCTION",
|
|
63
|
+
contract_address: CONTRACT_ADDRESS,
|
|
64
|
+
entry_point_selector: getSelectorFromName("init_pool"),
|
|
65
|
+
calldata: ["1000000", "1000000"],
|
|
66
|
+
});
|
|
67
|
+
console.log(addTokenResponse);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* callContract() example
|
|
71
|
+
**/
|
|
49
72
|
|
|
50
|
-
|
|
51
|
-
|
|
73
|
+
/** Get the balance of the liquidity pool of token A **/
|
|
74
|
+
const poolBalanceTokenA = await callContract({
|
|
75
|
+
contract_address: CONTRACT_ADDRESS,
|
|
76
|
+
entry_point_selector: getSelectorFromName("get_pool_token_balance"),
|
|
77
|
+
calldata: ["1"],
|
|
52
78
|
});
|
|
79
|
+
const balanceA = poolBalanceTokenA.result[0];
|
|
80
|
+
console.log('token a liquidity pool balance: ', parseInt(balanceA, 16));
|
|
81
|
+
|
|
82
|
+
/** Get the balance of the liquidity pool of token B **/
|
|
83
|
+
const poolBalanceTokenB = await callContract({
|
|
84
|
+
contract_address: CONTRACT_ADDRESS,
|
|
85
|
+
entry_point_selector: getSelectorFromName("get_pool_token_balance"),
|
|
86
|
+
calldata: ["2"],
|
|
87
|
+
});
|
|
88
|
+
const balanceB = poolBalanceTokenB.result[0];
|
|
89
|
+
console.log('token b liquidity pool balance: ', parseInt(balanceB, 16));
|
|
53
90
|
```
|
|
54
91
|
|
|
92
|
+
For more information about **signing transactions**, please take a look at this [pull request](https://github.com/seanjameshan/starknet.js/pull/51)
|
|
93
|
+
|
|
55
94
|
## 🌐 API
|
|
56
95
|
|
|
57
96
|
[Click Here](https://www.starknetjs.com/modules.html)
|
|
@@ -60,6 +99,7 @@ defaultProvider.getContractAddresses().then((data) => {
|
|
|
60
99
|
|
|
61
100
|
- [Argent X - the first StarkNet wallet](https://github.com/argentlabs/argent-x)
|
|
62
101
|
- [React + Starknet.js boilerplate](https://github.com/fracek/starknet-react-example)
|
|
102
|
+
- [AMM Demo](https://www.starknetswap.com/)
|
|
63
103
|
|
|
64
104
|
## ✏️ Contributing
|
|
65
105
|
|
|
@@ -67,7 +107,7 @@ If you consider to contribute to this project please read [CONTRIBUTING.md](http
|
|
|
67
107
|
|
|
68
108
|
## ❤️ Special Thanks
|
|
69
109
|
|
|
70
|
-
Special thanks to all the [contributors](https://github.com/seanjameshan/starknet.js/graphs/contributors),
|
|
110
|
+
Special thanks to all the [contributors](https://github.com/seanjameshan/starknet.js/graphs/contributors), especially to Janek ([@janek26](https://github.com/janek26)) from [Argent](https://github.com/argentlabs) for driving the development of Starknet.js.
|
|
71
111
|
|
|
72
112
|
This library would not be possible without these rockstars.
|
|
73
113
|
|
|
@@ -49,17 +49,17 @@ describe('defaultProvider', () => {
|
|
|
49
49
|
)
|
|
50
50
|
).resolves.not.toThrow();
|
|
51
51
|
});
|
|
52
|
-
test('getTransactionStatus()', () => {
|
|
52
|
+
test('getTransactionStatus()', async () => {
|
|
53
53
|
return expect(
|
|
54
54
|
defaultProvider.getTransactionStatus(
|
|
55
|
-
'
|
|
55
|
+
'0x72add9621ecdcb07405a4f943fe410bf57003ca250400f01ce70f8a6fc72147'
|
|
56
56
|
)
|
|
57
57
|
).resolves.not.toThrow();
|
|
58
58
|
});
|
|
59
59
|
test('getTransaction()', async () => {
|
|
60
60
|
return expect(
|
|
61
61
|
defaultProvider.getTransaction(
|
|
62
|
-
'
|
|
62
|
+
'0x72add9621ecdcb07405a4f943fe410bf57003ca250400f01ce70f8a6fc72147'
|
|
63
63
|
)
|
|
64
64
|
).resolves.not.toThrow();
|
|
65
65
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getKeyPair, getStarkKey, sign, verify
|
|
1
|
+
import { ec, getKeyPair, getStarkKey, sign, verify } from '../../src/utils/ellipticCurve';
|
|
2
2
|
import { removeHexPrefix } from '../../src/utils/encode';
|
|
3
3
|
import { hashCalldata, hashMessage, pedersen } from '../../src/utils/hash';
|
|
4
4
|
import { toBN, toHex } from '../../src/utils/number';
|
package/constants.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import BN from 'bn.js';
|
|
2
2
|
export { IS_BROWSER } from './utils/encode';
|
|
3
|
-
export declare const ZERO:
|
|
4
|
-
export declare const ONE:
|
|
5
|
-
export declare const TWO:
|
|
6
|
-
export declare const MASK_250:
|
|
3
|
+
export declare const ZERO: BN;
|
|
4
|
+
export declare const ONE: BN;
|
|
5
|
+
export declare const TWO: BN;
|
|
6
|
+
export declare const MASK_250: BN;
|
|
7
7
|
/**
|
|
8
8
|
* The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
|
|
9
9
|
* Please do not edit until the JSON changes.
|
package/contract.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Provider } from './provider';
|
|
2
|
-
import { Abi } from './types';
|
|
2
|
+
import { Abi, StructAbi } from './types';
|
|
3
3
|
import { BigNumberish } from './utils/number';
|
|
4
4
|
export declare type Args = {
|
|
5
5
|
[inputName: string]: string | string[];
|
|
@@ -9,6 +9,9 @@ export declare function compileCalldata(args: Args): Calldata;
|
|
|
9
9
|
export declare class Contract {
|
|
10
10
|
connectedTo: string | null;
|
|
11
11
|
abi: Abi[];
|
|
12
|
+
structs: {
|
|
13
|
+
[name: string]: StructAbi;
|
|
14
|
+
};
|
|
12
15
|
provider: Provider;
|
|
13
16
|
/**
|
|
14
17
|
* Contract class to handle contract methods
|
|
@@ -19,6 +22,7 @@ export declare class Contract {
|
|
|
19
22
|
constructor(abi: Abi[], address?: string | null, provider?: Provider);
|
|
20
23
|
connect(address: string): Contract;
|
|
21
24
|
private validateMethodAndArgs;
|
|
25
|
+
private parseResponseField;
|
|
22
26
|
private parseResponse;
|
|
23
27
|
invoke(
|
|
24
28
|
method: string,
|
package/contract.js
CHANGED
|
@@ -238,6 +238,14 @@ var Contract = /** @class */ (function () {
|
|
|
238
238
|
this.connectedTo = address;
|
|
239
239
|
this.provider = provider;
|
|
240
240
|
this.abi = abi;
|
|
241
|
+
this.structs = abi
|
|
242
|
+
.filter(function (abiEntry) {
|
|
243
|
+
return abiEntry.type === 'struct';
|
|
244
|
+
})
|
|
245
|
+
.reduce(function (acc, abiEntry) {
|
|
246
|
+
var _a;
|
|
247
|
+
return __assign(__assign({}, acc), ((_a = {}), (_a[abiEntry.name] = abiEntry), _a));
|
|
248
|
+
}, {});
|
|
241
249
|
}
|
|
242
250
|
Contract.prototype.connect = function (address) {
|
|
243
251
|
this.connectedTo = address;
|
|
@@ -250,9 +258,9 @@ var Contract = /** @class */ (function () {
|
|
|
250
258
|
// ensure provided method exists
|
|
251
259
|
var invokeableFunctionNames = this.abi
|
|
252
260
|
.filter(function (abi) {
|
|
261
|
+
if (abi.type !== 'function') return false;
|
|
253
262
|
var isView = abi.stateMutability === 'view';
|
|
254
|
-
|
|
255
|
-
return isFunction && type === 'INVOKE' ? !isView : isView;
|
|
263
|
+
return type === 'INVOKE' ? !isView : isView;
|
|
256
264
|
})
|
|
257
265
|
.map(function (abi) {
|
|
258
266
|
return abi.name;
|
|
@@ -263,7 +271,7 @@ var Contract = /** @class */ (function () {
|
|
|
263
271
|
);
|
|
264
272
|
// ensure args match abi type
|
|
265
273
|
var methodAbi = this.abi.find(function (abi) {
|
|
266
|
-
return abi.name === method;
|
|
274
|
+
return abi.name === method && abi.type === 'function';
|
|
267
275
|
});
|
|
268
276
|
methodAbi.inputs.forEach(function (input) {
|
|
269
277
|
if (args[input.name] !== undefined) {
|
|
@@ -291,14 +299,31 @@ var Contract = /** @class */ (function () {
|
|
|
291
299
|
}
|
|
292
300
|
});
|
|
293
301
|
};
|
|
302
|
+
Contract.prototype.parseResponseField = function (element, responseIterator) {
|
|
303
|
+
var _this = this;
|
|
304
|
+
var entries = [];
|
|
305
|
+
if (['felt', 'felt*'].includes(element.type)) {
|
|
306
|
+
return responseIterator.next().value;
|
|
307
|
+
}
|
|
308
|
+
if (element.type in this.structs) {
|
|
309
|
+
entries = this.structs[element.type].members;
|
|
310
|
+
} else if ('outputs' in element) {
|
|
311
|
+
entries = element.outputs;
|
|
312
|
+
}
|
|
313
|
+
return entries.reduce(function (acc, member) {
|
|
314
|
+
var _a;
|
|
315
|
+
return __assign(
|
|
316
|
+
__assign({}, acc),
|
|
317
|
+
((_a = {}), (_a[member.name] = _this.parseResponseField(member, responseIterator)), _a)
|
|
318
|
+
);
|
|
319
|
+
}, {});
|
|
320
|
+
};
|
|
294
321
|
Contract.prototype.parseResponse = function (method, response) {
|
|
295
322
|
var methodAbi = this.abi.find(function (abi) {
|
|
296
323
|
return abi.name === method;
|
|
297
324
|
});
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
return __assign(__assign({}, acc), ((_a = {}), (_a[output.name] = response[i]), _a));
|
|
301
|
-
}, {});
|
|
325
|
+
var responseIterator = response.flat()[Symbol.iterator]();
|
|
326
|
+
return this.parseResponseField(methodAbi, responseIterator);
|
|
302
327
|
};
|
|
303
328
|
Contract.prototype.invoke = function (method, args, signature) {
|
|
304
329
|
if (args === void 0) {
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import BN from 'bn.js';
|
|
2
2
|
export { IS_BROWSER } from './utils/encode';
|
|
3
|
-
export declare const ZERO:
|
|
4
|
-
export declare const ONE:
|
|
5
|
-
export declare const TWO:
|
|
6
|
-
export declare const MASK_250:
|
|
3
|
+
export declare const ZERO: BN;
|
|
4
|
+
export declare const ONE: BN;
|
|
5
|
+
export declare const TWO: BN;
|
|
6
|
+
export declare const MASK_250: BN;
|
|
7
7
|
/**
|
|
8
8
|
* The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
|
|
9
9
|
* Please do not edit until the JSON changes.
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Provider } from './provider';
|
|
2
|
-
import { Abi } from './types';
|
|
2
|
+
import { Abi, StructAbi } from './types';
|
|
3
3
|
import { BigNumberish } from './utils/number';
|
|
4
4
|
export declare type Args = {
|
|
5
5
|
[inputName: string]: string | string[];
|
|
@@ -9,6 +9,9 @@ export declare function compileCalldata(args: Args): Calldata;
|
|
|
9
9
|
export declare class Contract {
|
|
10
10
|
connectedTo: string | null;
|
|
11
11
|
abi: Abi[];
|
|
12
|
+
structs: {
|
|
13
|
+
[name: string]: StructAbi;
|
|
14
|
+
};
|
|
12
15
|
provider: Provider;
|
|
13
16
|
/**
|
|
14
17
|
* Contract class to handle contract methods
|
|
@@ -19,6 +22,7 @@ export declare class Contract {
|
|
|
19
22
|
constructor(abi: Abi[], address?: string | null, provider?: Provider);
|
|
20
23
|
connect(address: string): Contract;
|
|
21
24
|
private validateMethodAndArgs;
|
|
25
|
+
private parseResponseField;
|
|
22
26
|
private parseResponse;
|
|
23
27
|
invoke(method: string, args?: Args, signature?: [BigNumberish, BigNumberish]): Promise<import("./types").AddTransactionResponse>;
|
|
24
28
|
call(method: string, args?: Args): Promise<Args>;
|
package/dist/contract.js
CHANGED
|
@@ -119,6 +119,12 @@ var Contract = /** @class */ (function () {
|
|
|
119
119
|
this.connectedTo = address;
|
|
120
120
|
this.provider = provider;
|
|
121
121
|
this.abi = abi;
|
|
122
|
+
this.structs = abi
|
|
123
|
+
.filter(function (abiEntry) { return abiEntry.type === 'struct'; })
|
|
124
|
+
.reduce(function (acc, abiEntry) {
|
|
125
|
+
var _a;
|
|
126
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[abiEntry.name] = abiEntry, _a)));
|
|
127
|
+
}, {});
|
|
122
128
|
}
|
|
123
129
|
Contract.prototype.connect = function (address) {
|
|
124
130
|
this.connectedTo = address;
|
|
@@ -129,14 +135,15 @@ var Contract = /** @class */ (function () {
|
|
|
129
135
|
// ensure provided method exists
|
|
130
136
|
var invokeableFunctionNames = this.abi
|
|
131
137
|
.filter(function (abi) {
|
|
138
|
+
if (abi.type !== 'function')
|
|
139
|
+
return false;
|
|
132
140
|
var isView = abi.stateMutability === 'view';
|
|
133
|
-
|
|
134
|
-
return isFunction && type === 'INVOKE' ? !isView : isView;
|
|
141
|
+
return type === 'INVOKE' ? !isView : isView;
|
|
135
142
|
})
|
|
136
143
|
.map(function (abi) { return abi.name; });
|
|
137
144
|
(0, minimalistic_assert_1.default)(invokeableFunctionNames.includes(method), (type === 'INVOKE' ? 'invokeable' : 'viewable') + " method not found in abi");
|
|
138
145
|
// ensure args match abi type
|
|
139
|
-
var methodAbi = this.abi.find(function (abi) { return abi.name === method; });
|
|
146
|
+
var methodAbi = this.abi.find(function (abi) { return abi.name === method && abi.type === 'function'; });
|
|
140
147
|
methodAbi.inputs.forEach(function (input) {
|
|
141
148
|
if (args[input.name] !== undefined) {
|
|
142
149
|
if (input.type === 'felt') {
|
|
@@ -153,13 +160,28 @@ var Contract = /** @class */ (function () {
|
|
|
153
160
|
}
|
|
154
161
|
});
|
|
155
162
|
};
|
|
156
|
-
Contract.prototype.
|
|
157
|
-
var
|
|
158
|
-
|
|
163
|
+
Contract.prototype.parseResponseField = function (element, responseIterator) {
|
|
164
|
+
var _this = this;
|
|
165
|
+
var entries = [];
|
|
166
|
+
if (['felt', 'felt*'].includes(element.type)) {
|
|
167
|
+
return responseIterator.next().value;
|
|
168
|
+
}
|
|
169
|
+
if (element.type in this.structs) {
|
|
170
|
+
entries = this.structs[element.type].members;
|
|
171
|
+
}
|
|
172
|
+
else if ('outputs' in element) {
|
|
173
|
+
entries = element.outputs;
|
|
174
|
+
}
|
|
175
|
+
return entries.reduce(function (acc, member) {
|
|
159
176
|
var _a;
|
|
160
|
-
return __assign(__assign({}, acc), (_a = {}, _a[
|
|
177
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[member.name] = _this.parseResponseField(member, responseIterator), _a)));
|
|
161
178
|
}, {});
|
|
162
179
|
};
|
|
180
|
+
Contract.prototype.parseResponse = function (method, response) {
|
|
181
|
+
var methodAbi = this.abi.find(function (abi) { return abi.name === method; });
|
|
182
|
+
var responseIterator = response.flat()[Symbol.iterator]();
|
|
183
|
+
return this.parseResponseField(methodAbi, responseIterator);
|
|
184
|
+
};
|
|
163
185
|
Contract.prototype.invoke = function (method, args, signature) {
|
|
164
186
|
if (args === void 0) { args = {}; }
|
|
165
187
|
// ensure contract is connected
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { AddTransactionResponse, CallContractResponse, CallContractTransaction, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Transaction } from '../types';
|
|
2
2
|
import { BigNumberish } from '../utils/number';
|
|
3
3
|
import { ProviderInterface } from './interface';
|
|
4
|
-
declare type NetworkName = 'alpha';
|
|
5
|
-
|
|
6
|
-
network
|
|
7
|
-
}
|
|
4
|
+
declare type NetworkName = 'mainnet-alpha' | 'georli-alpha';
|
|
5
|
+
declare type ProviderOptions = {
|
|
6
|
+
network: NetworkName;
|
|
7
|
+
} | {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
};
|
|
8
10
|
export declare class Provider implements ProviderInterface {
|
|
9
11
|
baseUrl: string;
|
|
10
12
|
feederGatewayUrl: string;
|
|
11
13
|
gatewayUrl: string;
|
|
12
14
|
constructor(optionsOrProvider?: ProviderOptions | Provider);
|
|
13
|
-
protected static getNetworkFromName(name: NetworkName):
|
|
15
|
+
protected static getNetworkFromName(name: NetworkName): "https://alpha-mainnet.starknet.io" | "https://alpha4.starknet.io";
|
|
14
16
|
/**
|
|
15
17
|
* Gets the smart contract address on the goerli testnet.
|
|
16
18
|
*
|
package/dist/provider/default.js
CHANGED
|
@@ -52,6 +52,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.Provider = void 0;
|
|
54
54
|
var axios_1 = __importDefault(require("axios"));
|
|
55
|
+
var url_join_1 = __importDefault(require("url-join"));
|
|
55
56
|
var json_1 = require("../utils/json");
|
|
56
57
|
var number_1 = require("../utils/number");
|
|
57
58
|
var stark_1 = require("../utils/stark");
|
|
@@ -60,22 +61,26 @@ function wait(delay) {
|
|
|
60
61
|
}
|
|
61
62
|
var Provider = /** @class */ (function () {
|
|
62
63
|
function Provider(optionsOrProvider) {
|
|
64
|
+
if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'georli-alpha' }; }
|
|
63
65
|
if (optionsOrProvider instanceof Provider) {
|
|
64
66
|
this.baseUrl = optionsOrProvider.baseUrl;
|
|
65
67
|
this.feederGatewayUrl = optionsOrProvider.feederGatewayUrl;
|
|
66
68
|
this.gatewayUrl = optionsOrProvider.gatewayUrl;
|
|
67
69
|
}
|
|
68
70
|
else {
|
|
69
|
-
var
|
|
70
|
-
|
|
71
|
+
var baseUrl = 'baseUrl' in optionsOrProvider
|
|
72
|
+
? optionsOrProvider.baseUrl
|
|
73
|
+
: Provider.getNetworkFromName(optionsOrProvider.network);
|
|
71
74
|
this.baseUrl = baseUrl;
|
|
72
|
-
this.feederGatewayUrl = baseUrl
|
|
73
|
-
this.gatewayUrl = baseUrl
|
|
75
|
+
this.feederGatewayUrl = (0, url_join_1.default)(baseUrl, 'feeder_gateway');
|
|
76
|
+
this.gatewayUrl = (0, url_join_1.default)(baseUrl, 'gateway');
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
Provider.getNetworkFromName = function (name) {
|
|
77
80
|
switch (name) {
|
|
78
|
-
case 'alpha':
|
|
81
|
+
case 'mainnet-alpha':
|
|
82
|
+
return 'https://alpha-mainnet.starknet.io';
|
|
83
|
+
case 'georli-alpha':
|
|
79
84
|
default:
|
|
80
85
|
return 'https://alpha4.starknet.io';
|
|
81
86
|
}
|
|
@@ -91,7 +96,7 @@ var Provider = /** @class */ (function () {
|
|
|
91
96
|
var data;
|
|
92
97
|
return __generator(this, function (_a) {
|
|
93
98
|
switch (_a.label) {
|
|
94
|
-
case 0: return [4 /*yield*/, axios_1.default.get(this.feederGatewayUrl
|
|
99
|
+
case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_contract_addresses'))];
|
|
95
100
|
case 1:
|
|
96
101
|
data = (_a.sent()).data;
|
|
97
102
|
return [2 /*return*/, data];
|
|
@@ -113,7 +118,7 @@ var Provider = /** @class */ (function () {
|
|
|
113
118
|
var data;
|
|
114
119
|
return __generator(this, function (_a) {
|
|
115
120
|
switch (_a.label) {
|
|
116
|
-
case 0: return [4 /*yield*/, axios_1.default.post(this.feederGatewayUrl
|
|
121
|
+
case 0: return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.feederGatewayUrl, 'call_contract', "?blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null')), __assign({ signature: [], calldata: [] }, invokeTx))];
|
|
117
122
|
case 1:
|
|
118
123
|
data = (_a.sent()).data;
|
|
119
124
|
return [2 /*return*/, data];
|
|
@@ -134,7 +139,7 @@ var Provider = /** @class */ (function () {
|
|
|
134
139
|
var data;
|
|
135
140
|
return __generator(this, function (_a) {
|
|
136
141
|
switch (_a.label) {
|
|
137
|
-
case 0: return [4 /*yield*/, axios_1.default.get(this.feederGatewayUrl
|
|
142
|
+
case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_block', "?blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null')))];
|
|
138
143
|
case 1:
|
|
139
144
|
data = (_a.sent()).data;
|
|
140
145
|
return [2 /*return*/, data];
|
|
@@ -156,7 +161,7 @@ var Provider = /** @class */ (function () {
|
|
|
156
161
|
var data;
|
|
157
162
|
return __generator(this, function (_a) {
|
|
158
163
|
switch (_a.label) {
|
|
159
|
-
case 0: return [4 /*yield*/, axios_1.default.get(this.feederGatewayUrl
|
|
164
|
+
case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_code', "?contractAddress=" + contractAddress + "&blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null')))];
|
|
160
165
|
case 1:
|
|
161
166
|
data = (_a.sent()).data;
|
|
162
167
|
return [2 /*return*/, data];
|
|
@@ -180,7 +185,7 @@ var Provider = /** @class */ (function () {
|
|
|
180
185
|
var data;
|
|
181
186
|
return __generator(this, function (_a) {
|
|
182
187
|
switch (_a.label) {
|
|
183
|
-
case 0: return [4 /*yield*/, axios_1.default.get(this.feederGatewayUrl
|
|
188
|
+
case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_storage_at', "?contractAddress=" + contractAddress + "&key=" + key + "&blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null')))];
|
|
184
189
|
case 1:
|
|
185
190
|
data = (_a.sent()).data;
|
|
186
191
|
return [2 /*return*/, data];
|
|
@@ -203,7 +208,7 @@ var Provider = /** @class */ (function () {
|
|
|
203
208
|
switch (_a.label) {
|
|
204
209
|
case 0:
|
|
205
210
|
txHashBn = (0, number_1.toBN)(txHash);
|
|
206
|
-
return [4 /*yield*/, axios_1.default.get(this.feederGatewayUrl
|
|
211
|
+
return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_transaction_status', "?transactionHash=" + (0, number_1.toHex)(txHashBn)))];
|
|
207
212
|
case 1:
|
|
208
213
|
data = (_a.sent()).data;
|
|
209
214
|
return [2 /*return*/, data];
|
|
@@ -226,7 +231,7 @@ var Provider = /** @class */ (function () {
|
|
|
226
231
|
switch (_a.label) {
|
|
227
232
|
case 0:
|
|
228
233
|
txHashBn = (0, number_1.toBN)(txHash);
|
|
229
|
-
return [4 /*yield*/, axios_1.default.get(this.feederGatewayUrl
|
|
234
|
+
return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_transaction', "?transactionHash=" + (0, number_1.toHex)(txHashBn)))];
|
|
230
235
|
case 1:
|
|
231
236
|
data = (_a.sent()).data;
|
|
232
237
|
return [2 /*return*/, data];
|
|
@@ -250,7 +255,7 @@ var Provider = /** @class */ (function () {
|
|
|
250
255
|
case 0:
|
|
251
256
|
signature = tx.type === 'INVOKE_FUNCTION' && (0, stark_1.formatSignature)(tx.signature);
|
|
252
257
|
contract_address_salt = tx.type === 'DEPLOY' && (0, number_1.toHex)((0, number_1.toBN)(tx.contract_address_salt));
|
|
253
|
-
return [4 /*yield*/, axios_1.default.post(this.gatewayUrl
|
|
258
|
+
return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.gatewayUrl, 'add_transaction'), (0, json_1.stringify)(__assign(__assign(__assign({}, tx), (Array.isArray(signature) && { signature: signature })), (contract_address_salt && { contract_address_salt: contract_address_salt }))), { headers: { 'Content-Type': 'application/json' } })];
|
|
254
259
|
case 1:
|
|
255
260
|
data = (_a.sent()).data;
|
|
256
261
|
return [2 /*return*/, data];
|
|
@@ -296,14 +301,13 @@ var Provider = /** @class */ (function () {
|
|
|
296
301
|
});
|
|
297
302
|
};
|
|
298
303
|
Provider.prototype.waitForTx = function (txHash, retryInterval) {
|
|
299
|
-
if (retryInterval === void 0) { retryInterval =
|
|
304
|
+
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
300
305
|
return __awaiter(this, void 0, void 0, function () {
|
|
301
|
-
var onchain,
|
|
306
|
+
var onchain, res;
|
|
302
307
|
return __generator(this, function (_a) {
|
|
303
308
|
switch (_a.label) {
|
|
304
309
|
case 0:
|
|
305
310
|
onchain = false;
|
|
306
|
-
firstRun = true;
|
|
307
311
|
_a.label = 1;
|
|
308
312
|
case 1:
|
|
309
313
|
if (!!onchain) return [3 /*break*/, 4];
|
|
@@ -315,16 +319,17 @@ var Provider = /** @class */ (function () {
|
|
|
315
319
|
return [4 /*yield*/, this.getTransactionStatus(txHash)];
|
|
316
320
|
case 3:
|
|
317
321
|
res = _a.sent();
|
|
318
|
-
if (res.tx_status === 'ACCEPTED_ONCHAIN' ||
|
|
322
|
+
if (res.tx_status === 'ACCEPTED_ONCHAIN' ||
|
|
323
|
+
(res.tx_status === 'PENDING' && res.block_hash !== 'pending') // This is needed as of today. In the future there will be a different status for pending transactions.
|
|
324
|
+
) {
|
|
319
325
|
onchain = true;
|
|
320
326
|
}
|
|
321
327
|
else if (res.tx_status === 'REJECTED') {
|
|
322
328
|
throw Error('REJECTED');
|
|
323
329
|
}
|
|
324
|
-
else if (res.tx_status === 'NOT_RECEIVED'
|
|
330
|
+
else if (res.tx_status === 'NOT_RECEIVED') {
|
|
325
331
|
throw Error('NOT_RECEIVED');
|
|
326
332
|
}
|
|
327
|
-
firstRun = false;
|
|
328
333
|
return [3 /*break*/, 1];
|
|
329
334
|
case 4: return [2 /*return*/];
|
|
330
335
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -11,19 +11,26 @@ export declare type TxStatus = 'TRANSACTION_RECEIVED';
|
|
|
11
11
|
export declare type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
|
|
12
12
|
export declare type EntryPointType = 'EXTERNAL';
|
|
13
13
|
export declare type CompressedProgram = string;
|
|
14
|
-
export declare type
|
|
15
|
-
inputs: {
|
|
16
|
-
name: string;
|
|
17
|
-
type: 'felt' | 'felt*';
|
|
18
|
-
}[];
|
|
14
|
+
export declare type AbiEntry = {
|
|
19
15
|
name: string;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
type: 'felt' | 'felt*' | string;
|
|
17
|
+
};
|
|
18
|
+
export declare type FunctionAbi = {
|
|
19
|
+
inputs: AbiEntry[];
|
|
20
|
+
name: string;
|
|
21
|
+
outputs: AbiEntry[];
|
|
24
22
|
stateMutability?: 'view';
|
|
25
23
|
type: 'function';
|
|
26
24
|
};
|
|
25
|
+
export declare type StructAbi = {
|
|
26
|
+
members: (AbiEntry & {
|
|
27
|
+
offset: number;
|
|
28
|
+
})[];
|
|
29
|
+
name: string;
|
|
30
|
+
size: number;
|
|
31
|
+
type: 'struct';
|
|
32
|
+
};
|
|
33
|
+
export declare type Abi = FunctionAbi | StructAbi;
|
|
27
34
|
export declare type EntryPointsByType = object;
|
|
28
35
|
export declare type Program = object;
|
|
29
36
|
export declare type CompiledContract = {
|
|
@@ -54,14 +61,14 @@ export declare type CallContractResponse = {
|
|
|
54
61
|
export declare type GetBlockResponse = {
|
|
55
62
|
sequence_number: number;
|
|
56
63
|
state_root: string;
|
|
57
|
-
|
|
64
|
+
block_hash: string;
|
|
58
65
|
transactions: {
|
|
59
66
|
[txHash: string]: Transaction;
|
|
60
67
|
};
|
|
61
68
|
timestamp: number;
|
|
62
69
|
transaction_receipts: {
|
|
63
70
|
[txHash: string]: {
|
|
64
|
-
|
|
71
|
+
block_hash: string;
|
|
65
72
|
transaction_hash: string;
|
|
66
73
|
l2_to_l1_messages: {
|
|
67
74
|
to_address: string;
|
|
@@ -73,7 +80,7 @@ export declare type GetBlockResponse = {
|
|
|
73
80
|
transaction_index: number;
|
|
74
81
|
};
|
|
75
82
|
};
|
|
76
|
-
|
|
83
|
+
previous_block_hash: string;
|
|
77
84
|
status: Status;
|
|
78
85
|
};
|
|
79
86
|
export declare type GetCodeResponse = {
|
|
@@ -82,12 +89,12 @@ export declare type GetCodeResponse = {
|
|
|
82
89
|
};
|
|
83
90
|
export declare type GetTransactionStatusResponse = {
|
|
84
91
|
tx_status: Status;
|
|
85
|
-
|
|
92
|
+
block_hash: string;
|
|
86
93
|
};
|
|
87
94
|
export declare type GetTransactionResponse = {
|
|
88
95
|
status: Status;
|
|
89
96
|
transaction: Transaction;
|
|
90
|
-
|
|
97
|
+
block_hash: string;
|
|
91
98
|
block_number: number;
|
|
92
99
|
transaction_index: number;
|
|
93
100
|
transaction_hash: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starknet",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "JavaScript library for StarkNet",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"@types/json-bigint": "^1.0.1",
|
|
41
41
|
"@types/minimalistic-assert": "^1.0.1",
|
|
42
42
|
"@types/pako": "^1.0.2",
|
|
43
|
+
"@types/url-join": "^4.0.1",
|
|
43
44
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
44
45
|
"@typescript-eslint/parser": "^5.0.0",
|
|
45
46
|
"eslint": "^7.32.0",
|
|
@@ -65,7 +66,8 @@
|
|
|
65
66
|
"hash.js": "^1.1.7",
|
|
66
67
|
"json-bigint": "^1.0.0",
|
|
67
68
|
"minimalistic-assert": "^1.0.1",
|
|
68
|
-
"pako": "^2.0.4"
|
|
69
|
+
"pako": "^2.0.4",
|
|
70
|
+
"url-join": "^4.0.1"
|
|
69
71
|
},
|
|
70
72
|
"lint-staged": {
|
|
71
73
|
"*.ts": "eslint --cache --fix",
|