Skip to content

Commit

Permalink
Edit Manage networks, API reference, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandratran committed Sep 20, 2024
1 parent baa2b16 commit f6f30a2
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 126 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
description: Create a basic dapp using `get-starknet` and React TypeScript
description: Create a simple dapp using `get-starknet` and React TypeScript.
sidebar_position: 6
---

# Create a basic dapp with `get-starknet`
# Create a simple Starknet dapp

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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ sidebar_position: 3

# Manage Starknet networks

You can manage network interactions in your Starknet dapp.
You can detect a user's Starknet network and prompt them to switch Starknet networks in MetaMask.
The following examples use the [`get-starknet`](https://github.com/starknet-io/get-starknet) library.

## Detect a user's network

## Detect the user's network

You can detect the network a user is currently connected to using the following:
Detect the Starknet network a user is currently connected to using the following:

```javascript
const checkCurrentNetwork = () => {
Expand All @@ -21,31 +21,22 @@ const checkCurrentNetwork = () => {
};
```

## Switch between networks

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.

You can allow users to switch between different Starknet networks by setting the appropriate chain ID.

Starknet has two official networks:

| Network | Chain ID (Hexadecimal) |
|---------|------------------------|
| Mainnet | `0x534e5f4d41494e` |
| Sepolia testnet | `0x534e5f5345504f4c4941` |
## Switch networks

The following code example enables switching by setting the appropriate chain ID.
Starknet currently supports two public networks, Mainnet and Sepolia testnet.
Prompt users to switch between networks by setting the
[chain ID](../../../reference/non-evm-apis/starknet-snap-api.md#supported-networks) of the target network:

```javascript
const switchChain = async (chainId: string) => {
try {
await wallet?.request({
type: "wallet_switchStarknetChain",
params: { chainId: chainId },
});
console.log(`Switched to chainId: ${chainId}`);
} catch (e) {
console.error("Failed to switch chain:", e);
}
try {
await wallet?.request({
type: "wallet_switchStarknetChain",
params: { chainId: chainId },
});
console.log(`Switched to chainId: ${chainId}`);
} catch (e) {
console.error("Failed to switch chain:", e);
}
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ After an account is connected, you can sign a transaction using the `wallet.acco
const signStarknetTransaction = async (wallet, contractAddress, entrypoint, calldata) => {
try {
if(wallet?.isConnected !== true){
throw('Wallet not connected');
throw("Wallet not connected");
}

// Send the transaction
Expand All @@ -20,9 +20,9 @@ const signStarknetTransaction = async (wallet, contractAddress, entrypoint, call
entrypoint: entrypoint, // The function to call in the contract
calldata: calldata // The parameters to pass to the function
});
console.log('Transaction signed successfully:', result);
console.log("Transaction signed successfully:", result);
return result;
} catch (error) {
console.error('Error signing transaction:', error);
console.error("Error signing transaction:", error);
}
};
Loading

0 comments on commit f6f30a2

Please sign in to comment.