Skip to content

Commit

Permalink
RPC Metamask buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusWentz committed Jun 28, 2023
1 parent 7dc91ca commit 212098b
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
async function ConnectToSepolia() {
if (!window.ethereum) {
alert("Metamask not detected! Install Metamask then try again.")
return;
}
if (window.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)
}
}

type Props = {
buttonText: string;
};

export default function ConnectToSepoliaComponent(props: Props) {
return (
<div
onClick={() => ConnectToSepolia()}
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}
Click to Connect to Sepolia
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
async function ConnectToTaikoAlpha3() {
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: "ETH",
symbol: "eth",
decimals: 18,
},
rpcUrls: ["https://rpc.test.taiko.xyz"],
blockExplorerUrls: ["https://explorer.test.taiko.xyz/"],
iconUrls: [],
};

if (!window.ethereum) {
alert("Metamask not detected! Install Metamask then try again.")
return;
}
if (window.ethereum.networkVersion == 167005) {
alert("You are already connected to Taiko Alpha 3 (chainId 167005).", )
return;
}
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)
}
}

type Props = {
buttonText: string;
};

export default function ConnectToTaikoAlpha3Button(props: Props) {
return (
<div
onClick={() => ConnectToTaikoAlpha3()}
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}
Click to Connect to Taiko Alpha 3
</div>
);
}
53 changes: 0 additions & 53 deletions packages/website/components/NetworkButton1.tsx

This file was deleted.

8 changes: 6 additions & 2 deletions packages/website/pages/docs/reference/rpc-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## Sepolia

import NetworkButton1 from 'components/NetworkButton1';
import ConnectToSepolia from 'components/MetamaskNetworkButton/ConnectToSepolia';

<NetworkButton1 />
<ConnectToSepolia />

| Name | Value |
| ------------------ | ---------------------------- |
Expand All @@ -15,6 +15,10 @@ import NetworkButton1 from 'components/NetworkButton1';

## Taiko

import ConnectToTaikoAlpha3 from 'components/MetamaskNetworkButton/ConnectToTaikoAlpha3';

<ConnectToTaikoAlpha3 />

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

0 comments on commit 212098b

Please sign in to comment.