starknet 3.5.1 → 3.6.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 +18 -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 +2 -0
- package/account/default.js +60 -12
- package/account/interface.d.ts +14 -0
- package/contract/default.d.ts +1 -1
- package/contract/default.js +27 -11
- package/dist/account/default.d.ts +2 -1
- package/dist/account/default.js +47 -9
- package/dist/account/interface.d.ts +13 -1
- package/dist/contract/default.d.ts +1 -1
- package/dist/contract/default.js +22 -10
- 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 +25 -4
- package/src/account/interface.ts +15 -0
- package/src/contract/default.ts +23 -22
- 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,131 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Note: type annotations allow type checking and IDEs autocompletion
|
|
3
|
+
|
|
4
|
+
const lightCodeTheme = require('prism-react-renderer/themes/github');
|
|
5
|
+
const darkCodeTheme = require('prism-react-renderer/themes/dracula');
|
|
6
|
+
|
|
7
|
+
/** @type {import('@docusaurus/types').Config} */
|
|
8
|
+
const config = {
|
|
9
|
+
title: 'Starknet.js',
|
|
10
|
+
tagline: 'JavaScript libray for StarkNet',
|
|
11
|
+
url: 'https://starknetjs.com',
|
|
12
|
+
baseUrl: '/',
|
|
13
|
+
onBrokenLinks: 'throw',
|
|
14
|
+
onBrokenMarkdownLinks: 'warn',
|
|
15
|
+
favicon: 'img/favicon.ico',
|
|
16
|
+
organizationName: '0xs34n', // Usually your GitHub org/user name.
|
|
17
|
+
projectName: 'starknet.js', // Usually your repo name.
|
|
18
|
+
|
|
19
|
+
plugins: [
|
|
20
|
+
[
|
|
21
|
+
'@docusaurus/plugin-content-docs',
|
|
22
|
+
{
|
|
23
|
+
id: 'guides',
|
|
24
|
+
path: 'guides',
|
|
25
|
+
routeBasePath: 'guides',
|
|
26
|
+
sidebarPath: require.resolve('./sidebars.js'),
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
],
|
|
30
|
+
|
|
31
|
+
presets: [
|
|
32
|
+
[
|
|
33
|
+
'classic',
|
|
34
|
+
/** @type {import('@docusaurus/preset-classic').Options} */
|
|
35
|
+
({
|
|
36
|
+
docs: {
|
|
37
|
+
sidebarPath: require.resolve('./sidebars.js'),
|
|
38
|
+
// Please change this to your repo.
|
|
39
|
+
editUrl: 'https://github.com/0xs34n/starknet.js',
|
|
40
|
+
},
|
|
41
|
+
blog: {
|
|
42
|
+
showReadingTime: true,
|
|
43
|
+
// Please change this to your repo.
|
|
44
|
+
editUrl:
|
|
45
|
+
'https://github.com/0xs34n/starknet.js',
|
|
46
|
+
},
|
|
47
|
+
theme: {
|
|
48
|
+
customCss: require.resolve('./src/css/custom.css'),
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
],
|
|
52
|
+
],
|
|
53
|
+
|
|
54
|
+
themeConfig:
|
|
55
|
+
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
|
|
56
|
+
({
|
|
57
|
+
navbar: {
|
|
58
|
+
title: 'Home',
|
|
59
|
+
logo: {
|
|
60
|
+
alt: 'Starknet.js Logo',
|
|
61
|
+
src: 'img/logo.svg',
|
|
62
|
+
},
|
|
63
|
+
items: [
|
|
64
|
+
{
|
|
65
|
+
type: 'doc',
|
|
66
|
+
docId: 'API/index',
|
|
67
|
+
position: 'left',
|
|
68
|
+
label: 'API',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
position: 'left',
|
|
72
|
+
label: 'Guides',
|
|
73
|
+
to: '/guides/intro'
|
|
74
|
+
},
|
|
75
|
+
// {to: '/blog', label: 'Blog', position: 'left'},
|
|
76
|
+
{
|
|
77
|
+
href: 'https://github.com/facebook/docusaurus',
|
|
78
|
+
label: 'GitHub',
|
|
79
|
+
position: 'right',
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
footer: {
|
|
84
|
+
style: 'dark',
|
|
85
|
+
links: [
|
|
86
|
+
{
|
|
87
|
+
title: 'Docs',
|
|
88
|
+
items: [
|
|
89
|
+
{
|
|
90
|
+
label: 'API',
|
|
91
|
+
to: '/docs/API/',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
label: 'Guides',
|
|
95
|
+
to: '/guides/intro',
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
title: 'Community',
|
|
101
|
+
items: [
|
|
102
|
+
{
|
|
103
|
+
label: 'Twitter',
|
|
104
|
+
href: 'https://twitter.com/0xs34n',
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
title: 'More',
|
|
110
|
+
items: [
|
|
111
|
+
// {
|
|
112
|
+
// label: 'Blog',
|
|
113
|
+
// to: '/blog',
|
|
114
|
+
// },
|
|
115
|
+
{
|
|
116
|
+
label: 'GitHub',
|
|
117
|
+
href: 'https://github.com/0xs34n/starknet.js',
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
copyright: `Copyright © ${new Date().getFullYear()} 0xs34n`,
|
|
123
|
+
},
|
|
124
|
+
prism: {
|
|
125
|
+
theme: lightCodeTheme,
|
|
126
|
+
darkTheme: darkCodeTheme,
|
|
127
|
+
},
|
|
128
|
+
}),
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
module.exports = config;
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
## Install and import StarkNet
|
|
12
|
+
|
|
13
|
+
Install the latest version of starknet with `npm install starknet@next`
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import fs from "fs";
|
|
17
|
+
import * as starknet from "starknet";
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Generate random key pair.
|
|
21
|
+
|
|
22
|
+
You can also get a key pair from a private key using `getKeyPair(pk: BigNumberish)`
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
const starkKeyPair = ec.genKeyPair();
|
|
26
|
+
const starkKeyPub = ec.getStarkKey(starkKeyPair);;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Deploy Account Contract
|
|
30
|
+
|
|
31
|
+
Deploy the Account contract and wait for it to be verified on StarkNet.
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
const compiledArgentAccount = json.parse(
|
|
35
|
+
fs.readFileSync("./ArgentAccount.json").toString("ascii")
|
|
36
|
+
);
|
|
37
|
+
const accountResponse = await defaultProvider.deployContract({
|
|
38
|
+
contract: compiledArgentAccount,
|
|
39
|
+
addressSalt: starkKeyPub,
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Use your new account
|
|
44
|
+
|
|
45
|
+
Wait for the deployment transaction to be accepted and assign the address of the deployed account to the Account object.
|
|
46
|
+
|
|
47
|
+
Use your new account object to sign transactions, messages or verify signatures!
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
await defaultProvider.waitForTransaction(accountResponse.transaction_hash);
|
|
51
|
+
const accountContract = new Contract(
|
|
52
|
+
compiledArgentAccount.abi,
|
|
53
|
+
accountResponse.address
|
|
54
|
+
);
|
|
55
|
+
const { transaction_hash: initializeTxHash } = await accountContract.initialize(
|
|
56
|
+
starkKeyPub,
|
|
57
|
+
"0"
|
|
58
|
+
);
|
|
59
|
+
await defaultProvider.waitForTransaction(initializeTxHash);
|
|
60
|
+
```
|
|
@@ -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>
|