starknet 4.17.0 → 4.18.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.
Files changed (150) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +2 -10
  3. package/dist/index.d.ts +27 -9
  4. package/dist/index.global.js +30 -13
  5. package/dist/index.global.js.map +1 -1
  6. package/dist/index.js +30 -13
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +30 -13
  9. package/dist/index.mjs.map +1 -1
  10. package/package.json +5 -1
  11. package/.babelrc +0 -6
  12. package/.commitlintrc +0 -22
  13. package/.eslintignore +0 -2
  14. package/.eslintrc +0 -28
  15. package/.prettierrc +0 -6
  16. package/.releaserc +0 -28
  17. package/CODE_OF_CONDUCT.md +0 -128
  18. package/CONTRIBUTING.md +0 -52
  19. package/__mocks__/Account.json +0 -25486
  20. package/__mocks__/ERC20.json +0 -40027
  21. package/__mocks__/TestDapp.json +0 -12962
  22. package/__mocks__/contract.json +0 -33191
  23. package/__mocks__/l1l2_compiled.json +0 -10107
  24. package/__mocks__/multicall.json +0 -8139
  25. package/__mocks__/naming_compiled.json +0 -53283
  26. package/__mocks__/starknetId_compiled.json +0 -44703
  27. package/__mocks__/typedDataExample.json +0 -35
  28. package/__mocks__/typedDataSessionExample.json +0 -42
  29. package/__mocks__/typedDataStructArrayExample.json +0 -44
  30. package/__tests__/account.test.ts +0 -345
  31. package/__tests__/contract.test.ts +0 -249
  32. package/__tests__/defaultProvider.test.ts +0 -177
  33. package/__tests__/fixtures.ts +0 -84
  34. package/__tests__/jest.setup.ts +0 -30
  35. package/__tests__/rpcProvider.test.ts +0 -132
  36. package/__tests__/sequencerProvider.test.ts +0 -123
  37. package/__tests__/utils/__snapshots__/ellipticalCurve.test.ts.snap +0 -5
  38. package/__tests__/utils/__snapshots__/utils.browser.test.ts.snap +0 -5
  39. package/__tests__/utils/__snapshots__/utils.test.ts.snap +0 -5
  40. package/__tests__/utils/address.test.ts +0 -45
  41. package/__tests__/utils/ellipticalCurve.test.ts +0 -91
  42. package/__tests__/utils/merkle.test.ts +0 -256
  43. package/__tests__/utils/shortString.test.ts +0 -22
  44. package/__tests__/utils/starknetId.test.ts +0 -53
  45. package/__tests__/utils/transactionHash.test.ts +0 -17
  46. package/__tests__/utils/typedData.test.ts +0 -223
  47. package/__tests__/utils/uint256.test.ts +0 -32
  48. package/__tests__/utils/utils.browser.test.ts +0 -29
  49. package/__tests__/utils/utils.test.ts +0 -141
  50. package/img/logo.svg +0 -17
  51. package/index.d.ts +0 -2683
  52. package/index.global.js +0 -23192
  53. package/index.global.js.map +0 -1
  54. package/index.js +0 -4910
  55. package/index.js.map +0 -1
  56. package/index.mjs +0 -4852
  57. package/index.mjs.map +0 -1
  58. package/src/account/default.ts +0 -501
  59. package/src/account/index.ts +0 -2
  60. package/src/account/interface.ts +0 -309
  61. package/src/constants.ts +0 -2065
  62. package/src/contract/contractFactory.ts +0 -88
  63. package/src/contract/default.ts +0 -425
  64. package/src/contract/index.ts +0 -3
  65. package/src/contract/interface.ts +0 -106
  66. package/src/index.ts +0 -26
  67. package/src/provider/default.ts +0 -187
  68. package/src/provider/errors.ts +0 -14
  69. package/src/provider/index.ts +0 -9
  70. package/src/provider/interface.ts +0 -281
  71. package/src/provider/rpc.ts +0 -482
  72. package/src/provider/sequencer.ts +0 -523
  73. package/src/provider/utils.ts +0 -100
  74. package/src/signer/default.ts +0 -99
  75. package/src/signer/index.ts +0 -2
  76. package/src/signer/interface.ts +0 -77
  77. package/src/types/account.ts +0 -43
  78. package/src/types/api/index.ts +0 -10
  79. package/src/types/api/openrpc.ts +0 -607
  80. package/src/types/api/rpc.ts +0 -45
  81. package/src/types/api/sequencer.ts +0 -369
  82. package/src/types/contract.ts +0 -5
  83. package/src/types/index.ts +0 -8
  84. package/src/types/lib.ts +0 -143
  85. package/src/types/provider.ts +0 -134
  86. package/src/types/signer.ts +0 -24
  87. package/src/utils/address.ts +0 -44
  88. package/src/utils/calldata.ts +0 -250
  89. package/src/utils/ellipticCurve.ts +0 -120
  90. package/src/utils/encode.ts +0 -66
  91. package/src/utils/events.ts +0 -32
  92. package/src/utils/fetchPonyfill.ts +0 -5
  93. package/src/utils/hash.ts +0 -235
  94. package/src/utils/json.ts +0 -15
  95. package/src/utils/merkle.ts +0 -69
  96. package/src/utils/number.ts +0 -98
  97. package/src/utils/provider.ts +0 -28
  98. package/src/utils/responseParser/index.ts +0 -28
  99. package/src/utils/responseParser/rpc.ts +0 -70
  100. package/src/utils/responseParser/sequencer.ts +0 -135
  101. package/src/utils/shortString.ts +0 -21
  102. package/src/utils/stark.ts +0 -57
  103. package/src/utils/starknetId.ts +0 -116
  104. package/src/utils/transaction.ts +0 -56
  105. package/src/utils/typedData/index.ts +0 -247
  106. package/src/utils/typedData/types.ts +0 -37
  107. package/src/utils/typedData/utils.ts +0 -16
  108. package/src/utils/uint256.ts +0 -32
  109. package/src/utils/url.ts +0 -53
  110. package/tsconfig.eslint.json +0 -4
  111. package/tsup.config.ts +0 -9
  112. package/www/README.md +0 -41
  113. package/www/babel.config.js +0 -3
  114. package/www/code-examples/account.js +0 -65
  115. package/www/code-examples/amm.js +0 -44
  116. package/www/code-examples/erc20.js +0 -13
  117. package/www/code-examples/package-lock.json +0 -336
  118. package/www/code-examples/package.json +0 -15
  119. package/www/docs/API/_category_.json +0 -5
  120. package/www/docs/API/account.md +0 -463
  121. package/www/docs/API/changelog.md +0 -15
  122. package/www/docs/API/contract.md +0 -135
  123. package/www/docs/API/contractFactory.md +0 -45
  124. package/www/docs/API/index.md +0 -3
  125. package/www/docs/API/provider.md +0 -725
  126. package/www/docs/API/signer.md +0 -105
  127. package/www/docs/API/utils.md +0 -374
  128. package/www/docusaurus.config.js +0 -130
  129. package/www/guides/account.md +0 -140
  130. package/www/guides/cra.md +0 -3
  131. package/www/guides/erc20.md +0 -163
  132. package/www/guides/intro.md +0 -63
  133. package/www/package-lock.json +0 -20405
  134. package/www/package.json +0 -43
  135. package/www/sidebars.js +0 -31
  136. package/www/src/components/HomepageFeatures/index.tsx +0 -67
  137. package/www/src/components/HomepageFeatures/styles.module.css +0 -10
  138. package/www/src/css/custom.css +0 -39
  139. package/www/src/pages/index.module.css +0 -23
  140. package/www/src/pages/index.tsx +0 -40
  141. package/www/src/pages/markdown-page.md +0 -7
  142. package/www/static/.nojekyll +0 -0
  143. package/www/static/img/docusaurus.png +0 -0
  144. package/www/static/img/favicon.ico +0 -0
  145. package/www/static/img/logo.svg +0 -17
  146. package/www/static/img/starknet-1.png +0 -0
  147. package/www/static/img/starknet-2.png +0 -0
  148. package/www/static/img/starknet-3.png +0 -0
  149. package/www/static/img/tutorial/docsVersionDropdown.png +0 -0
  150. package/www/static/img/tutorial/localeDropdown.png +0 -0
@@ -1,140 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- ---
4
-
5
- # Creating an Account
6
-
7
- Since there are no Externally Owned Accounts (EOA) in StarkNet, all Accounts in StarkNet are contracts.
8
-
9
- Unlike in Ethereum where a wallet is created with a public and private key pair, StarkNet Accounts are the only way to sign transactions and messages, and verify signatures. Therefore a Account - Contract interface is needed.
10
-
11
- > Account contracts on StarkNet cannot be deployed without paying a fee.
12
-
13
- High level explanations from StarkWare can be found in this Notion [page](https://starkware.notion.site/Deploy-a-contract-and-an-account-on-StarkNet-ed2fd13301d2414e8223bb72bb90e386), but in short, the process is:
14
-
15
- 1. Decide on your account type (OpenZeppelin, Argent, ...)
16
- 2. Compute the address of our would-be account off-chain (adressess on StarkNet are deterministic)
17
- 3. Send funds to this pre-computed address. The funds will be used to pay for the account contract deployment
18
- 4. Actual deployment of the Account
19
-
20
- ## Install and setup
21
-
22
- Install the latest version of starknet with
23
-
24
- `npm install starknet@next`
25
-
26
- Imports example:
27
-
28
- ```javascript
29
- import fs from "fs";
30
- import {
31
- Account,
32
- Contract,
33
- defaultProvider,
34
- ec,
35
- json,
36
- number,
37
- hash
38
- } from "starknet";
39
- ```
40
-
41
- Starknet.js currently doesn't have the functionality to calculate the class hash needed for the account deployment, so we need to calculate it with some other tool, for example: [Starkli](https://github.com/xJonathanLEI/starkli)
42
-
43
- ```javascript
44
- // class hash of OpenZeppelin Account contract version 0.5.1
45
- const OZContractClassHash = '0x058d97f7d76e78f44905cc30cb65b91ea49a4b908a76703c54197bca90f81773';
46
- ```
47
-
48
- ```javascript
49
- // get the compiled contract ABI, in this case OpenZeppelin
50
- const compiledOZAccount = json.parse(
51
- fs.readFileSync("./Account.json").toString("ascii")
52
- );
53
- ```
54
-
55
- ## Generate random key pair
56
-
57
- ```javascript
58
- const starkKeyPair = ec.genKeyPair();
59
- const starkKeyPub = ec.getStarkKey(starkKeyPair);
60
- ```
61
-
62
- You can also get a key pair from a private key using:
63
-
64
- `getKeyPair(pk: BigNumberish)`
65
-
66
- ```javascript
67
- const privateKey = '0x-Some-Existing-Private-Key'; // you can use stark.randomAddress();
68
- const starkKeyPair = ec.getKeyPair(privateKey);
69
- const starkKeyPub = ec.getStarkKey(starkKeyPair);
70
- ```
71
-
72
- ## Pre-compute address of the Account
73
-
74
- ```javascript
75
- const precalculatedAddress = hash.calculateContractAddressFromHash(
76
- starkKeyPub, // salt
77
- OZContractClassHash,
78
- [starkKeyPub],
79
- 0
80
- );
81
- ```
82
-
83
- ## Funding options for the pre-computed address
84
-
85
- 1. TESTNET
86
-
87
- You can do so by using a faucet: https://faucet.goerli.starknet.io/
88
-
89
- 2. DEVNET
90
-
91
- Address is the newly `precalculatedAddress`.
92
-
93
- ```bash
94
- curl -X POST http://127.0.0.1:5050/mint -d '{"address":"0x04a093c37ab61065d001550089b1089922212c60b34e662bb14f2f91faee2979","amount":50000000000000000000,"lite":true}' -H "Content-Type:application/json"
95
- // {"new_balance":50000000000000000000,"tx_hash":null,"unit":"wei"}
96
- ```
97
-
98
- 3. Send funds from an already existing account
99
-
100
- ## OPTIONAL - Declare Account
101
-
102
- > NOTE: This step will fail if you haven't sent funds to the pre-calculated address.
103
-
104
- We need to use an already deployed account in order to declare ours. StarkNet will always have at least 1 already declared/deployed account for this purpose.
105
-
106
- ```javascript
107
- // In this case we will use the devnet's predeployed OZ account, after you start the devnet with: `starknet-devnet --seed 0`
108
- const devnetPrivateKey = '0xe3e70682c2094cac629f6fbed82c07cd';
109
- const devnetAccount0Address = '0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a';
110
- const devnetKeyPair = ec.getKeyPair(devnetPrivateKey);
111
-
112
- const predeployedAccount = new Account(provider, devnetAccount0Address, devnetKeyPair);
113
-
114
- const declareTx = await predeployedAccount.declare({
115
- classHash: OZContractClassHash,
116
- contract: compiledOZAccount
117
- });
118
-
119
- await provider.waitForTransaction(declareTx.transaction_hash);
120
- ```
121
-
122
- ## Deploy Account Contract
123
-
124
- Deploy the Account contract and wait for it to be verified on StarkNet.
125
-
126
- > NOTE: This step will fail if you haven't sent funds to the pre-calculated address.
127
-
128
- ```javascript
129
- const account = new Account(provider, precalculatedAddress, starkKeyPair);
130
-
131
- // This is OpenZeppelin account contract deployment
132
- const accountResponse = await account.deployAccount({
133
- classHash: OZContractClassHash,
134
- constructorCalldata: [starkKeyPub],
135
- contractAddress: precalculatedAddress,
136
- addressSalt: starkKeyPub
137
- });
138
-
139
- await provider.waitForTransaction(accountResponse.transaction_hash);
140
- ```
package/www/guides/cra.md DELETED
@@ -1,3 +0,0 @@
1
- # Usage with Create React App
2
-
3
- Please refer to this <ins>[GitHub issue](https://github.com/0xs34n/starknet.js/issues/37)</ins>
@@ -1,163 +0,0 @@
1
- ---
2
- sidebar_position: 3
3
- ---
4
-
5
- # Deploy an ERC20 Contract
6
-
7
- Deploying a contract relies on having an account already set up with enough ETH to pay fees for both:
8
-
9
- 1. The class declaration
10
- 2. The transaction interacting with the UDC (universal deployer contract)
11
-
12
- > You must first declare your contract class and only then deploy a new instance of it!
13
-
14
- High level explanations from StarkWare can be found in this Notion [page](https://starkware.notion.site/Deploy-a-contract-and-an-account-on-StarkNet-ed2fd13301d2414e8223bb72bb90e386).
15
-
16
- ERC20 implementations:
17
-
18
- 1. Argent ERC20 contract can be found [here](https://github.com/argentlabs/argent-contracts-starknet/blob/develop/contracts/lib/ERC20.cairo).
19
- 2. OpenZeppelin ERC20 can be found [here](https://github.com/OpenZeppelin/cairo-contracts/tree/main/src/openzeppelin/token/erc20).
20
-
21
- ## Setup
22
-
23
- ```javascript
24
- const compiledErc20 = json.parse(
25
- fs.readFileSync("./ERC20.json").toString("ascii")
26
- );
27
- ```
28
-
29
- ```javascript
30
- // devnet private key from Account #0 if generated with --seed 0
31
- const starkKeyPair = ec.getKeyPair("0xe3e70682c2094cac629f6fbed82c07cd");
32
- const accountAddress = "0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a";
33
-
34
- const recieverAddress = '0x69b49c2cc8b16e80e86bfc5b0614a59aa8c9b601569c7b80dde04d3f3151b79';
35
-
36
- // Starknet.js currently doesn't have the functionality to calculate the class hash
37
- const erc20ClassHash = '0x03f794a28472089a1a99b7969fc51cd5fbe22dd09e3f38d2bd6fa109cb3f4ecf';
38
-
39
- const account = new Account(
40
- provider,
41
- accountAddress,
42
- starkKeyPair
43
- );
44
- ```
45
-
46
- ## Declare contract
47
-
48
- ```javascript
49
- const erc20DeclareResponse = await account.declare({
50
- classHash: erc20ClassHash,
51
- contract: compiledErc20,
52
- });
53
-
54
- await provider.waitForTransaction(erc20DeclareResponse.transaction_hash);
55
- ```
56
-
57
- ## Deploy contract
58
-
59
- ```javascript
60
- const salt = '900080545022'; // use some random salt
61
-
62
- const erc20Response = await account.deploy({
63
- classHash: erc20ClassHash,
64
- constructorCalldata: stark.compileCalldata({
65
- name: shortString.encodeShortString('TestToken'),
66
- symbol: shortString.encodeShortString('ERC20'),
67
- decimals: 18,
68
- initial_supply: ['1000'],
69
- recipient: account.address,
70
- }),
71
- salt,
72
- });
73
-
74
- await provider.waitForTransaction(erc20Response.transaction_hash);
75
-
76
- const txReceipt = await provider.getTransactionReceipt(erc20Response.transaction_hash);
77
- ```
78
-
79
- ## Interact with contracts
80
-
81
- We have 2 options to interact with contracts.
82
-
83
- ### Option 1 - call the contract object
84
-
85
- ```javascript
86
- const erc20 = new Contract(compiledErc20.abi, erc20Address, provider);
87
-
88
- erc20.connect(account);
89
-
90
- const { transaction_hash: mintTxHash } = await erc20.transfer(
91
- recieverAddress,
92
- ['0', '10'], // send 10 tokens as Uint256
93
- );
94
-
95
- await provider.waitForTransaction(mintTxHash);
96
- ```
97
-
98
- ### Option 2 - call contract from Account
99
-
100
- ```javascript
101
- const executeHash = await account.execute(
102
- {
103
- contractAddress: erc20Address,
104
- entrypoint: 'transfer',
105
- calldata: stark.compileCalldata({
106
- recipient: recieverAddress,
107
- amount: ['10']
108
- })
109
- }
110
- );
111
-
112
- await provider.waitForTransaction(executeHash.transaction_hash);
113
- ```
114
-
115
- ## Check the balance
116
-
117
- ```javascript
118
- const balanceBeforeTransfer = await erc20.balanceOf(account.address);
119
-
120
- console.log(
121
- `account Address ${account.address} has a balance of:`,
122
- number.toBN(balanceBeforeTransfer[0].high).toString()
123
- );
124
- ```
125
-
126
- ## Convenience Methods
127
-
128
- ### deployContract convenience method
129
-
130
- High level wrapper for deploy. Doesn't require `waitForTransaction`. Response similar to deprecated `provider.deployContract`.
131
-
132
- Convenient also to get the address of the deployed contract in the same response - easier than using the `deploy` already mentioned in the guide.
133
-
134
- ```typescript
135
- const deployResponse = await account.deployContract({
136
- classHash: erc20ClassHash,
137
- constructorCalldata: [
138
- encodeShortString('Token'),
139
- encodeShortString('ERC20'),
140
- account.address,
141
- ],
142
- });
143
- ```
144
-
145
- ### declareDeploy convenience method
146
-
147
- High level wrapper for declare & deploy. Doesn't require `waitForTransaction`. Functionality similar to deprecated `provider.deployContract`.
148
-
149
- Declare and Deploy contract using single function:
150
-
151
- ```typescript
152
- const declareDeploy = await account.declareDeploy({
153
- contract: compiledErc20,
154
- classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
155
- constructorCalldata: [
156
- encodeShortString('Token'),
157
- encodeShortString('ERC20'),
158
- account.address,
159
- ],
160
- });
161
- const declareTransactionHash = declareDeploy.declare.transaction_hash
162
- const erc20Address = declareDeploy.deploy.contract_address;
163
- ```
@@ -1,63 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- ---
4
-
5
- # Getting Started
6
-
7
- ## Installation
8
-
9
- ```bash
10
-
11
- # use the main branch
12
-
13
- npm install starknet
14
-
15
- # to use latest features (merges in develop branch)
16
-
17
- npm install starknet@next
18
- ```
19
-
20
- ## Running test locally
21
-
22
- ### With Devnet
23
-
24
- Example devnet version is `0.4.2`.
25
-
26
- Get devnet with docker:
27
-
28
- ```bash
29
- docker pull shardlabs/starknet-devnet:0.4.2
30
- docker run -p 5050:5050 shardlabs/starknet-devnet:0.4.2 --seed 0
31
- ```
32
-
33
- Open new console tab, go to your starknet.js directory and run:
34
-
35
- ```bash
36
- npm run test # all tests
37
- npm run test ./__tests__/contract.test.ts # just one test suite
38
- ```
39
-
40
- By default `defaultProvider` tests will be ran through the `Sequencer`.
41
-
42
- If you want to run `defaultProvider` through the `RPC` run:
43
-
44
- ```bash
45
- export TEST_RPC_URL = "http://127.0.0.1:5050/rpc"
46
-
47
- # only RPC related tests:
48
- npm run test ./__tests__/rpcProvider.test.ts
49
- ```
50
-
51
- ## Compiling StarkNet Contracts
52
-
53
- Please check the StarkNet documentation <ins>[here](https://www.cairo-lang.org/docs/hello_starknet/intro.html)</ins> to compile starknet contracts.
54
-
55
- Additional helpful resources can also be found at <ins>[OpenZeppelin](https://docs.openzeppelin.com/contracts-cairo/0.5.0/)</ins> documentation site.
56
-
57
- Get the class hash of a contract: [starkli](https://github.com/xJonathanLEI/starkli).
58
-
59
- ## Full example with account & erc20 deployments
60
-
61
- Please take a look at our workshop using OpenZeppelin contracts <ins>[here](https://github.com/0xs34n/starknet.js-workshop)</ins>.
62
-
63
- Example with Argent contract <ins>[here](https://github.com/0xs34n/starknet.js-account)</ins>.