Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Starknet Snap docs #1509

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e6bd15c
rough skeleton
joaniefromtheblock Aug 28, 2024
f8c3685
update menu sidebar
joaniefromtheblock Aug 28, 2024
1130adf
Add Starknet Snap API reference docs
alexandratran Aug 31, 2024
9401571
Merge branch 'main' into wip-starknet-snap
alexandratran Sep 5, 2024
a43f196
Clean up files and placeholders
alexandratran Sep 5, 2024
c27a96d
add changes for connect
joaniefromtheblock Sep 12, 2024
6bac10a
update branch
joaniefromtheblock Sep 12, 2024
473a71d
examples added
joaniefromtheblock Sep 12, 2024
25821bb
rewrite of connect section
joaniefromtheblock Sep 14, 2024
0251bcc
rough additions of troubleshoot section
joaniefromtheblock Sep 14, 2024
3d8ef91
updates with suggestions
joaniefromtheblock Sep 18, 2024
b915696
add additional suggestions
joaniefromtheblock Sep 18, 2024
5b6e1cf
apply suggestions
joaniefromtheblock Sep 19, 2024
f2074ef
more suggestions
joaniefromtheblock Sep 19, 2024
455aaec
updates
joaniefromtheblock Sep 19, 2024
d832af8
updates
joaniefromtheblock Sep 19, 2024
df73570
Merge branch 'main' into wip-starknet-snap
alexandratran Sep 20, 2024
0e4ef69
Edit non-EVM intro and Starknet intro
alexandratran Sep 20, 2024
8e75cb8
Edit Connect to Starknet
alexandratran Sep 20, 2024
8501a8b
Edit About get-starknet
alexandratran Sep 20, 2024
baa2b16
Edit Manage Starknet accounts
alexandratran Sep 20, 2024
f6f30a2
Edit Manage networks, API reference, etc
alexandratran Sep 20, 2024
81d3bb2
add docs
joaniefromtheblock Sep 20, 2024
c5f1762
fix table
joaniefromtheblock Sep 20, 2024
333cef5
Apply suggestions from code review
joaniefromtheblock Sep 24, 2024
5786849
Apply suggestions from code review
joaniefromtheblock Sep 24, 2024
8e467fa
update troubleshoot section
joaniefromtheblock Sep 25, 2024
151e759
update troubleshoot sections
joaniefromtheblock Sep 25, 2024
a1fe114
update text for tutorial
joaniefromtheblock Sep 25, 2024
ff7df58
add dual examples
joaniefromtheblock Sep 26, 2024
faba7f4
copy edits
joaniefromtheblock Sep 26, 2024
1617eab
copy edits
joaniefromtheblock Sep 26, 2024
4a64f9b
copy edits
joaniefromtheblock Sep 26, 2024
07ad89e
Edit content for style and formatting
alexandratran Sep 26, 2024
0cadd60
Merge and edit branch 'wip-starknet-snap' of github.com:MetaMask/meta…
alexandratran Sep 26, 2024
d432e98
add template text
joaniefromtheblock Sep 26, 2024
99839e7
add note
joaniefromtheblock Sep 26, 2024
f92fdc3
Merge branch 'main' into wip-starknet-snap
joaniefromtheblock Sep 30, 2024
cc4cb52
Apply suggestions from code review
joaniefromtheblock Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions wallet-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const sidebar = {
type: "doc",
id: "reference/sdk-unity-api",
},
{
type: "category",
label: "Non-EVM APIs",
link: { type: "generated-index", slug: "/reference/non-evm-apis" },
items: [{ type: "autogenerated", dirName: "reference/non-evm-apis" }],
},
{
type: "doc",
id: "reference/provider-api",
Expand Down
4 changes: 4 additions & 0 deletions wallet/how-to/connect/access-accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ When accessing a user's accounts:
- **Always** disable the connect button while the connection request is pending.
- **Never** initiate a connection request on page load.

:::note
You can also access users' accounts on some [non-EVM networks](/wallet/how-to/use-non-evm-networks).
:::

## Create a connect button

:::caution Important
Expand Down
8 changes: 4 additions & 4 deletions wallet/how-to/manage-networks/add-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ The confirmations look like the following:
</div>
</div>

:::note

To add a local development network such as [Hardhat](https://hardhat.org) to MetaMask, see [Run a development network](../run-devnet.md).

:::info Development and non-EVM networks
- To add a local development network such as [Hardhat](https://hardhat.org) to MetaMask, see [Run a development network](../run-devnet.md).
- To add a non-EVM network such as [Starknet](../use-non-evm-networks/starknet/index.md) to MetaMask,
see [Use non-EVM networks](/wallet/how-to/use-non-evm-networks).
:::

## Example
Expand Down
2 changes: 1 addition & 1 deletion wallet/how-to/run-devnet.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: Configure and connect to a Ganache development network.
sidebar_position: 9
sidebar_position: 10
---

# Run a development network
Expand Down
32 changes: 32 additions & 0 deletions wallet/how-to/use-non-evm-networks/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
description: Interact with users' accounts on non-EVM networks.
sidebar_position: 9
---

import CardList from "@site/src/components/CardList"

# Use non-EVM networks

You can interact with users' accounts on non-EVM networks by connecting to existing
[MetaMask Snaps](https://metamask.io/snaps/).

Non-EVM networks are blockchain networks that are not compatible with the Ethereum Virtual Machine (EVM).
Non-EVM dapps and MetaMask can't directly interact with each other.
By connecting to dedicated non-EVM Snaps, you can extend the functionality of MetaMask and integrate non-EVM networks into your existing MetaMask workflow.

joaniefromtheblock marked this conversation as resolved.
Show resolved Hide resolved
MetaMask provides Snaps for the following networks:

<CardList
items={[
{
href: "starknet",
title: "Starknet",
description:
"Layer 2 network for Ethereum using ZK rollups.",
},
]}
/>
joaniefromtheblock marked this conversation as resolved.
Show resolved Hide resolved

:::info
See the [full list of available non-EVM Snaps](https://snaps.metamask.io/interoperability).
:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
description: Learn about how `get-starknet` interacts with MetaMask.
sidebar_position: 8
---

# About `get-starknet`

[`get-starknet`](https://github.com/starknet-io/get-starknet) is a library that simplifies Starknet
network interactions.
It works with the [Starknet Snap](https://snaps.metamask.io/snap/npm/consensys/starknet-snap/) to
enable dapps to interact with users' Starknet accounts in MetaMask.

Copy link

@stanleyyconsensys stanleyyconsensys Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joaniefromtheblock
attached the diagram for the Architecture
feel free to move it to anywhere you prefer or even change the content

Suggested change
```mermaid
graph
dapp[Dapp] -- wallet_invokeSnapp --> snap[Starknet Snap]
dapp[Dapp] -- get-starknet --> swo[Starknet Window Object]
swo -- wallet_invokeSnap --> snap
swo --> acc[Account Object]
acc --> signer[Signer Object] -- wallet_invokeSnap --> snap
acc -- wallet_invokeSnap --> snap
acc --> sp[Starknet Network]
snap --> sp

When you integrate `get-starknet` into your dapp, it creates a `WalletAccount` object, which acts as
the connection between the dapp and MetaMask, and manages Starknet interactions.
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 in the Starknet
ecosystem.
Comment on lines +13 to +17

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When you integrate `get-starknet` into your dapp, it creates a `WalletAccount` object, which acts as
the connection between the dapp and MetaMask, and manages Starknet interactions.
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 in the Starknet
ecosystem.
When you integrate `get-starknet` into your dapp, it creates a [Starknet
Windows Object (SWO)](https://github.com/starknet-io/get-starknet/blob/get-starknet-core%403.3.0/packages/core/src/StarknetWindowObject.ts), which acts as
the connection between the dapp and MetaMask, and manages Starknet interactions.
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 in the Starknet
ecosystem.

WalletAccount is design for get-starknet v4, which we have not integrated yet

Copy link
Contributor Author

@joaniefromtheblock joaniefromtheblock Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khanti42 so I should remove all instances and mentions of WalletAccount?

Copy link

@stanleyyconsensys stanleyyconsensys Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, the fact is,
in get-starknet 3.3.0, user will communicate with network via SWO.account
in get-starknet 4.x user can communicate with network via SWO.account or make their own implementation with WalletAccount object

and we will try to do the advice comment on all WalletAccount related comment , including the description , and you can help us to revised to better wording later, wdyt?


## How `get-starknet` and MetaMask interact

A dapp with `get-starknet` installed interacts with MetaMask as follows:

1. The dapp uses `get-starknet` to request the user connect to MetaMask.
MetaMask automatically requests the user to add the Starknet Snap, if it's not already present.

1. After the dapp is connected to MetaMask and the Starknet Snap, `get-starknet` receives a Starknet

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. After the dapp is connected to MetaMask and the Starknet Snap, `get-starknet` receives a Starknet
2. After the dapp is connected to MetaMask and the Starknet Snap, `get-starknet` receives a Starknet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stanleyyconsensys Sorry that's not a typo. The markdown will increment. If you check the Vercel build it will show sequential numbering. I just chose to do it like that in case we add or remove another step - that way we will not have to renumber everything ;)

Windows Object (SWO), which represents the MetaMask wallet with Starknet functionality.

1. `get-starknet` creates a [`WalletAccount`](http://starknetjs.com/docs/guides/walletAccount/) instance.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. `get-starknet` creates a [`WalletAccount`](http://starknetjs.com/docs/guides/walletAccount/) instance.
3. With the Starknet Windows Object (SWO), an [Account Object] (https://starknetjs.com/docs/API/#account) can be retrieved - e.g `swo.account` and provide the functionality to manage Starknet interactions

WalletAccount is design for get-starknet v4, which we have not integrated yet
for current implementation, it works as above way

This instance manages the Starknet account within MetaMask.

```mermaid
sequenceDiagram
participant dapp as Dapp
participant get as get-starknet
participant mm as MetaMask
participant Snap as Starknet Snap
participant network as Starknet network

dapp->>get: Initialize connection
get->>mm: Request connection
mm->>Snap: Activate
Snap-->>mm: Activated
mm-->>get: Return SWO
get->>network: Create WalletAccount
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Starknet there is a difference between creating a wallet account object and deploying an account. The creation of the walletObject is handled by the snap. The Deployment of the account (that targets the network) is done during the first transaction if the account is not deployed

Suggested change
get->>network: Create WalletAccount
get->>Snap: Create WalletAccount

Comment on lines +33 to +45

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sequenceDiagram
participant dapp as Dapp
participant get as get-starknet
participant mm as MetaMask
participant Snap as Starknet Snap
participant network as Starknet network
dapp->>get: Initialize connection
get->>mm: Request connection
mm->>Snap: Activate
Snap-->>mm: Activated
mm-->>get: Return SWO
get->>network: Create WalletAccount
sequenceDiagram
participant user as End User
participant dapp as Dapp
participant get as get-starknet
participant mm as MetaMask
participant Snap as Starknet Snap
participant network as Starknet network
dapp->>get: Initialize connection
get->>mm: Request connection
mm->>Snap: Activate
Snap-->>mm: Activated
get->>Snap: Request Starknet account address
Snap-->>mm: Recover account and return Starknet account address
mm-->>get: Return Starknet account address
get-->>dapp: Connection established with SWO return
dapp->>get: Read blockchain data
get->>network: Query data
network-->>get: Return data
get-->>dapp: Processed data
dapp->>get: Write transaction
get->>mm: Request write transaction
mm->>Snap: write transaction
Snap-->>mm: Request confirmation to write transaction
mm-->>user: Request confirmation
user-->>mm: Confirm transaction
mm-->>Snap: Confirm transaction
alt If the Account has deployed
Snap-->>network: deploying account transaction
end
Snap-->>network: Submit transaction
network-->>Snap: Transaction result
Snap-->>mm: Return Transaction result
mm-->>get: Return Transaction result
get-->>dapp: Return Transaction result

combine with @khanti42 comments, i have make a advice change above

Copy link
Contributor Author

@joaniefromtheblock joaniefromtheblock Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for updating and providing more guidance on this

get-->>dapp: Connection established

dapp->>get: Read blockchain data
get->>network: Query data
network-->>get: Return data
get-->>dapp: Processed data

dapp->>get: Write transaction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we need a if / else close.

if the account is not deployed then the account deployment is done together with the write transaction. If the account is already deployed then only the transaction is written.

get->>mm: Request signature
mm->>Snap: Sign transaction
Snap-->>mm: Signed transaction
mm-->>get: Return signature
get->>network: Submit transaction
network-->>get: Transaction result
get-->>dapp: Transaction confirmation
```

The `get-starknet` library offers several features that improve how dapps interact with the Starknet
network through MetaMask:

- The `WalletAccount` uses a specified provider to access data from the Starknet network.
- For transactions, `get-starknet` prepares the data and sends it to MetaMask for signing through
the Starknet Snap.
- `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.
- `get-starknet` sets up listeners for account and network changes in MetaMask, so the dapp can
subscribe and update its state accordingly.
- `get-starknet` can request network changes through MetaMask, allowing users to switch between
Starknet networks, such as Mainnet and Sepolia testnet.
- `get-starknet` can also request MetaMask to display specific tokens, improving the user experience.
Comment on lines +63 to +75

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `get-starknet` library offers several features that improve how dapps interact with the Starknet
network through MetaMask:
- The `WalletAccount` uses a specified provider to access data from the Starknet network.
- For transactions, `get-starknet` prepares the data and sends it to MetaMask for signing through
the Starknet Snap.
- `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.
- `get-starknet` sets up listeners for account and network changes in MetaMask, so the dapp can
subscribe and update its state accordingly.
- `get-starknet` can request network changes through MetaMask, allowing users to switch between
Starknet networks, such as Mainnet and Sepolia testnet.
- `get-starknet` can also request MetaMask to display specific tokens, improving the user experience.
The `get-starknet` library offers several features that improve how dapps interact with the Starknet
network through MetaMask:
- `get-starknet` enable [EIP-6963](https://metamask.io/news/developers/how-to-implement-eip-6963-support-in-your-web-3-dapp/) by default, hence to support multi-wallet discovery in the dapp.
- The `Account Object` in `Starknet Window Object (SWO))` provide the functionality as [Starknet.js Account Object](https://starknetjs.com/docs/API/#account) to manage Starknet interactions, it bridges the request from the dapp to MetaMask and the Starknet Snap automately.
- `get-starknet` can request network changes through MetaMask, allowing users to switch between
Starknet networks, such as Mainnet and Sepolia testnet.
- `get-starknet` can also request MetaMask to display specific tokens, improving the user experience.

not sure if the last open point is valid or not (get-starknet can also request MetaMask to display specific tokens...),
if it means fetch token balance , then it is ,
if it means display token in MM wallet, then it is not

Loading
Loading