starknet 4.2.0 → 4.4.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 (102) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/__mocks__/typedDataSessionExample.json +42 -0
  3. package/__tests__/defaultProvider.test.ts +11 -24
  4. package/__tests__/rpcProvider.test.ts +3 -3
  5. package/__tests__/sequencerProvider.test.ts +40 -2
  6. package/__tests__/utils/__snapshots__/ellipticalCurve.test.ts.snap +2 -0
  7. package/__tests__/utils/ellipticalCurve.test.ts +5 -0
  8. package/__tests__/utils/merkle.test.ts +146 -0
  9. package/__tests__/utils/typedData.test.ts +107 -9
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.js +3 -1
  12. package/dist/provider/default.d.ts +2 -2
  13. package/dist/provider/default.js +3 -3
  14. package/dist/provider/interface.d.ts +6 -3
  15. package/dist/provider/rpc.d.ts +9 -4
  16. package/dist/provider/rpc.js +67 -25
  17. package/dist/provider/sequencer.d.ts +2 -2
  18. package/dist/provider/sequencer.js +9 -9
  19. package/dist/provider/utils.d.ts +12 -0
  20. package/dist/provider/utils.js +17 -1
  21. package/dist/signer/default.d.ts +1 -1
  22. package/dist/signer/default.js +1 -0
  23. package/dist/types/api/openrpc.d.ts +151 -0
  24. package/dist/types/api/openrpc.js +9 -0
  25. package/dist/types/api/rpc.d.ts +22 -43
  26. package/dist/types/provider.d.ts +5 -5
  27. package/dist/utils/ellipticCurve.d.ts +13 -0
  28. package/dist/utils/ellipticCurve.js +20 -16
  29. package/dist/utils/hash.js +8 -6
  30. package/dist/utils/merkle.d.ts +10 -0
  31. package/dist/utils/merkle.js +90 -0
  32. package/dist/utils/number.js +1 -1
  33. package/dist/utils/responseParser/rpc.d.ts +13 -3
  34. package/dist/utils/responseParser/rpc.js +2 -10
  35. package/dist/utils/responseParser/sequencer.d.ts +4 -1
  36. package/dist/utils/responseParser/sequencer.js +1 -7
  37. package/dist/utils/typedData/index.d.ts +23 -8
  38. package/dist/utils/typedData/index.js +70 -31
  39. package/dist/utils/typedData/types.d.ts +8 -3
  40. package/dist/utils/url.d.ts +7 -0
  41. package/dist/utils/url.js +49 -0
  42. package/index.d.ts +2 -0
  43. package/index.js +3 -1
  44. package/package.json +1 -1
  45. package/provider/default.d.ts +2 -2
  46. package/provider/default.js +3 -3
  47. package/provider/interface.d.ts +6 -3
  48. package/provider/rpc.d.ts +9 -4
  49. package/provider/rpc.js +67 -25
  50. package/provider/sequencer.d.ts +2 -2
  51. package/provider/sequencer.js +9 -9
  52. package/provider/utils.d.ts +12 -0
  53. package/provider/utils.js +17 -1
  54. package/signer/default.d.ts +1 -1
  55. package/signer/default.js +1 -0
  56. package/src/index.ts +2 -0
  57. package/src/provider/default.ts +2 -3
  58. package/src/provider/interface.ts +5 -3
  59. package/src/provider/rpc.ts +56 -34
  60. package/src/provider/sequencer.ts +11 -9
  61. package/src/provider/utils.ts +22 -1
  62. package/src/signer/default.ts +2 -2
  63. package/src/types/api/openrpc.ts +168 -0
  64. package/src/types/api/rpc.ts +22 -45
  65. package/src/types/provider.ts +5 -5
  66. package/src/utils/ellipticCurve.ts +20 -16
  67. package/src/utils/hash.ts +8 -6
  68. package/src/utils/merkle.ts +70 -0
  69. package/src/utils/number.ts +1 -1
  70. package/src/utils/responseParser/rpc.ts +16 -13
  71. package/src/utils/responseParser/sequencer.ts +5 -8
  72. package/src/utils/typedData/index.ts +88 -34
  73. package/src/utils/typedData/types.ts +12 -4
  74. package/src/utils/url.ts +53 -0
  75. package/types/api/openrpc.d.ts +151 -0
  76. package/types/api/openrpc.js +9 -0
  77. package/types/api/rpc.d.ts +22 -43
  78. package/types/provider.d.ts +5 -5
  79. package/utils/ellipticCurve.d.ts +13 -0
  80. package/utils/ellipticCurve.js +20 -16
  81. package/utils/hash.js +8 -6
  82. package/utils/merkle.d.ts +10 -0
  83. package/utils/merkle.js +90 -0
  84. package/utils/number.js +1 -1
  85. package/utils/responseParser/rpc.d.ts +13 -3
  86. package/utils/responseParser/rpc.js +2 -10
  87. package/utils/responseParser/sequencer.d.ts +4 -1
  88. package/utils/responseParser/sequencer.js +1 -7
  89. package/utils/typedData/index.d.ts +23 -8
  90. package/utils/typedData/index.js +70 -31
  91. package/utils/typedData/types.d.ts +8 -3
  92. package/utils/url.d.ts +7 -0
  93. package/utils/url.js +49 -0
  94. package/www/docs/API/account.md +20 -18
  95. package/www/docs/API/contract.md +10 -10
  96. package/www/docs/API/contractFactory.md +14 -11
  97. package/www/docs/API/provider.md +60 -37
  98. package/www/docs/API/signer.md +8 -10
  99. package/www/docs/API/utils.md +151 -74
  100. package/www/guides/account.md +12 -12
  101. package/www/guides/erc20.md +19 -4
  102. package/www/guides/intro.md +3 -1
@@ -43,9 +43,9 @@ const compiledAccount = json.parse(
43
43
  );
44
44
  ```
45
45
 
46
- > **Note**
47
- >
48
- > below example uses [Argent's](https://github.com/argentlabs/argent-contracts-starknet/blob/develop/contracts/ArgentAccount.cairo) account contract
46
+ > **Note**
47
+ >
48
+ > below example uses [Argent's](https://github.com/argentlabs/argent-contracts-starknet/blob/develop/contracts/ArgentAccount.cairo) account contract
49
49
 
50
50
  ```javascript
51
51
  const accountResponse = await defaultProvider.deployContract({
@@ -54,9 +54,9 @@ const accountResponse = await defaultProvider.deployContract({
54
54
  });
55
55
  ```
56
56
 
57
- > **Note**
58
- >
59
- > below example uses [OpenZeppelin's](https://github.com/OpenZeppelin/cairo-contracts/blob/main/src/openzeppelin/account/presets/Account.cairo) account contract
57
+ > **Note**
58
+ >
59
+ > below example uses [OpenZeppelin's](https://github.com/OpenZeppelin/cairo-contracts/blob/main/src/openzeppelin/account/presets/Account.cairo) account contract
60
60
 
61
61
  ```javascript
62
62
  const accountResponse = await defaultProvider.deployContract({
@@ -74,16 +74,16 @@ Wait for the deployment transaction to be accepted and assign the address of the
74
74
  await defaultProvider.waitForTransaction(accountResponse.transaction_hash);
75
75
  ```
76
76
 
77
- 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!
78
-
79
- > **Note**
80
- >
81
- > Make sure your Account has enough funds to execute invocations. Use this [faucet](https://faucet.goerli.starknet.io/) for funding on testnet.
77
+ 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!
82
78
 
83
79
  ```js
84
80
  const account = new Account(
85
81
  defaultProvider,
86
- accountResponse.address,
82
+ accountResponse.contract_address,
87
83
  starkKeyPair
88
84
  );
89
85
  ```
86
+
87
+ ## Fund your new account!
88
+
89
+ Make sure your Account has enough funds to execute invocations. Use this [faucet](https://faucet.goerli.starknet.io/) for funding on testnet.
@@ -20,26 +20,41 @@ await defaultProvider.waitForTransaction(erc20Response.transaction_hash);
20
20
  ## Get the erc20 contract address and create the contact object
21
21
 
22
22
  ```javascript
23
- const erc20Address = erc20Response.address;
24
- const erc20 = new Contract(compiledErc20.abi, erc20Address);
23
+ const erc20Address = erc20Response.contract_address;
24
+ const erc20 = new Contract(compiledErc20.abi, erc20Address, defaultProvider);
25
25
  ```
26
26
 
27
27
  ## Mint tokens to an account address
28
28
 
29
29
  Make sure you created the `Account` instance following the [Creating an Account](./account.md) guide.
30
30
 
31
+ Also make sure you added funds to your account!
32
+
31
33
  ```javascript
32
34
  erc20.connect(account);
33
35
 
34
36
  const { transaction_hash: mintTxHash } = await erc20.mint(
35
37
  account.address,
36
- "1000"
38
+ "1000",
39
+ {
40
+ maxFee: "1"
41
+ }
37
42
  );
38
43
 
39
44
  console.log(`Waiting for Tx to be Accepted on Starknet - Minting...`);
40
45
  await defaultProvider.waitForTransaction(mintTxHash);
41
46
  ```
42
47
 
48
+ > **Note**
49
+ >
50
+ > Transaction can be rejected if `maxFee` is lower than actual.
51
+ >
52
+ > _Error: REJECTED: FEE_TRANSFER_FAILURE_
53
+ >
54
+ > _Actual fee exceeded max fee._
55
+ >
56
+ > If this occurs, set `maxFee` to a higher value, for example: 999999995330000
57
+
43
58
  ## Check balance after mint
44
59
 
45
60
  ```javascript
@@ -64,7 +79,7 @@ const { transaction_hash: transferTxHash } = await account.execute(
64
79
  calldata: [erc20Address, "10"],
65
80
  },
66
81
  undefined,
67
- { maxFee: "0" }
82
+ { maxFee: "1" }
68
83
  );
69
84
 
70
85
  // Wait for the invoke transaction to be accepted on StarkNet
@@ -16,6 +16,8 @@ npm install starknet@next
16
16
 
17
17
  Please check the StarkNet documentation <ins>[here](https://www.cairo-lang.org/docs/hello_starknet/intro.html)</ins> to compile starknet contracts.
18
18
 
19
+ Additional helpful resources can also be found at [OpenZeppelin](https://docs.openzeppelin.com/contracts-cairo/0.3.1/) documentation site.
20
+
19
21
  ## Full example with account & erc20
20
22
 
21
- Please see workshop <ins>[here](https://github.com/0xs34n/starknet.js-workshop)</ins>
23
+ Please take a look at our workshop <ins>[here](https://github.com/0xs34n/starknet.js-workshop)</ins>.