starknet 3.5.0 → 3.7.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 (79) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/__tests__/account.test.ts +38 -20
  3. package/__tests__/accountContract.test.ts +0 -31
  4. package/__tests__/constancts.ts +2 -0
  5. package/__tests__/contract.test.ts +14 -21
  6. package/__tests__/provider.test.ts +8 -0
  7. package/account/default.d.ts +4 -1
  8. package/account/default.js +63 -14
  9. package/account/interface.d.ts +14 -0
  10. package/contract/default.d.ts +6 -6
  11. package/contract/default.js +28 -13
  12. package/contract/interface.d.ts +4 -4
  13. package/dist/account/default.d.ts +4 -2
  14. package/dist/account/default.js +50 -11
  15. package/dist/account/interface.d.ts +13 -1
  16. package/dist/contract/default.d.ts +6 -6
  17. package/dist/contract/default.js +23 -12
  18. package/dist/contract/interface.d.ts +4 -4
  19. package/dist/provider/default.d.ts +9 -2
  20. package/dist/provider/default.js +16 -11
  21. package/dist/signer/index.d.ts +1 -0
  22. package/dist/signer/index.js +1 -0
  23. package/dist/signer/ledger.d.ts +12 -0
  24. package/dist/signer/ledger.js +138 -0
  25. package/dist/types/api.d.ts +57 -2
  26. package/package.json +5 -2
  27. package/provider/default.d.ts +9 -1
  28. package/provider/default.js +19 -15
  29. package/signer/index.d.ts +1 -0
  30. package/signer/index.js +1 -0
  31. package/signer/ledger.d.ts +15 -0
  32. package/signer/ledger.js +243 -0
  33. package/src/account/default.ts +28 -6
  34. package/src/account/interface.ts +15 -0
  35. package/src/contract/default.ts +33 -28
  36. package/src/contract/interface.ts +4 -4
  37. package/src/provider/default.ts +13 -11
  38. package/src/signer/index.ts +1 -0
  39. package/src/signer/ledger.ts +81 -0
  40. package/src/types/api.ts +62 -3
  41. package/tsconfig.json +1 -10
  42. package/types/api.d.ts +57 -2
  43. package/www/README.md +41 -0
  44. package/www/babel.config.js +3 -0
  45. package/www/code-examples/account.js +62 -0
  46. package/www/code-examples/amm.js +49 -0
  47. package/www/code-examples/erc20.js +10 -0
  48. package/www/code-examples/package-lock.json +336 -0
  49. package/www/code-examples/package.json +15 -0
  50. package/www/docs/API/_category_.json +5 -0
  51. package/www/docs/API/account.md +11 -0
  52. package/www/docs/API/contract.md +14 -0
  53. package/www/docs/API/index.md +4 -0
  54. package/www/docs/API/provider.md +10 -0
  55. package/www/docs/API/signer.md +8 -0
  56. package/www/docusaurus.config.js +131 -0
  57. package/www/guides/account.md +60 -0
  58. package/www/guides/cra.md +3 -0
  59. package/www/guides/erc20.md +88 -0
  60. package/www/guides/intro.md +20 -0
  61. package/www/package-lock.json +22285 -0
  62. package/www/package.json +43 -0
  63. package/www/sidebars.js +31 -0
  64. package/www/src/components/HomepageFeatures/index.tsx +67 -0
  65. package/www/src/components/HomepageFeatures/styles.module.css +10 -0
  66. package/www/src/css/custom.css +39 -0
  67. package/www/src/pages/index.module.css +23 -0
  68. package/www/src/pages/index.tsx +40 -0
  69. package/www/src/pages/markdown-page.md +7 -0
  70. package/www/static/.nojekyll +0 -0
  71. package/www/static/img/docusaurus.png +0 -0
  72. package/www/static/img/favicon.ico +0 -0
  73. package/www/static/img/logo.svg +17 -0
  74. package/www/static/img/starknet-1.png +0 -0
  75. package/www/static/img/starknet-2.png +0 -0
  76. package/www/static/img/starknet-3.png +0 -0
  77. package/www/static/img/tutorial/docsVersionDropdown.png +0 -0
  78. package/www/static/img/tutorial/localeDropdown.png +0 -0
  79. package/www/tsconfig.json +8 -0
@@ -0,0 +1,88 @@
1
+ ---
2
+ sidebar_position: 3
3
+ ---
4
+ # Deploy an ERC20 Contract
5
+
6
+ Dpeploy the contract and wait for deployment transaction to be accepted on StarkNet
7
+
8
+ ```javascript
9
+ const compiledErc20 = json.parse(
10
+ fs.readFileSync("./ERC20.json").toString("ascii")
11
+ );
12
+ const erc20Response = await defaultProvider.deployContract({
13
+ contract: compiledErc20,
14
+ });
15
+ console.log("Waiting for Tx to be Accepted on Starknet - ERC20 Deployment...");
16
+ await defaultProvider.waitForTransaction(erc20Response.transaction_hash);
17
+ ```
18
+ ## Get the erc20 contract address and create the contact object
19
+ ```javascript
20
+ const erc20Address = erc20Response.address;
21
+ const erc20 = new Contract(compiledErc20.abi, erc20Address);
22
+ ```
23
+
24
+ ## Mint tokens to an account address
25
+ ```javascript
26
+ const { transaction_hash: mintTxHash } = await erc20.mint(
27
+ accountContract.address,
28
+ "1000"
29
+ );
30
+ console.log(`Waiting for Tx to be Accepted on Starknet - Minting...`);
31
+ await defaultProvider.waitForTransaction(mintTxHash);
32
+ ```
33
+
34
+ ## Check balance after mint
35
+ ```javascript
36
+ console.log(`Calling StarkNet for accountContract balance...`);
37
+ const balanceBeforeTransfer = await erc20.balance_of(accountContract.address);
38
+
39
+ console.log(
40
+ `accountContract Address ${accountContract.address} has a balance of:`,
41
+ number.toBN(balanceBeforeTransfer.res, 16).toString()
42
+ );
43
+ ```
44
+
45
+ ## Transfer tokens
46
+ ```javascript
47
+ // Get the nonce of the account and prepare transfer tx
48
+ console.log(`Calling StarkNet for accountContract nonce...`);
49
+ const nonce = (await accountContract.call("get_nonce")).nonce.toString();
50
+ const calls = [
51
+ {
52
+ contractAddress: erc20Address,
53
+ entrypoint: "transfer",
54
+ calldata: [erc20Address, "10"],
55
+ },
56
+ ];
57
+ const msgHash = hash.hashMulticall(accountContract.address, calls, nonce, "0");
58
+
59
+ const { callArray, calldata } = transformCallsToMulticallArrays(calls);
60
+
61
+ // sign tx to transfer 10 tokens
62
+ const signature = ec.sign(starkKeyPair, msgHash);
63
+
64
+ // Execute tx transfer of 10 tokens
65
+ console.log(`Invoke Tx - Transfer 10 tokens back to erc20 contract...`);
66
+ const { transaction_hash: transferTxHash } = await accountContract.__execute__(
67
+ callArray,
68
+ calldata,
69
+ nonce,
70
+ signature
71
+ );
72
+
73
+ // Wait for the invoke transaction to be accepted on StarkNet
74
+ console.log(`Waiting for Tx to be Accepted on Starknet - Transfer...`);
75
+ await defaultProvider.waitForTransaction(transferTxHash);
76
+ ```
77
+
78
+ ## Check balance after transfer
79
+ ```javascript
80
+ // Check balance after transfer - should be 990
81
+ console.log(`Calling StarkNet for accountContract balance...`);
82
+ const balanceAfterTransfer = await erc20.balance_of(accountContract.address);
83
+
84
+ console.log(
85
+ `accountContract Address ${accountContract.address} has a balance of:`,
86
+ number.toBN(balanceAfterTransfer.res, 16).toString()
87
+ );
88
+ ```
@@ -0,0 +1,20 @@
1
+ ---
2
+ sidebar_position: 1
3
+ ---
4
+
5
+ # Getting Started
6
+
7
+ ```bash
8
+ npm install starknet
9
+
10
+ # to use latest features
11
+
12
+ npm install starknet@next
13
+ ```
14
+
15
+ ## Compiling StarkNet Contracts
16
+
17
+ Please check the StarkNet documentation <ins>[here](https://www.cairo-lang.org/docs/hello_starknet/intro.html)</ins> to compile starknet contracts.
18
+
19
+ ## Full example with account & erc20
20
+ Please see workshop <ins>[here](https://github.com/0xs34n/starknet.js-workshop)</ins>