starknet 0.1.2 → 1.1.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/.babelrc +6 -0
- package/.commitlintrc +12 -0
- package/.eslintignore +2 -0
- package/.eslintrc +20 -0
- package/.github/workflows/pr.yml +23 -0
- package/.github/workflows/release.yml +40 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/{.prettierrc.json → .prettierrc} +0 -1
- package/.releaserc +28 -0
- package/CHANGELOG.md +49 -0
- package/CONTRIBUTING.md +52 -0
- package/README.md +39 -11
- package/__mocks__/ArgentAccount.json +92620 -0
- package/__tests__/__snapshots__/utils.browser.test.ts.snap +5 -0
- package/__tests__/__snapshots__/utils.test.ts.snap +5 -0
- package/__tests__/index.test.ts +49 -4
- package/__tests__/utils.browser.test.ts +30 -0
- package/__tests__/utils.test.ts +35 -0
- package/constants.d.ts +3 -0
- package/constants.js +9 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +6 -0
- package/dist/index.d.ts +23 -9
- package/dist/index.js +51 -5
- package/dist/types.d.ts +89 -0
- package/dist/types.js +2 -0
- package/dist/utils.d.ts +21 -0
- package/dist/utils.js +44 -0
- package/docs/README.md +235 -0
- package/index.d.ts +115 -0
- package/index.js +261 -0
- package/package.json +29 -5
- package/src/constants.ts +3 -0
- package/src/index.ts +67 -21
- package/src/types.ts +95 -0
- package/src/utils.ts +44 -0
- package/tsconfig.eslint.json +4 -0
- package/tsconfig.json +15 -13
- package/types.d.ts +94 -0
- package/types.js +2 -0
- package/utils.d.ts +29 -0
- package/utils.js +62 -0
- package/.eslintrc.json +0 -26
- package/babel.config.js +0 -3
- package/dist/__tests__/index.test.d.ts +0 -1
- package/dist/__tests__/index.test.js +0 -49
- package/docs/Home.md +0 -220
- package/docs/_Sidebar.md +0 -3
package/docs/README.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
StarkNet.js Docs
|
|
2
|
+
|
|
3
|
+
# StarkNet.js Docs
|
|
4
|
+
|
|
5
|
+
## Table of contents
|
|
6
|
+
|
|
7
|
+
### Functions
|
|
8
|
+
|
|
9
|
+
- [addTransaction](README.md#addtransaction)
|
|
10
|
+
- [callContract](README.md#callcontract)
|
|
11
|
+
- [compressProgram](README.md#compressprogram)
|
|
12
|
+
- [deployContract](README.md#deploycontract)
|
|
13
|
+
- [getBlock](README.md#getblock)
|
|
14
|
+
- [getCode](README.md#getcode)
|
|
15
|
+
- [getContractAddresses](README.md#getcontractaddresses)
|
|
16
|
+
- [getStorageAt](README.md#getstorageat)
|
|
17
|
+
- [getTransaction](README.md#gettransaction)
|
|
18
|
+
- [getTransactionStatus](README.md#gettransactionstatus)
|
|
19
|
+
|
|
20
|
+
## Functions
|
|
21
|
+
|
|
22
|
+
### addTransaction
|
|
23
|
+
|
|
24
|
+
▸ **addTransaction**(`tx`): `Promise`<`AddTransactionResponse`\>
|
|
25
|
+
|
|
26
|
+
Invoke a function on the starknet contract
|
|
27
|
+
|
|
28
|
+
[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
29
|
+
|
|
30
|
+
#### Parameters
|
|
31
|
+
|
|
32
|
+
| Name | Type | Description |
|
|
33
|
+
| :--- | :------------ | :------------------------------ |
|
|
34
|
+
| `tx` | `Transaction` | transaction to be invoked (WIP) |
|
|
35
|
+
|
|
36
|
+
#### Returns
|
|
37
|
+
|
|
38
|
+
`Promise`<`AddTransactionResponse`\>
|
|
39
|
+
|
|
40
|
+
a confirmation of invoking a function on the starknet contract
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
### callContract
|
|
45
|
+
|
|
46
|
+
▸ **callContract**(`invokeTx`, `blockId`): `Promise`<`object`\>
|
|
47
|
+
|
|
48
|
+
Calls a function on the StarkNet contract.
|
|
49
|
+
|
|
50
|
+
[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
|
|
51
|
+
|
|
52
|
+
#### Parameters
|
|
53
|
+
|
|
54
|
+
| Name | Type | Description |
|
|
55
|
+
| :--------- | :------- | :------------------------------ |
|
|
56
|
+
| `invokeTx` | `object` | transaction to be invoked (WIP) |
|
|
57
|
+
| `blockId` | `number` | |
|
|
58
|
+
|
|
59
|
+
#### Returns
|
|
60
|
+
|
|
61
|
+
`Promise`<`object`\>
|
|
62
|
+
|
|
63
|
+
the result of the function on the smart contract.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
### compressProgram
|
|
68
|
+
|
|
69
|
+
▸ **compressProgram**(`jsonProgram`): `CompressedProgram`
|
|
70
|
+
|
|
71
|
+
Function to compress compiled cairo program
|
|
72
|
+
|
|
73
|
+
[Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/gateway/transaction.py#L54-L58)
|
|
74
|
+
|
|
75
|
+
#### Parameters
|
|
76
|
+
|
|
77
|
+
| Name | Type | Description |
|
|
78
|
+
| :------------ | :------------------- | :------------------------------------------------ |
|
|
79
|
+
| `jsonProgram` | `string` \| `object` | json file representing the compiled cairo program |
|
|
80
|
+
|
|
81
|
+
#### Returns
|
|
82
|
+
|
|
83
|
+
`CompressedProgram`
|
|
84
|
+
|
|
85
|
+
Compressed cairo program
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### deployContract
|
|
90
|
+
|
|
91
|
+
▸ **deployContract**(`contract`, `address?`): `Promise`<`AddTransactionResponse`\>
|
|
92
|
+
|
|
93
|
+
Deploys a given compiled contract (json) to starknet
|
|
94
|
+
|
|
95
|
+
#### Parameters
|
|
96
|
+
|
|
97
|
+
| Name | Type | Description |
|
|
98
|
+
| :--------- | :----------------------------- | :------------------------------------------------------------------------------------------------- |
|
|
99
|
+
| `contract` | `string` \| `CompiledContract` | a json object containing the compiled contract |
|
|
100
|
+
| `address` | `string` | (optional, defaults to a random address) the address where the contract should be deployed (alpha) |
|
|
101
|
+
|
|
102
|
+
#### Returns
|
|
103
|
+
|
|
104
|
+
`Promise`<`AddTransactionResponse`\>
|
|
105
|
+
|
|
106
|
+
a confirmation of sending a transaction on the starknet contract
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
### getBlock
|
|
111
|
+
|
|
112
|
+
▸ **getBlock**(`blockId`): `Promise`<`GetBlockResponse`\>
|
|
113
|
+
|
|
114
|
+
Gets the block information from a block ID.
|
|
115
|
+
|
|
116
|
+
[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
|
|
117
|
+
|
|
118
|
+
#### Parameters
|
|
119
|
+
|
|
120
|
+
| Name | Type |
|
|
121
|
+
| :-------- | :------- |
|
|
122
|
+
| `blockId` | `number` |
|
|
123
|
+
|
|
124
|
+
#### Returns
|
|
125
|
+
|
|
126
|
+
`Promise`<`GetBlockResponse`\>
|
|
127
|
+
|
|
128
|
+
the block object { block_id, previous_block_id, state_root, status, timestamp, transaction_receipts, transactions }
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
### getCode
|
|
133
|
+
|
|
134
|
+
▸ **getCode**(`contractAddress`, `blockId`): `Promise`<`GetCode`\>
|
|
135
|
+
|
|
136
|
+
Gets the code of the deployed contract.
|
|
137
|
+
|
|
138
|
+
[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
|
|
139
|
+
|
|
140
|
+
#### Parameters
|
|
141
|
+
|
|
142
|
+
| Name | Type |
|
|
143
|
+
| :---------------- | :------- |
|
|
144
|
+
| `contractAddress` | `string` |
|
|
145
|
+
| `blockId` | `number` |
|
|
146
|
+
|
|
147
|
+
#### Returns
|
|
148
|
+
|
|
149
|
+
`Promise`<`GetCode`\>
|
|
150
|
+
|
|
151
|
+
Bytecode and ABI of compiled contract
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
### getContractAddresses
|
|
156
|
+
|
|
157
|
+
▸ **getContractAddresses**(): `Promise`<`GetContractAddressesResponse`\>
|
|
158
|
+
|
|
159
|
+
Gets the smart contract address on the goerli testnet.
|
|
160
|
+
|
|
161
|
+
[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
|
|
162
|
+
|
|
163
|
+
#### Returns
|
|
164
|
+
|
|
165
|
+
`Promise`<`GetContractAddressesResponse`\>
|
|
166
|
+
|
|
167
|
+
starknet smart contract addresses
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
### getStorageAt
|
|
172
|
+
|
|
173
|
+
▸ **getStorageAt**(`contractAddress`, `key`, `blockId`): `Promise`<`object`\>
|
|
174
|
+
|
|
175
|
+
Gets the contract's storage variable at a specific key.
|
|
176
|
+
|
|
177
|
+
[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
|
|
178
|
+
|
|
179
|
+
#### Parameters
|
|
180
|
+
|
|
181
|
+
| Name | Type | Description |
|
|
182
|
+
| :---------------- | :------- | :--------------------------------------------------------- |
|
|
183
|
+
| `contractAddress` | `string` | |
|
|
184
|
+
| `key` | `number` | from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP) |
|
|
185
|
+
| `blockId` | `number` | |
|
|
186
|
+
|
|
187
|
+
#### Returns
|
|
188
|
+
|
|
189
|
+
`Promise`<`object`\>
|
|
190
|
+
|
|
191
|
+
the value of the storage variable
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
### getTransaction
|
|
196
|
+
|
|
197
|
+
▸ **getTransaction**(`txId`): `Promise`<`GetTransactionResponse`\>
|
|
198
|
+
|
|
199
|
+
Gets the transaction information from a tx id.
|
|
200
|
+
|
|
201
|
+
[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
|
|
202
|
+
|
|
203
|
+
#### Parameters
|
|
204
|
+
|
|
205
|
+
| Name | Type |
|
|
206
|
+
| :----- | :------- |
|
|
207
|
+
| `txId` | `number` |
|
|
208
|
+
|
|
209
|
+
#### Returns
|
|
210
|
+
|
|
211
|
+
`Promise`<`GetTransactionResponse`\>
|
|
212
|
+
|
|
213
|
+
the transacton object { transaction_id, status, transaction, block_id?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
### getTransactionStatus
|
|
218
|
+
|
|
219
|
+
▸ **getTransactionStatus**(`txId`): `Promise`<`GetTransactionStatusResponse`\>
|
|
220
|
+
|
|
221
|
+
Gets the status of a transaction.
|
|
222
|
+
|
|
223
|
+
[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
|
|
224
|
+
|
|
225
|
+
#### Parameters
|
|
226
|
+
|
|
227
|
+
| Name | Type |
|
|
228
|
+
| :----- | :------- |
|
|
229
|
+
| `txId` | `number` |
|
|
230
|
+
|
|
231
|
+
#### Returns
|
|
232
|
+
|
|
233
|
+
`Promise`<`GetTransactionStatusResponse`\>
|
|
234
|
+
|
|
235
|
+
the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { compressProgram } from './utils';
|
|
2
|
+
import type {
|
|
3
|
+
GetBlockResponse,
|
|
4
|
+
GetCode,
|
|
5
|
+
GetContractAddressesResponse,
|
|
6
|
+
GetTransactionResponse,
|
|
7
|
+
GetTransactionStatusResponse,
|
|
8
|
+
Transaction,
|
|
9
|
+
AddTransactionResponse,
|
|
10
|
+
CompiledContract,
|
|
11
|
+
} from './types';
|
|
12
|
+
/**
|
|
13
|
+
* Gets the smart contract address on the goerli testnet.
|
|
14
|
+
*
|
|
15
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
|
|
16
|
+
* @returns starknet smart contract addresses
|
|
17
|
+
*/
|
|
18
|
+
export declare function getContractAddresses(): Promise<GetContractAddressesResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* Calls a function on the StarkNet contract.
|
|
21
|
+
*
|
|
22
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
|
|
23
|
+
*
|
|
24
|
+
* @param invokeTx - transaction to be invoked (WIP)
|
|
25
|
+
* @param blockId
|
|
26
|
+
* @returns the result of the function on the smart contract.
|
|
27
|
+
*/
|
|
28
|
+
export declare function callContract(invokeTx: object, blockId: number): Promise<object>;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the block information from a block ID.
|
|
31
|
+
*
|
|
32
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
|
|
33
|
+
*
|
|
34
|
+
* @param blockId
|
|
35
|
+
* @returns the block object { block_id, previous_block_id, state_root, status, timestamp, transaction_receipts, transactions }
|
|
36
|
+
*/
|
|
37
|
+
export declare function getBlock(blockId: number): Promise<GetBlockResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the code of the deployed contract.
|
|
40
|
+
*
|
|
41
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
|
|
42
|
+
*
|
|
43
|
+
* @param contractAddress
|
|
44
|
+
* @param blockId
|
|
45
|
+
* @returns Bytecode and ABI of compiled contract
|
|
46
|
+
*/
|
|
47
|
+
export declare function getCode(contractAddress: string, blockId: number): Promise<GetCode>;
|
|
48
|
+
/**
|
|
49
|
+
* Gets the contract's storage variable at a specific key.
|
|
50
|
+
*
|
|
51
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
|
|
52
|
+
*
|
|
53
|
+
* @param contractAddress
|
|
54
|
+
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
55
|
+
* @param blockId
|
|
56
|
+
* @returns the value of the storage variable
|
|
57
|
+
*/
|
|
58
|
+
export declare function getStorageAt(
|
|
59
|
+
contractAddress: string,
|
|
60
|
+
key: number,
|
|
61
|
+
blockId: number
|
|
62
|
+
): Promise<object>;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the status of a transaction.
|
|
65
|
+
*
|
|
66
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
|
|
67
|
+
*
|
|
68
|
+
* @param txId
|
|
69
|
+
* @returns the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
|
|
70
|
+
*/
|
|
71
|
+
export declare function getTransactionStatus(txId: number): Promise<GetTransactionStatusResponse>;
|
|
72
|
+
/**
|
|
73
|
+
* Gets the transaction information from a tx id.
|
|
74
|
+
*
|
|
75
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
|
|
76
|
+
*
|
|
77
|
+
* @param txId
|
|
78
|
+
* @returns the transacton object { transaction_id, status, transaction, block_id?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
79
|
+
*/
|
|
80
|
+
export declare function getTransaction(txId: number): Promise<GetTransactionResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* Invoke a function on the starknet contract
|
|
83
|
+
*
|
|
84
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
85
|
+
*
|
|
86
|
+
* @param tx - transaction to be invoked (WIP)
|
|
87
|
+
* @returns a confirmation of invoking a function on the starknet contract
|
|
88
|
+
*/
|
|
89
|
+
export declare function addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* Deploys a given compiled contract (json) to starknet
|
|
92
|
+
*
|
|
93
|
+
* @param contract - a json object containing the compiled contract
|
|
94
|
+
* @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha)
|
|
95
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
96
|
+
*/
|
|
97
|
+
export declare function deployContract(
|
|
98
|
+
contract: CompiledContract | string,
|
|
99
|
+
address?: string
|
|
100
|
+
): Promise<AddTransactionResponse>;
|
|
101
|
+
export * from './utils';
|
|
102
|
+
export * from './types';
|
|
103
|
+
declare const _default: {
|
|
104
|
+
getContractAddresses: typeof getContractAddresses;
|
|
105
|
+
callContract: typeof callContract;
|
|
106
|
+
getBlock: typeof getBlock;
|
|
107
|
+
getCode: typeof getCode;
|
|
108
|
+
getStorageAt: typeof getStorageAt;
|
|
109
|
+
getTransactionStatus: typeof getTransactionStatus;
|
|
110
|
+
getTransaction: typeof getTransaction;
|
|
111
|
+
addTransaction: typeof addTransaction;
|
|
112
|
+
compressProgram: typeof compressProgram;
|
|
113
|
+
deployContract: typeof deployContract;
|
|
114
|
+
};
|
|
115
|
+
export default _default;
|
package/index.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __assign =
|
|
3
|
+
(this && this.__assign) ||
|
|
4
|
+
function () {
|
|
5
|
+
__assign =
|
|
6
|
+
Object.assign ||
|
|
7
|
+
function (t) {
|
|
8
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
+
s = arguments[i];
|
|
10
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
};
|
|
14
|
+
return __assign.apply(this, arguments);
|
|
15
|
+
};
|
|
16
|
+
var __createBinding =
|
|
17
|
+
(this && this.__createBinding) ||
|
|
18
|
+
(Object.create
|
|
19
|
+
? function (o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
Object.defineProperty(o, k2, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return m[k];
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
: function (o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
o[k2] = m[k];
|
|
31
|
+
});
|
|
32
|
+
var __exportStar =
|
|
33
|
+
(this && this.__exportStar) ||
|
|
34
|
+
function (m, exports) {
|
|
35
|
+
for (var p in m)
|
|
36
|
+
if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
37
|
+
__createBinding(exports, m, p);
|
|
38
|
+
};
|
|
39
|
+
var __importDefault =
|
|
40
|
+
(this && this.__importDefault) ||
|
|
41
|
+
function (mod) {
|
|
42
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
45
|
+
exports.deployContract =
|
|
46
|
+
exports.addTransaction =
|
|
47
|
+
exports.getTransaction =
|
|
48
|
+
exports.getTransactionStatus =
|
|
49
|
+
exports.getStorageAt =
|
|
50
|
+
exports.getCode =
|
|
51
|
+
exports.getBlock =
|
|
52
|
+
exports.callContract =
|
|
53
|
+
exports.getContractAddresses =
|
|
54
|
+
void 0;
|
|
55
|
+
var axios_1 = __importDefault(require('axios'));
|
|
56
|
+
var utils_1 = require('./utils');
|
|
57
|
+
var API_URL = 'https://alpha2.starknet.io';
|
|
58
|
+
var FEEDER_GATEWAY_URL = API_URL + '/feeder_gateway';
|
|
59
|
+
var GATEWAY_URL = API_URL + '/gateway';
|
|
60
|
+
/**
|
|
61
|
+
* Gets the smart contract address on the goerli testnet.
|
|
62
|
+
*
|
|
63
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
|
|
64
|
+
* @returns starknet smart contract addresses
|
|
65
|
+
*/
|
|
66
|
+
function getContractAddresses() {
|
|
67
|
+
return new Promise(function (resolve, reject) {
|
|
68
|
+
axios_1.default
|
|
69
|
+
.get(FEEDER_GATEWAY_URL + '/get_contract_addresses')
|
|
70
|
+
.then(function (resp) {
|
|
71
|
+
resolve(resp.data);
|
|
72
|
+
})
|
|
73
|
+
.catch(reject);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
exports.getContractAddresses = getContractAddresses;
|
|
77
|
+
// TODO: add proper type
|
|
78
|
+
/**
|
|
79
|
+
* Calls a function on the StarkNet contract.
|
|
80
|
+
*
|
|
81
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
|
|
82
|
+
*
|
|
83
|
+
* @param invokeTx - transaction to be invoked (WIP)
|
|
84
|
+
* @param blockId
|
|
85
|
+
* @returns the result of the function on the smart contract.
|
|
86
|
+
*/
|
|
87
|
+
function callContract(invokeTx, blockId) {
|
|
88
|
+
return new Promise(function (resolve, reject) {
|
|
89
|
+
axios_1.default
|
|
90
|
+
.post(FEEDER_GATEWAY_URL + '/call_contract?blockId=' + blockId, invokeTx)
|
|
91
|
+
.then(function (resp) {
|
|
92
|
+
resolve(resp.data);
|
|
93
|
+
})
|
|
94
|
+
.catch(reject);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
exports.callContract = callContract;
|
|
98
|
+
/**
|
|
99
|
+
* Gets the block information from a block ID.
|
|
100
|
+
*
|
|
101
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
|
|
102
|
+
*
|
|
103
|
+
* @param blockId
|
|
104
|
+
* @returns the block object { block_id, previous_block_id, state_root, status, timestamp, transaction_receipts, transactions }
|
|
105
|
+
*/
|
|
106
|
+
function getBlock(blockId) {
|
|
107
|
+
return new Promise(function (resolve, reject) {
|
|
108
|
+
axios_1.default
|
|
109
|
+
.get(FEEDER_GATEWAY_URL + '/get_block?blockId=' + blockId)
|
|
110
|
+
.then(function (resp) {
|
|
111
|
+
resolve(resp.data);
|
|
112
|
+
})
|
|
113
|
+
.catch(reject);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
exports.getBlock = getBlock;
|
|
117
|
+
/**
|
|
118
|
+
* Gets the code of the deployed contract.
|
|
119
|
+
*
|
|
120
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
|
|
121
|
+
*
|
|
122
|
+
* @param contractAddress
|
|
123
|
+
* @param blockId
|
|
124
|
+
* @returns Bytecode and ABI of compiled contract
|
|
125
|
+
*/
|
|
126
|
+
function getCode(contractAddress, blockId) {
|
|
127
|
+
return new Promise(function (resolve, reject) {
|
|
128
|
+
axios_1.default
|
|
129
|
+
.get(
|
|
130
|
+
FEEDER_GATEWAY_URL + '/get_code?contractAddress=' + contractAddress + '&blockId=' + blockId
|
|
131
|
+
)
|
|
132
|
+
.then(function (resp) {
|
|
133
|
+
resolve(resp.data);
|
|
134
|
+
})
|
|
135
|
+
.catch(reject);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
exports.getCode = getCode;
|
|
139
|
+
// TODO: add proper type
|
|
140
|
+
/**
|
|
141
|
+
* Gets the contract's storage variable at a specific key.
|
|
142
|
+
*
|
|
143
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
|
|
144
|
+
*
|
|
145
|
+
* @param contractAddress
|
|
146
|
+
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
147
|
+
* @param blockId
|
|
148
|
+
* @returns the value of the storage variable
|
|
149
|
+
*/
|
|
150
|
+
function getStorageAt(contractAddress, key, blockId) {
|
|
151
|
+
return new Promise(function (resolve, reject) {
|
|
152
|
+
axios_1.default
|
|
153
|
+
.get(
|
|
154
|
+
FEEDER_GATEWAY_URL +
|
|
155
|
+
'/get_storage_at?contractAddress=' +
|
|
156
|
+
contractAddress +
|
|
157
|
+
'&key=' +
|
|
158
|
+
key +
|
|
159
|
+
'&blockId=' +
|
|
160
|
+
blockId
|
|
161
|
+
)
|
|
162
|
+
.then(function (resp) {
|
|
163
|
+
resolve(resp.data);
|
|
164
|
+
})
|
|
165
|
+
.catch(reject);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
exports.getStorageAt = getStorageAt;
|
|
169
|
+
/**
|
|
170
|
+
* Gets the status of a transaction.
|
|
171
|
+
*
|
|
172
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
|
|
173
|
+
*
|
|
174
|
+
* @param txId
|
|
175
|
+
* @returns the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
|
|
176
|
+
*/
|
|
177
|
+
function getTransactionStatus(txId) {
|
|
178
|
+
return new Promise(function (resolve, reject) {
|
|
179
|
+
axios_1.default
|
|
180
|
+
.get(FEEDER_GATEWAY_URL + '/get_transaction_status?transactionId=' + txId)
|
|
181
|
+
.then(function (resp) {
|
|
182
|
+
resolve(resp.data);
|
|
183
|
+
})
|
|
184
|
+
.catch(reject);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
exports.getTransactionStatus = getTransactionStatus;
|
|
188
|
+
/**
|
|
189
|
+
* Gets the transaction information from a tx id.
|
|
190
|
+
*
|
|
191
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
|
|
192
|
+
*
|
|
193
|
+
* @param txId
|
|
194
|
+
* @returns the transacton object { transaction_id, status, transaction, block_id?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
195
|
+
*/
|
|
196
|
+
function getTransaction(txId) {
|
|
197
|
+
return new Promise(function (resolve, reject) {
|
|
198
|
+
axios_1.default
|
|
199
|
+
.get(FEEDER_GATEWAY_URL + '/get_transaction?transactionId=' + txId)
|
|
200
|
+
.then(function (resp) {
|
|
201
|
+
resolve(resp.data);
|
|
202
|
+
})
|
|
203
|
+
.catch(reject);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
exports.getTransaction = getTransaction;
|
|
207
|
+
/**
|
|
208
|
+
* Invoke a function on the starknet contract
|
|
209
|
+
*
|
|
210
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
211
|
+
*
|
|
212
|
+
* @param tx - transaction to be invoked (WIP)
|
|
213
|
+
* @returns a confirmation of invoking a function on the starknet contract
|
|
214
|
+
*/
|
|
215
|
+
function addTransaction(tx) {
|
|
216
|
+
return new Promise(function (resolve, reject) {
|
|
217
|
+
axios_1.default
|
|
218
|
+
.post(GATEWAY_URL + '/add_transaction', tx)
|
|
219
|
+
.then(function (resp) {
|
|
220
|
+
resolve(resp.data);
|
|
221
|
+
})
|
|
222
|
+
.catch(reject);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
exports.addTransaction = addTransaction;
|
|
226
|
+
/**
|
|
227
|
+
* Deploys a given compiled contract (json) to starknet
|
|
228
|
+
*
|
|
229
|
+
* @param contract - a json object containing the compiled contract
|
|
230
|
+
* @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha)
|
|
231
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
232
|
+
*/
|
|
233
|
+
function deployContract(contract, address) {
|
|
234
|
+
if (address === void 0) {
|
|
235
|
+
address = (0, utils_1.randomAddress)();
|
|
236
|
+
}
|
|
237
|
+
var parsedContract = typeof contract === 'string' ? utils_1.JsonParser.parse(contract) : contract;
|
|
238
|
+
var contractDefinition = __assign(__assign({}, parsedContract), {
|
|
239
|
+
program: (0, utils_1.compressProgram)(parsedContract.program),
|
|
240
|
+
});
|
|
241
|
+
return addTransaction({
|
|
242
|
+
type: 'DEPLOY',
|
|
243
|
+
contract_address: address,
|
|
244
|
+
contract_definition: contractDefinition,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
exports.deployContract = deployContract;
|
|
248
|
+
__exportStar(require('./utils'), exports);
|
|
249
|
+
__exportStar(require('./types'), exports);
|
|
250
|
+
exports.default = {
|
|
251
|
+
getContractAddresses: getContractAddresses,
|
|
252
|
+
callContract: callContract,
|
|
253
|
+
getBlock: getBlock,
|
|
254
|
+
getCode: getCode,
|
|
255
|
+
getStorageAt: getStorageAt,
|
|
256
|
+
getTransactionStatus: getTransactionStatus,
|
|
257
|
+
getTransaction: getTransaction,
|
|
258
|
+
addTransaction: addTransaction,
|
|
259
|
+
compressProgram: utils_1.compressProgram,
|
|
260
|
+
deployContract: deployContract,
|
|
261
|
+
};
|
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starknet",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "JavaScript library for StarkNet",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"prepare": "npm run build",
|
|
8
|
+
"prepare": "npm run build && husky install",
|
|
9
9
|
"build": "tsc",
|
|
10
|
+
"pretest": "npm run lint",
|
|
10
11
|
"test": "jest",
|
|
12
|
+
"posttest": "npm run format",
|
|
11
13
|
"test:watch": "jest --watch",
|
|
12
|
-
"docs": "typedoc --
|
|
14
|
+
"docs": "typedoc --readme none --name 'StarkNet.js Docs' --excludeNotDocumented --disableSources",
|
|
15
|
+
"format": "prettier --loglevel warn --write \"**/*.{ts,js,md,yml,json}\"",
|
|
16
|
+
"lint": "eslint . --cache --fix --ext .ts"
|
|
13
17
|
},
|
|
14
18
|
"keywords": [
|
|
15
19
|
"starknet",
|
|
@@ -24,22 +28,42 @@
|
|
|
24
28
|
"devDependencies": {
|
|
25
29
|
"@babel/preset-env": "^7.15.8",
|
|
26
30
|
"@babel/preset-typescript": "^7.15.0",
|
|
31
|
+
"@commitlint/cli": "^13.2.1",
|
|
32
|
+
"@commitlint/config-conventional": "^13.2.0",
|
|
33
|
+
"@semantic-release/changelog": "^6.0.0",
|
|
34
|
+
"@semantic-release/commit-analyzer": "^9.0.1",
|
|
35
|
+
"@semantic-release/git": "^10.0.0",
|
|
36
|
+
"@semantic-release/npm": "^8.0.2",
|
|
37
|
+
"@semantic-release/release-notes-generator": "^10.0.2",
|
|
27
38
|
"@types/jest": "^27.0.2",
|
|
39
|
+
"@types/json-bigint": "^1.0.1",
|
|
40
|
+
"@types/pako": "^1.0.2",
|
|
28
41
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
29
42
|
"@typescript-eslint/parser": "^5.0.0",
|
|
30
43
|
"eslint": "^7.32.0",
|
|
31
44
|
"eslint-config-airbnb-base": "^14.2.1",
|
|
45
|
+
"eslint-config-airbnb-typescript": "^14.0.1",
|
|
32
46
|
"eslint-config-prettier": "^8.3.0",
|
|
33
47
|
"eslint-plugin-import": "^2.25.2",
|
|
34
48
|
"eslint-plugin-prettier": "^4.0.0",
|
|
49
|
+
"husky": "^7.0.2",
|
|
35
50
|
"jest": "^27.3.0",
|
|
51
|
+
"lint-staged": "^11.2.3",
|
|
36
52
|
"prettier": "^2.4.1",
|
|
37
53
|
"typedoc": "^0.22.6",
|
|
38
|
-
"typedoc-github-wiki-theme": "^0.6.0",
|
|
39
54
|
"typedoc-plugin-markdown": "^3.11.3",
|
|
40
55
|
"typescript": "^4.4.4"
|
|
41
56
|
},
|
|
42
57
|
"dependencies": {
|
|
43
|
-
"axios": "^0.23.0"
|
|
58
|
+
"axios": "^0.23.0",
|
|
59
|
+
"json-bigint": "^1.0.0",
|
|
60
|
+
"pako": "^2.0.4"
|
|
61
|
+
},
|
|
62
|
+
"lint-staged": {
|
|
63
|
+
"*.ts": "eslint --cache --fix",
|
|
64
|
+
"*.{ts,js,md,yml,json}": "prettier --write"
|
|
65
|
+
},
|
|
66
|
+
"jest": {
|
|
67
|
+
"testTimeout": 20000
|
|
44
68
|
}
|
|
45
69
|
}
|
package/src/constants.ts
ADDED