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
description: How does `get-starknet` interact with MetaMask.
3
+
sidebar_position: 2
4
+
---
5
+
6
+
# About `get-starknet`
7
+
8
+
`get-starknet` is a library that simplifies Starknet network interactions.
9
+
It works with the Starknet Snap to extend the functionality of MetaMask and enable dapps to interact with users' Starknet accounts in MetaMask.
10
+
11
+
When you integrate `get-starknet` into your dapp, it creates a `WalletAccount` object. `WalletAccount` acts as a connection between dapps and MetaMask and provides a way to manage Starknet interactions.
12
+
13
+
This allows users to send Starknet transactions, sign Starknet messages, and manage Starknet accounts within MetaMask, and this functionality can be extended to multiple wallets.
14
+
15
+
## How `get-starknet` and MetaMask interact
16
+
17
+
A dapp with `get-starknet` installed interacts with MetaMask as follows:
18
+
19
+
1. The dapp uses `get-starknet` to request the user connect to MetaMask. If the user doesn't have the Starknet Snap installed, MetaMask automatically prompts the user to connect and approve the addition.
20
+
21
+
1. After the dapp is connected to MetaMask and the Starknet Snap, `get-starknet` receives a Starknet Windows Object (SWO), which represents the MetaMask wallet with Starknet functionality.
22
+
23
+
1.`get-starknet` creates a [`WalletAccount`](http://starknetjs.com/docs/guides/walletAccount/) instance. This instance manages the Starknet account within MetaMask.
24
+
25
+
```mermaid
26
+
sequenceDiagram
27
+
participant dapp as dapp
28
+
participant get as get-starknet
29
+
participant mm as MetaMask
30
+
participant Snap as Starknet Snap
31
+
participant network as Starknet network
32
+
33
+
dapp->>get: Initialize connection
34
+
get->>mm: Request connection
35
+
mm->>Snap: Activate
36
+
Snap-->>mm: Activated
37
+
mm-->>get: Return SWO
38
+
get->>get: Create WalletAccount
39
+
get-->>dapp: Connection established
40
+
41
+
dapp->>get: Read blockchain data
42
+
get->>network: Query data
43
+
network-->>get: Return data
44
+
get-->>dapp: Processed data
45
+
46
+
dapp->>get: Write transaction
47
+
get->>mm: Request signature
48
+
mm->>Snap: Sign transaction
49
+
Snap-->>mm: Signed transaction
50
+
mm-->>get: Return signature
51
+
get->>network: Submit transaction
52
+
network-->>get: Transaction result
53
+
get-->>dapp: Transaction confirmation
54
+
55
+
mm->>get: Account/Network changed
56
+
get->>dapp: Notify change
57
+
```
58
+
59
+
The `get-starknet` library offers several key features that improve how dapps interact with the Starknet network through MetaMask:
60
+
61
+
- The `WalletAccount` uses a specified provider to access data from the Starknet network.
62
+
- For transactions, `get-starknet` prepares the data and sends it to MetaMask for signing through the Starknet Snap.
63
+
-`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.
64
+
-`get-starknet` sets up listeners for account and network changes in MetaMask, so the dapp can subscribe and update its state accordingly.
65
+
-`get-starknet` can request network changes through MetaMask, allowing users to switch between Starknet networks, such as Mainnet or Sepolia testnet.
66
+
-`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/connect-to-starknet.md
+15-14Lines changed: 15 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ import TabItem from "@theme/TabItem";
8
8
9
9
# Connect your Starknet account to MetaMask
10
10
11
-
To connect your dapp to the Starknet network in MetaMask, you can use the `get-starknet` library.
11
+
To connect your dapp to the Starknet network in MetaMask, you can use the [`get-starknet`](https://github.com/starknet-io/get-starknet) library.
12
12
This library simplifies the process of connecting to the Starknet Snap, allowing you to interact with users' Starknet accounts in MetaMask.
13
13
`get-starknet` also enables dapps to interact with other wallets in the Starknet ecosystem.
14
14
@@ -53,6 +53,7 @@ Add the [`get-starknet`](https://github.com/starknet-io/get-starknet) `version 3
53
53
### 2. Connect to the Snap
54
54
55
55
Create a `src/components` directory, and add a new file named `WalletConnectButton.js` to the directory. Add the following code to the file:
@@ -77,7 +78,7 @@ function WalletConnectButton() {
77
78
setWalletName(getWallet?.name||"")
78
79
}
79
80
catch(e){
80
-
//handle user rejection to install metamask / snaps here.
81
+
//Handle user rejection to install MetaMask / Snaps.
81
82
console.log(e)
82
83
}
83
84
};
@@ -143,7 +144,7 @@ Alternatively, you can manage the Snap invocation manually. Use the `wallet_invo
143
144
144
145
:::note
145
146
146
-
To connect to Starknet, the dapp user must ensure the [Starknet Snap](https://snaps.metamask.io/snap/npm/consensys/starknet-snap/) is added to MetaMask.
147
+
To connect to Starknet, the dapp user must ensure the [Starknet Snap](https://snaps.metamask.io/snap/npm/consensys/starknet-snap/) is added to MetaMask.
147
148
148
149
:::
149
150
@@ -190,11 +191,11 @@ Use the `callSnap` function to call a specific Snap method.
190
191
The following example calls `starkNet_createAccount`:
191
192
192
193
```javascript
193
-
constdeploy=false; // Set to true to deploy the actual account
194
-
constaddressIndex=0; // Specify which address to derive
195
-
constchainId="0x534e5f5345504f4c4941"; //Specify which chain to use (in this instance the Sepolia testnet)
194
+
constdeploy=false; // Set to true to deploy the actual account.
195
+
constaddressIndex=0; // Specify which address to derive.
196
+
constchainId="0x534e5f5345504f4c4941"; //Chain ID of the network to use.
Copy file name to clipboardExpand all lines: wallet/how-to/use-non-evm-networks/starknet/index.md
+27-69Lines changed: 27 additions & 69 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,91 +7,49 @@ sidebar_position: 1
7
7
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
-
You can use the `get-starknet` library or the `wallet_invokeSnap` JSON-RPC method to connect to the Starknet Snap.
10
+
You can use the [`get-starknet`](https://github.com/starknet-io/get-starknet) library or the `wallet_invokeSnap` JSON-RPC method to connect to the Starknet Snap.
11
11
12
-
13
-
`get-starknet`:
12
+
[`get-starknet`](architecture):
14
13
- Provides a high-level API that abstracts complex operations.
15
14
- Offers standardized error handling.
16
15
- Supports multiple wallets, not limited to MetaMask.
17
16
- Manages wallet connections and Starknet interactions.
- Provides results in more detailed, lower-level code.
26
25
27
-
28
26
:::note
29
27
30
-
We recommend using the `get-starknet` library for most use cases.
31
-
32
-
:::
33
-
34
-
The choice between the two connection methods depends on the specific needs of the project, the desired level of control, and familiarity with Starknet and Snaps.
35
-
36
-
37
-
## About `get-starknet`
38
-
39
-
`get-starknet` is a library that simplifies Starknet network interactions.
40
-
It works with the Starknet Snap to extend the functionality of MetaMask and enable dapps to interact with users' Starknet accounts in MetaMask.
28
+
We recommend using the `get-starknet` library for most use cases due to its ease of configuration.
41
29
42
-
When you integrate `get-starknet` into your dapp, it creates a `WalletAccount` object. `WalletAccount` acts as a connection between dapps and MetaMask and provides a way to manage Starknet interactions.
30
+
There are [limitations](#limitations) on the methods that are avilabile when using `get-starknet`. For more information on the methods you can use when interacting with users' Starknet accounts, see the [Starknet Snap API documentation](../../../reference/non-evm-apis/starknet-snap-api.md).
43
31
44
-
This allows users to send Starknet transactions, sign Starknet messages, and manage Starknet accounts within MetaMask, and this functionality can be extended to multiple wallets.
45
-
46
-
### How `get-starknet` and MetaMask interact
47
-
48
-
A dapp with `get-starknet` installed interacts with MetaMask as follows:
49
-
50
-
1. The dapp uses `get-starknet` to request the user connect to MetaMask. If the user doesn't have the Starknet Snap installed, MetaMask automatically prompts the user to connect and approve the addition.
51
-
52
-
1. After the dapp is connected to MetaMask and the Starknet Snap, `get-starknet` receives a Starknet Windows Object (SWO), which represents the MetaMask wallet with Starknet functionality.
53
-
54
-
1.`get-starknet` creates a [`WalletAccount`](http://starknetjs.com/docs/guides/walletAccount/) instance. This instance manages the Starknet account within MetaMask.
55
-
56
-
```mermaid
57
-
sequenceDiagram
58
-
participant dapp as dapp
59
-
participant get as get-starknet
60
-
participant mm as MetaMask
61
-
participant Snap as Starknet Snap
62
-
participant network as Starknet network
63
-
64
-
dapp->>get: Initialize connection
65
-
get->>mm: Request connection
66
-
mm->>Snap: Activate
67
-
Snap-->>mm: Activated
68
-
mm-->>get: Return SWO
69
-
get->>get: Create WalletAccount
70
-
get-->>dapp: Connection established
71
-
72
-
dapp->>get: Read blockchain data
73
-
get->>network: Query data
74
-
network-->>get: Return data
75
-
get-->>dapp: Processed data
76
-
77
-
dapp->>get: Write transaction
78
-
get->>mm: Request signature
79
-
mm->>Snap: Sign transaction
80
-
Snap-->>mm: Signed transaction
81
-
mm-->>get: Return signature
82
-
get->>network: Submit transaction
83
-
network-->>get: Transaction result
84
-
get-->>dapp: Transaction confirmation
85
-
86
-
mm->>get: Account/Network changed
87
-
get->>dapp: Notify change
88
-
```
32
+
:::
89
33
90
-
The `get-starknet` library offers several key features that improve how dapps interact with the Starknet network through MetaMask:
91
34
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
-
-`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
-
-`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.
35
+
## Limitations
36
+
37
+
Not all methods are supported by both `get-starknet` and `wallet_invokeSnap`. The following table lists which methods are availabile for the two implemnatations.
Copy file name to clipboardExpand all lines: wallet/how-to/use-non-evm-networks/starknet/manage-starknet-accounts.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ This component displays the connected account address if available, and provides
61
61
62
62
## Account creation
63
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.
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](../connect-to-starknet) with their preferred wallet provider.
Starknet currently operates two public networks. Each network is identified by a unique chain ID. Use these chain IDs when configuring your dapp or interacting with the Starknet networks.
27
27
28
28
You can allow users to switch between different Starknet networks by setting the appropriate chain ID.
Copy file name to clipboardExpand all lines: wallet/how-to/use-non-evm-networks/starknet/tutorial.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
---
2
-
description: Starknet integration tutorial
2
+
description: Create a basic dapp using `get-starknet` and React TypeScript
3
3
sidebar_position: 6
4
4
---
5
5
6
-
# Create a basic dapp with `get-starknet` and React TypeScript
6
+
# Create a basic dapp with `get-starknet`
7
7
8
-
In this tutorial, you'll learn how to set up a basic dapp that uses get-starknet to connect to MetaMask and display the user's wallet address.
8
+
In this tutorial, you'll learn how to set up a basic dapp that uses `get-starknet` to connect to MetaMask and display the user's wallet address.
9
9
10
10
## 1. Project Setup
11
11
@@ -203,7 +203,7 @@ Now that you have set up the basics, let's go a step further and show how to dis
203
203
204
204
### 3.1. Setting Up the Contract
205
205
206
-
To interact with an ERC-20 contract, you'll need to create a Contract instance from starknet.js using the WalletAccount instance. Assuming the ABI is loaded from a JSON file, here's how you would do it:
206
+
To interact with an ERC-20 contract, you'll need to create a contract instance from `starknet.js` using the `WalletAccount` instance. Assuming the ABI is loaded from a JSON file, here's how you would do it:
0 commit comments