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

Merged
merged 100 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
100 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
b22b545
updates
joaniefromtheblock Oct 3, 2024
7219bc9
Merge branch 'main' into wip-starknet-snap
joaniefromtheblock Oct 3, 2024
052b326
remove old instances
joaniefromtheblock Oct 4, 2024
e5da758
Apply suggestions from code review
joaniefromtheblock Oct 6, 2024
5174774
Merge branch 'main' into wip-starknet-snap
alexandratran Oct 7, 2024
57d3e60
edits
alexandratran Oct 7, 2024
91a5cd8
Update wallet/reference/non-evm-apis/starknet-snap-api.md
joaniefromtheblock Oct 7, 2024
5233dad
Update wallet/how-to/use-non-evm-networks/starknet/manage-starknet-ac…
joaniefromtheblock Oct 7, 2024
b1dcae9
Merge branch 'main' into wip-starknet-snap
joaniefromtheblock Oct 7, 2024
b315361
missed examples
joaniefromtheblock Oct 7, 2024
41c9772
update with images
joaniefromtheblock Oct 7, 2024
ad2fcaf
wip-starknet-snap
joaniefromtheblock Oct 7, 2024
f0b1d42
update table
joaniefromtheblock Oct 8, 2024
6a462d7
Merge branch 'main' into wip-starknet-snap
alexandratran Oct 8, 2024
56fe03c
update table
joaniefromtheblock Oct 8, 2024
771185c
Merge branch 'main' into wip-starknet-snap
joaniefromtheblock Oct 8, 2024
8c076f6
update screenshots and edits
alexandratran Oct 8, 2024
d886822
Merge branch 'wip-starknet-snap' of github.com:MetaMask/metamask-docs…
alexandratran Oct 8, 2024
01d35b8
fix table
alexandratran Oct 8, 2024
94e2599
wip-starknet-snap
joaniefromtheblock Oct 9, 2024
c67150d
add note
joaniefromtheblock Oct 9, 2024
b99d9b4
Merge branch 'main' into wip-starknet-snap
alexandratran Oct 10, 2024
69e1866
another update
joaniefromtheblock Oct 10, 2024
ecc8a19
tutorial edit pass
alexandratran Oct 10, 2024
f6ca718
Merge branch 'wip-starknet-snap' of github.com:MetaMask/metamask-docs…
alexandratran Oct 10, 2024
3662d58
edit notes
alexandratran Oct 11, 2024
2077ee4
edit diagrams
alexandratran Oct 11, 2024
3cebaf4
Updates to code
joaniefromtheblock Oct 11, 2024
6c135f4
update code
joaniefromtheblock Oct 12, 2024
b3a510d
more updates
joaniefromtheblock Oct 12, 2024
8fb366c
updates for starknet docs
joaniefromtheblock Oct 15, 2024
6ab86da
Merge branch 'main' into wip-starknet-snap
alexandratran Oct 16, 2024
9c71895
Apply suggestions from code review
alexandratran Oct 16, 2024
f04565b
Merge branch 'wip-starknet-snap' of github.com:MetaMask/metamask-docs…
alexandratran Oct 16, 2024
ce2f148
edit recent updates
alexandratran Oct 16, 2024
c26d1c3
typo
alexandratran Oct 16, 2024
0db437e
add methods updates
joaniefromtheblock Oct 16, 2024
bc13128
update to include api methods not included and update to match params
joaniefromtheblock Oct 16, 2024
7de41e3
add image for tutorial
joaniefromtheblock Oct 16, 2024
33e58b4
Merge branch 'main' into wip-starknet-snap
joaniefromtheblock Oct 17, 2024
faa439f
Apply suggestions from code review
joaniefromtheblock Oct 17, 2024
232b1ca
update samples
joaniefromtheblock Oct 17, 2024
fd1f59c
add div
joaniefromtheblock Oct 17, 2024
1ec4259
update table
joaniefromtheblock Oct 17, 2024
ca5dc07
update table
joaniefromtheblock Oct 17, 2024
87d74d1
table update
joaniefromtheblock Oct 17, 2024
c517776
new table and headings
joaniefromtheblock Oct 17, 2024
cda26d1
add more screenshots
joaniefromtheblock Oct 17, 2024
7eb26f6
make tutorial clearer
joaniefromtheblock Oct 17, 2024
4d45e45
updates for clarity
joaniefromtheblock Oct 17, 2024
27824a4
Merge branch 'main' into wip-starknet-snap
joaniefromtheblock Oct 17, 2024
6a3f2fc
update table to use vertically merged cells
alexandratran Oct 18, 2024
9d38fee
tutorial edits but also hide it
alexandratran Oct 18, 2024
588083d
api fixes
alexandratran Oct 18, 2024
a3b1515
test table links
joaniefromtheblock Oct 18, 2024
ed3d0a5
update table and fix links
joaniefromtheblock Oct 18, 2024
31af75c
edit instances of EIP6963Provider
joaniefromtheblock Oct 18, 2024
7388c12
added some resource links
joaniefromtheblock Oct 18, 2024
71808b3
add note on deployment
joaniefromtheblock Oct 18, 2024
9b51cd7
Merge branch 'main' into wip-starknet-snap
joaniefromtheblock Oct 18, 2024
26406ab
Merge branch 'main' into wip-starknet-snap
alexandratran Oct 18, 2024
14ff23b
Merge branch 'wip-starknet-snap' of github.com:MetaMask/metamask-docs…
alexandratran Oct 18, 2024
0c45838
edits
alexandratran Oct 18, 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
125 changes: 70 additions & 55 deletions wallet/how-to/use-non-evm-networks/starknet/connect-to-starknet.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,24 @@ After the user connects to Starknet, the dapp displays the user's connected wall
<img src={require("../../../assets/starknet-dapp-connected.png").default} alt="Connected Starknet dapp" width="850" style={{border: "1px solid #DCDCDC"}} />
</p>

:::note

An account can submit transactions only after it's deployed.
It does not deploy immediately upon creation.
Deployment happens during the first [transaction](send-starknet-transactions.md).

:::

## Connect using `wallet_invokeSnap`

Alternatively, you can manage the Snap invocation manually.
Use the [`wallet_invokeSnap`](/snaps/reference/wallet-api-for-snaps/#wallet_invokesnap) JSON-RPC
method to directly interact with the Starknet Snap.

:::note
:::warning Important

We recommend using [EIP-6963](../../../concepts/wallet-interoperability.md) for detecting the MetaMask wallet when using the `wallet_invokeSnap` approach. This ensures better interoperability and improved wallet integration.
We recommend using [EIP-6963](../../../concepts/wallet-interoperability.md) for detecting MetaMask when using the `wallet_invokeSnap` approach.
This ensures you can connect to MetaMask and other installed wallets without conflict.

:::

Expand All @@ -254,26 +263,28 @@ This file handles the interactions with the Starknet Snap:
const snapId = "npm:starknet-snap";

export async function connect() {
await ethereum.request({
method: "wallet_requestSnaps",
params: {
[snapId]: {},
},
});
await provider // Or window.ethereum if you don't support EIP-6963.
.request({
method: "wallet_requestSnaps",
params: {
[snapId]: {},
},
});
}

export async function callSnap(method, params) {
try {
const response = await ethereum.request({
method: "wallet_invokeSnap",
params: {
snapId,
request: {
method,
params,
const response = await provider // Or window.ethereum if you don't support EIP-6963.
.request({
method: "wallet_invokeSnap",
params: {
snapId,
request: {
method,
params,
},
},
},
});
});
console.log(`${method} response:`, response);
return response;
} catch (err) {
Expand Down Expand Up @@ -303,6 +314,14 @@ const chainId = "0x534e5f5345504f4c4941"; // Chain ID of the network to use.
const accountInfo = await callSnap("starkNet_createAccount", { addressIndex, deploy, chainId });
```

:::note

An account can submit transactions only after it's deployed.
It does not deploy immediately upon creation.
Deployment happens during the first [transaction](send-starknet-transactions.md).

:::

### Examples
alexandratran marked this conversation as resolved.
Show resolved Hide resolved

#### HTML and Vanilla JS
Expand All @@ -316,14 +335,6 @@ It displays a button that, when selected:
- Creates a Starknet account.
- Displays the account address.

:::note

An account can submit transactions only after it's deployed.
It does not deploy immediately upon creation. Deployment happens during the first [transaction](index.md#supported-functionalities).
such as when calling `execute`(https://starknetjs.com/docs/API/classes/Account/#execute) through `get-starknet` or using [`starknet_executeTxn`](../../../reference/non-evm-apis/starknet-snap-api.md#starknet_executeTxn) from `wallet_invokeSnap`.

:::

```html
alexandratran marked this conversation as resolved.
Show resolved Hide resolved
<html lang="en">
<head>
Expand All @@ -336,24 +347,26 @@ such as when calling `execute`(https://starknetjs.com/docs/API/classes/Account/#
<p id="accountInfo"></p>
<script>
async function connect(snapId) {
await ethereum.request({
method: "wallet_requestSnaps",
params: {
[snapId]: {},
},
});
await provider // Or window.ethereum if you don't support EIP-6963.
.request({
method: "wallet_requestSnaps",
params: {
[snapId]: {},
},
});
}
async function callSnap(snapId, method, params) {
try {
const response = await ethereum.request({
method: "wallet_invokeSnap",
params: {
snapId,
request: {
method,
params,
const response = await provider // Or window.ethereum if you don't support EIP-6963.
.request({
method: "wallet_invokeSnap",
params: {
snapId,
request: {
method,
params,
},
},
},
});
return response;
} catch (err) {
Expand Down Expand Up @@ -391,29 +404,31 @@ const ConnectWallet = () => {
const [accountInfo, setAccountInfo] = useState('');
const connect = async (snapId) => {
try {
await provider.request({           // Or window.ethereum if you don't support EIP-6963.
method: "wallet_requestSnaps",
params: {
[snapId]: {},
},
});
await provider // Or window.ethereum if you don't support EIP-6963.
.request({
method: "wallet_requestSnaps",
params: {
[snapId]: {},
},
});
} catch (err) {
console.error("Snap connection error:", err);
alert(`Error connecting to Snap: ${err.message || err}`);
}
};
const callSnap = async (snapId, method, params) => {
try {
const response = await provider.request({           // Or window.ethereum if you don't support EIP-6963.
method: "wallet_invokeSnap",
params: {
snapId,
request: {
method,
params,
const response = await provider // Or window.ethereum if you don't support EIP-6963.
.request({
method: "wallet_invokeSnap",
params: {
snapId,
request: {
method,
params,
},
},
},
});
});
return response;
} catch (err) {
console.error(`${method} problem happened:`, err);
Expand All @@ -422,7 +437,7 @@ const ConnectWallet = () => {
};
const handleConnectClick = async () => {
try {
const snapId = "npm:@consensys/starknet-snap"; // Snap ID
const snapId = "npm:@consensys/starknet-snap"; // Snap ID.
await connect(snapId);
const deploy = false; // Whether to deploy the actual account.
const addressIndex = 0; // The address to derive.
Expand Down
11 changes: 4 additions & 7 deletions wallet/how-to/use-non-evm-networks/starknet/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ sidebar_position: 1
[Starknet](https://www.starknet.io/) is a non-EVM Layer 2 network.
You can interact with users' Starknet accounts in MetaMask by connecting to the
[Starknet Snap](https://snaps.metamask.io/snap/npm/consensys/starknet-snap/).

You can use the [`get-starknet`](https://github.com/starknet-io/get-starknet) library or the
[`wallet_invokeSnap`](/snaps/reference/wallet-api-for-snaps/#wallet_invokesnap) JSON-RPC method from
your dapp to connect to the Starknet Snap.
Both options support similar functionalities, but offer different ways of interacting with users'
Starknet accounts.
See [Connect to Starknet](connect-to-starknet.md) to get started.

See [**Connect to Starknet**](connect-to-starknet.md) to get started.

The following sections compare the two connection options.

Expand Down Expand Up @@ -164,13 +163,11 @@ The following section lists the core functionalities and API methods that each c
</tbody>
</table>

## Next steps

To get started, learn how to [connect your dapp to Starknet in MetaMask](connect-to-starknet.md).

## Resources

The following resources provide additional information for learning about and interacting with Starknet:
To get started, [connect your dapp to Starknet in MetaMask](connect-to-starknet.md).

The following external resources provide additional information for learning about and interacting with Starknet:

- [Official Starknet documentation](https://www.starknet.io/developers/)
- [Starknet companion dapp](https://snaps.consensys.io/starknet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The following example displays the account address:
```javascript
const connectStarknetAccount = async () => {
const starknet = await connect();
await starknet.enable(); // Prompts the user to connect their Starknet account using MetaMask
await starknet.enable(); // Prompts the user to connect their Starknet account using MetaMask.
return starknet;
};

Expand All @@ -57,15 +57,16 @@ The following example displays the account address:
if (typeof provider !== "undefined" && provider.isMetaMask) {
try {
// Invoke the Starknet Snap to get account information.
const response = await provider.request({           // Or window.ethereum if you don't support EIP-6963.
method: "wallet_invokeSnap",
params: {
snapId: "npm:@starknet-snap/snap",
request: {
method: "starknet_recoverAccounts"
const response = await provider // Or window.ethereum if you don't support EIP-6963.
.request({
method: "wallet_invokeSnap",
params: {
snapId: "npm:@starknet-snap/snap",
request: {
method: "starknet_recoverAccounts"
}
}
}
});
});

if (response && response.length > 0) {
const account = response[0]; // Get the first account.
Expand All @@ -82,7 +83,7 @@ The following example displays the account address:
}
};

// Call the function when needed
// Call the function when needed.
showAccountInfo();
```

Expand Down Expand Up @@ -147,11 +148,12 @@ connect or disconnect the account.
const connectToSnap = async () => {
if (typeof provider !== "undefined" && provider.isMetaMask) {
try {
// Request permission to access the Snap
await provider.request({           // Or window.ethereum if you don't support EIP-6963.
method: "wallet_requestSnaps",
params: { [STARKNET_SNAP_ID]: {} }
});
// Request permission to access the Snap.
await provider // Or window.ethereum if you don't support EIP-6963.
.request({
method: "wallet_requestSnaps",
params: { [STARKNET_SNAP_ID]: {} }
});
setIsConnected(true);
fetchAccount();
} catch (err) {
Expand All @@ -171,15 +173,16 @@ connect or disconnect the account.
const fetchAccount = async () => {
if (typeof provider !== "undefined" && provider.isMetaMask) {
try {
const response = await provider.request({           // Or window.ethereum if you don't support EIP-6963.
method: "wallet_invokeSnap",
params: {
snapId: STARKNET_SNAP_ID,
request: {
method: "starknet_recoverAccounts"
const response = await provider // Or window.ethereum if you don't support EIP-6963.
.request({
method: "wallet_invokeSnap",
params: {
snapId: STARKNET_SNAP_ID,
request: {
method: "starknet_recoverAccounts"
}
}
}
});
});

if (response && response.length > 0) {
setAccountAddress(response[0].address);
Expand Down Expand Up @@ -240,7 +243,7 @@ const invokeStarknetContract = async () => {

const contractAddress = "0xYourContractAddress"; // Replace with your contract address.
const entrypoint = "function_name"; // The function you want to call.
const calldata = [/* your function arguments */]; // Replace with calldata
const calldata = [/* your function arguments */]; // Replace with calldata.

const result = await starknet.account.execute({
contractAddress: contractAddress,
Expand Down Expand Up @@ -272,24 +275,25 @@ const invokeStarknetContract = async () => {
}
];

const result = await provider.request({           // Or window.ethereum if you don't support EIP-6963.
method: "wallet_invokeSnap",
params: {
snapId: "npm:@consensys/starknet-snap",
request: {
method: "starkNet_executeTxn",
params: {
address: "0xb60e8dd61c5d32be8058bb8eb970870f07233155", // The sender's address.
calls: calls, // The array of calls with entrypoint and calldata.
details: {
nonce: 1, // Optional nonce.
maxFee: "1000000000000000", // Maximum gas fee allowed.
},
chainId: "0x534e5f5345504f4c4941" // Starknet Sepolia testnet chain ID
const result = await provider // Or window.ethereum if you don't support EIP-6963.
.request({
method: "wallet_invokeSnap",
params: {
snapId: "npm:@consensys/starknet-snap",
request: {
method: "starkNet_executeTxn",
params: {
address: "0xb60e8dd61c5d32be8058bb8eb970870f07233155", // The sender's address.
calls: calls, // The array of calls with entrypoint and calldata.
details: {
nonce: 1, // Optional nonce.
maxFee: "1000000000000000", // Maximum gas fee allowed.
},
chainId: "0x534e5f5345504f4c4941" // Starknet Sepolia testnet chain ID.
}
}
}
}
});
});

console.log("Transaction result: ", result);
} catch (error) {
Expand Down Expand Up @@ -375,15 +379,16 @@ Use the following component at the top level of your dapp to handle account chan
const fetchAccount = async () => {
if (typeof provider !== "undefined" && provider.isMetaMask) {
try {
const response = await provider.request({           // Or window.ethereum if you don't support EIP-6963.
method: "wallet_invokeSnap",
params: {
snapId: STARKNET_SNAP_ID,
request: {
method: "starknet_recoverAccounts"
const response = await provider // Or window.ethereum if you don't support EIP-6963.
.request({
method: "wallet_invokeSnap",
params: {
snapId: STARKNET_SNAP_ID,
request: {
method: "starknet_recoverAccounts"
}
}
}
});
});

if (response && response.length > 0) {
setAccount(response[0].address);
Expand Down
Loading
Loading