-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Website docs RPC connect Metamask click button
- Loading branch information
1 parent
e6a7945
commit 2efb8a4
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
packages/website/components/MetamaskNetworkButton/ConnectToSepolia.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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) | ||
} | ||
} | ||
|
||
type Props = { | ||
buttonText: string; | ||
}; | ||
|
||
export default function ConnectToSepoliaButton(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> | ||
); | ||
} |
60 changes: 60 additions & 0 deletions
60
packages/website/components/MetamaskNetworkButton/ConnectToTaikoAlpha3.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 as any).ethereum) { | ||
alert("Metamask not detected! Install Metamask then try again.") | ||
return; | ||
} | ||
if ((window as any).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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters