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.
- package/CHANGELOG.md +33 -0
- package/__tests__/account.test.ts +38 -20
- package/__tests__/accountContract.test.ts +0 -31
- package/__tests__/constancts.ts +2 -0
- package/__tests__/contract.test.ts +14 -21
- package/__tests__/provider.test.ts +8 -0
- package/account/default.d.ts +4 -1
- package/account/default.js +63 -14
- package/account/interface.d.ts +14 -0
- package/contract/default.d.ts +6 -6
- package/contract/default.js +28 -13
- package/contract/interface.d.ts +4 -4
- package/dist/account/default.d.ts +4 -2
- package/dist/account/default.js +50 -11
- package/dist/account/interface.d.ts +13 -1
- package/dist/contract/default.d.ts +6 -6
- package/dist/contract/default.js +23 -12
- package/dist/contract/interface.d.ts +4 -4
- package/dist/provider/default.d.ts +9 -2
- package/dist/provider/default.js +16 -11
- package/dist/signer/index.d.ts +1 -0
- package/dist/signer/index.js +1 -0
- package/dist/signer/ledger.d.ts +12 -0
- package/dist/signer/ledger.js +138 -0
- package/dist/types/api.d.ts +57 -2
- package/package.json +5 -2
- package/provider/default.d.ts +9 -1
- package/provider/default.js +19 -15
- package/signer/index.d.ts +1 -0
- package/signer/index.js +1 -0
- package/signer/ledger.d.ts +15 -0
- package/signer/ledger.js +243 -0
- package/src/account/default.ts +28 -6
- package/src/account/interface.ts +15 -0
- package/src/contract/default.ts +33 -28
- package/src/contract/interface.ts +4 -4
- package/src/provider/default.ts +13 -11
- package/src/signer/index.ts +1 -0
- package/src/signer/ledger.ts +81 -0
- package/src/types/api.ts +62 -3
- package/tsconfig.json +1 -10
- package/types/api.d.ts +57 -2
- package/www/README.md +41 -0
- package/www/babel.config.js +3 -0
- package/www/code-examples/account.js +62 -0
- package/www/code-examples/amm.js +49 -0
- package/www/code-examples/erc20.js +10 -0
- package/www/code-examples/package-lock.json +336 -0
- package/www/code-examples/package.json +15 -0
- package/www/docs/API/_category_.json +5 -0
- package/www/docs/API/account.md +11 -0
- package/www/docs/API/contract.md +14 -0
- package/www/docs/API/index.md +4 -0
- package/www/docs/API/provider.md +10 -0
- package/www/docs/API/signer.md +8 -0
- package/www/docusaurus.config.js +131 -0
- package/www/guides/account.md +60 -0
- package/www/guides/cra.md +3 -0
- package/www/guides/erc20.md +88 -0
- package/www/guides/intro.md +20 -0
- package/www/package-lock.json +22285 -0
- package/www/package.json +43 -0
- package/www/sidebars.js +31 -0
- package/www/src/components/HomepageFeatures/index.tsx +67 -0
- package/www/src/components/HomepageFeatures/styles.module.css +10 -0
- package/www/src/css/custom.css +39 -0
- package/www/src/pages/index.module.css +23 -0
- package/www/src/pages/index.tsx +40 -0
- package/www/src/pages/markdown-page.md +7 -0
- package/www/static/.nojekyll +0 -0
- package/www/static/img/docusaurus.png +0 -0
- package/www/static/img/favicon.ico +0 -0
- package/www/static/img/logo.svg +17 -0
- package/www/static/img/starknet-1.png +0 -0
- package/www/static/img/starknet-2.png +0 -0
- package/www/static/img/starknet-3.png +0 -0
- package/www/static/img/tutorial/docsVersionDropdown.png +0 -0
- package/www/static/img/tutorial/localeDropdown.png +0 -0
- 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>
|