You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: wallet/how-to/use-non-evm-networks/starknet/connect-to-starknet.md
+38-28Lines changed: 38 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,12 @@ This library simplifies the process of connecting to the Starknet Snap, allowing
22
22
23
23
## Connect using `get-starknet`
24
24
25
+
:::note
26
+
27
+
We recommend using the `get-starknet method for most uses.
28
+
29
+
:::
30
+
25
31
### 1. Add `get-starknet` to your project
26
32
27
33
Add the [`get-starknet`](https://github.com/starknet-io/get-starknet)`version 3.3.0` library and the version `6.11.0` of the `starknet.js` library to your project's dependencies:
@@ -46,11 +52,10 @@ Add the [`get-starknet`](https://github.com/starknet-io/get-starknet) `version 3
46
52
47
53
### 2. Connect to the Snap
48
54
49
-
Create a new file named `WalletConnectButton.js` in your project's `src/components` folder. Create this folder if it doesn't exist. Add the following code to the file:.
@@ -110,7 +115,7 @@ To connect to Starknet, the dapp user must ensure the [Starknet Snap](https://sn
110
115
111
116
### 3. Start the dapp
112
117
113
-
Start the dapp, which allow users to click **Connect Wallet** and interact with the Starknet network using MetaMask:
118
+
Start the dapp, which allows users to select **Connect Wallet** and interact with the Starknet network using MetaMask:
114
119
115
120
<Tabs>
116
121
<TabItem value="yarn" label="Yarn" default>
@@ -142,14 +147,15 @@ Alternatively, you can manage the Snap invocation manually. Use the `wallet_invo
142
147
143
148
:::
144
149
145
-
In the `src/utils/snapHelper.js` file add the `connect` function and the `callSnap` helper function. This file handles the interactions with the Starknet Snap.
150
+
Create a `src/utils` directory, and add a new file named `snapHelper.js` to the directory.
151
+
In `snapHelper.js`, add a `connect` function and a `callSnap` helper function as follows. This file handles the interactions with the Starknet Snap:
146
152
147
-
```javascript title="src/utils/snapHelper.js"
148
-
constsnapId='npm:starknet-snap';
153
+
```javascript title="snapHelper.js"
154
+
constsnapId="npm:starknet-snap";
149
155
150
156
exportasyncfunctionconnect() {
151
157
awaitethereum.request({
152
-
method:'wallet_requestSnaps',
158
+
method:"wallet_requestSnaps",
153
159
params: {
154
160
[snapId]: {},
155
161
},
@@ -159,7 +165,7 @@ export async function connect() {
159
165
exportasyncfunctioncallSnap(method, params) {
160
166
try {
161
167
constresponse=awaitethereum.request({
162
-
method:'wallet_invokeSnap',
168
+
method:"wallet_invokeSnap",
163
169
params: {
164
170
snapId,
165
171
request: {
@@ -180,18 +186,20 @@ export async function callSnap(method, params) {
180
186
181
187
### 2. Call a specific Snap method
182
188
183
-
To call a specific Snap method, for example `createAccount` use the following:
189
+
Use the `callSnap` function to call a specific Snap method.
190
+
The following example calls `starkNet_createAccount`:
184
191
185
192
```javascript
186
193
constdeploy=false; // Set to true to deploy the actual account
187
194
constaddressIndex=0; // Specify which address to derive
188
-
constchainId="0x534e5f5345504f4c4941"; // Specify which chain to use (Sepolia testnet)
189
-
// For mainnet, use: "0x534e5f4d41494e"
195
+
constchainId="0x534e5f5345504f4c4941"; // Specify which chain to use (in this instance the Sepolia testnet)
The following is a full example of a dapp with a button that, when clicked, connects to a Starknet wallet using a MetaMask Snap, creates a Starknet account, and displays the account address:
Copy file name to clipboardExpand all lines: wallet/how-to/use-non-evm-networks/starknet/index.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ sidebar_position: 1
8
8
Starknet is a non-EVM Layer 2 network. To interact with Starknet accounts in MetaMask, you need to use the Starknet Snap.
9
9
10
10
You can use the `get-starknet` library or the `wallet_invokeSnap` JSON-RPC method to connect to the Starknet Snap.
11
-
The choice depends on your specific use case and development preferences.
11
+
12
12
13
13
`get-starknet`:
14
14
- Provides a high-level API that abstracts complex operations.
@@ -27,7 +27,7 @@ The choice depends on your specific use case and development preferences.
27
27
28
28
:::note
29
29
30
-
We recommend using the `get-starknet` library for a most use cases.
30
+
We recommend using the `get-starknet` library for most use cases.
31
31
32
32
:::
33
33
@@ -59,7 +59,7 @@ sequenceDiagram
59
59
participant get as get-starknet
60
60
participant mm as MetaMask
61
61
participant Snap as Starknet Snap
62
-
participant network as Starknet Network
62
+
participant network as Starknet network
63
63
64
64
dapp->>get: Initialize connection
65
65
get->>mm: Request connection
@@ -87,11 +87,11 @@ sequenceDiagram
87
87
get->>dapp: Notify change
88
88
```
89
89
90
-
The `get-starknet` library offers several key features that improve how dapps interact with the StarkNet network through MetaMask."
90
+
The `get-starknet` library offers several key features that improve how dapps interact with the Starknet network through MetaMask:
91
91
92
-
- The `WalletAccount` uses a specified provider to access data from the StarkNet network.
93
-
- For transactions, `get-starknet` prepares the data and sends it to MetaMask for signing via StarkNet Snap.
92
+
- The `WalletAccount` uses a specified provider to access data from the Starknet network.
93
+
- For transactions, `get-starknet` prepares the data and sends it to MetaMask for signing through the Starknet Snap.
94
94
-`get-starknet` enables the dapp to create contract instances connected to the `WalletAccount`, allowing smart contract functions to be invoked, with MetaMask handling the signatures.
95
-
-It sets up listeners for account and network changes in MetaMask, so the dapp can subscribe and update its state accordingly.
96
-
-`get-starknet` can request network changes through MetaMask, allowing users to switch between StarkNet networks, such as Mainnet or Sepolia testnet.
97
-
-It can also request MetaMask to display specific tokens, improving the user experience.
95
+
-`get-starknet` sets up listeners for account and network changes in MetaMask, so the dapp can subscribe and update its state accordingly.
96
+
-`get-starknet` can request network changes through MetaMask, allowing users to switch between Starknet networks, such as Mainnet or Sepolia testnet.
97
+
-`get-starknet` can also request MetaMask to display specific tokens, improving the user experience.
Copy file name to clipboardExpand all lines: wallet/how-to/use-non-evm-networks/starknet/manage-starknet-accounts.md
+28-25Lines changed: 28 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,15 +5,7 @@ sidebar_position: 2
5
5
6
6
# Manage Starknet accounts
7
7
8
-
## Account creation
9
-
10
-
Account creation in Starknet is handled by the wallet provider. As a dapp developer, you do not create accounts directly. Instead, you guide users to create an account with their preferred wallet provider.
11
-
12
-
:::note
13
-
14
-
Currently, multiple Starknet accounts are not supported in the Starknet Snap.
15
-
16
-
:::
8
+
You can manage Starknet accounts to display account information, handle transactions, and respond to account changes in your dapp.
17
9
18
10
## View account information
19
11
@@ -23,7 +15,7 @@ After a user connects, you can display the account details, such as the account
This component displays the connected account address if available, and provides buttons to connect or disconnect accounts.
69
61
62
+
## Account creation
63
+
64
+
Account creation in Starknet is handled by the wallet provider. As a dapp developer, you do not create accounts directly. Instead, you guide users to create an account with their preferred wallet provider.
65
+
66
+
:::note
67
+
68
+
Currently, multiple Starknet accounts are not supported in the Starknet Snap.
This invokes a specific function on a Starknet smart contract, handling wallet connection and transaction submission, and logs the result or any errors.
98
100
101
+
99
102
## Handle account changes and disconnections
100
103
101
104
To handle account changes and disconnections, you can use event listeners provided by `get-starknet`:
0 commit comments