Skip to content

Commit

Permalink
Website docs RPC connect Metamask click button
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusWentz committed Jun 29, 2023
1 parent e6a7945 commit b331521
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
87 changes: 87 additions & 0 deletions packages/website/components/MetamaskNetworkButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
type Props = {
buttonText: string;
};

async function ConnectToMetamask(props: Props) {
if (!(window as any).ethereum) {
alert("Wallet not detected! Install Metamask then try again.");
return;
}
if(props.buttonText == "Connect to Sepolia"){
ConnectToSepolia();
}
if(props.buttonText == "Connect to Taiko"){
ConnectToTaiko();
}
}

async function ConnectToSepolia() {
if (!(window as any).ethereum) {
alert("Metamask not detected! Install Metamask then try again.")
return;
}
if ((window as any).ethereum.networkVersion == "11155111") {
alert("You are already connected to Sepolia (chainId 11155111).", )
return;
}
try{
await (window as any).ethereum.request({
method: "wallet_switchEthereumChain",
params: [{
chainId: "0xaa36a7"
}]
});
} catch (error) {
alert("Failed to add the network with wallet_addEthereumChain request. Add the network with https://chainlist.org/ or do it manually. Error log: " + error.message)
}
}

async function ConnectToTaiko() {
if ((window as any).ethereum.networkVersion == "167005") {
alert("You are already connected to Taiko Alpha 3 (chainId 167005).", )
return;
}
interface AddEthereumChainParameter {
chainId: string; // A 0x-prefixed hexadecimal string
chainName: string;
nativeCurrency: {
name: string;
symbol: string; // 2-6 characters long
decimals: 18;
};
rpcUrls: string[];
blockExplorerUrls?: string[];
// iconUrls?: string[]; // Currently ignored.
}
const taikoParams: AddEthereumChainParameter = {
chainId: "0x28c5d",
chainName: "Taiko (Alpha-3 Testnet)",
nativeCurrency: {
name: "Ether",
symbol: "ETH",
decimals: 18,
},
rpcUrls: ["https://rpc.test.taiko.xyz"],
blockExplorerUrls: ["https://explorer.test.taiko.xyz/"],
// iconUrls: [],
};
try{
await (window as any).ethereum.request({
method: "wallet_addEthereumChain",
params: [taikoParams],
});
} catch (error) {
alert("Failed to add the network with wallet_addEthereumChain request. Add the network with https://chainlist.org/ or do it manually. Error log: " + error.message)
}
}

export default function ConnectToMetamaskButton(props: Props) {
return (
<div
onClick={() => ConnectToMetamask(props)}
className="hover:cursor-pointer text-neutral-900 bg-neutral-100 hover:bg-neutral-200 border-solid border-neutral-200 focus:ring-4 focus:outline-none focus:ring-neutral-100 font-medium rounded-lg text-sm px-3 py-2 text-center inline-flex items-center dark:focus:ring-neutral-600 dark:bg-neutral-800 dark:border-neutral-700 dark:text-white dark:hover:bg-neutral-700"
>
{props.buttonText}
</div>
);
}
6 changes: 5 additions & 1 deletion packages/website/pages/docs/guides/configure-your-wallet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ This guide help you connect your wallet to Taiko (Alpha-3 testnet). There are tw
Visit [https://chainlist.org/](https://chainlist.org/) and check the box for "Include Testnets".

### Add the Sepolia testnet
Search for "Sepolia", and click the "Add Chain" button.
Search for "Sepolia", and click the "Add Chain" button.

You can also connect to Sepolia at [Sepolia RPC configuration](../reference/rpc-configuration#sepolia).

### Add the Taiko testnet
Search for "Taiko", and click the "Add Chain" button for Taiko (Alpha-3 testnet).

You can also connect to Taiko at [Taiko RPC configuration](../reference/rpc-configuration#taiko).

### Add tokens to your wallet
Use your wallet (e.g., Metamask) to [import the tokens](https://support.ledger.com/hc/en-us/articles/6375103346077-Add-custom-tokens-to-MetaMask?docs=true) with [this configuration](https://gist.githubusercontent.com/d1onys1us/8f8824daed0882b1094296f824fae53c/raw/taiko_tokens.json) (HORSE, BLL, and TTKO).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import ConnectToMetamask from 'components/MetamaskNetworkButton';

# RPC configuration

## Sepolia

<ConnectToMetamask buttonText={"Connect to Sepolia"} />

| Name | Value |
| ------------------ | ---------------------------- |
| Chain ID | 11155111 |
Expand All @@ -11,6 +15,8 @@

## Taiko

<ConnectToMetamask buttonText={"Connect to Taiko"} />

| Name | Value |
| ------------------ | ------------------------------- |
| Chain ID | 167005 |
Expand Down

0 comments on commit b331521

Please sign in to comment.