Skip to content

Commit

Permalink
Automatically pull chain id
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Electron committed Nov 28, 2023
1 parent 88bd75b commit b582d00
Show file tree
Hide file tree
Showing 4 changed files with 424 additions and 5 deletions.
5 changes: 3 additions & 2 deletions docs/build/getting-started/networks-endpoints.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ keywords:
---

import { AddToMetaMaskButton, EVMNetworks } from '@theme/AddToMetaMaskButton';
import { GetChainId } from '@theme/GetChainId';

# Networks & Endpoints

Expand Down Expand Up @@ -57,7 +58,7 @@ Mainnet.

| Base Token | Protocol | Chain ID | RPC URL | Explorer |
| ------------- | --------- | -------- | ----------------------------------------------------------------------------- | ------------------------------------ |
| Shimmer Token | ISC / EVM | 148 | https://json-rpc.evm.shimmer.network or wss://ws.json-rpc.evm.shimmer.network | https://explorer.evm.shimmer.network |
| Shimmer Token | ISC / EVM | <GetChainId url='https://json-rpc.evm.shimmer.network'/> | https://json-rpc.evm.shimmer.network or wss://ws.json-rpc.evm.shimmer.network | https://explorer.evm.shimmer.network |

## Public Testnet

Expand Down Expand Up @@ -86,7 +87,7 @@ This network is subject to occasional resets (no data retention) which are usual

| Base Token | Protocol | Chain ID | RPC URL | Faucet | Explorer |
| ------------------------- | --------- | -------- | -------------------------------------------- | ------------------------------------------ | -------------------------------------------- |
| Testnet Tokens (no value) | ISC / EVM | 1073 | https://json-rpc.evm.testnet.shimmer.network | https://evm-faucet.testnet.shimmer.network | https://explorer.evm.testnet.shimmer.network |
| Testnet Tokens (no value) | ISC / EVM | <GetChainId url='https://json-rpc.evm.testnet.shimmer.network'/> | https://json-rpc.evm.testnet.shimmer.network | https://evm-faucet.testnet.shimmer.network | https://explorer.evm.testnet.shimmer.network |

## DevNet

Expand Down
3 changes: 2 additions & 1 deletion theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"@metamask/providers": "^10.2.1",
"clsx": "^1.2.1",
"html-react-parser": "^4.2.2",
"react-markdown": "6"
"react-markdown": "6",
"web3": "^4.2.2"
},
"devDependencies": {
"@docusaurus/types": "2.4.1",
Expand Down
26 changes: 26 additions & 0 deletions theme/src/theme/GetChainId/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { useEffect, useState } from 'react';
import { Web3 } from 'web3';

interface GetChainIdProps {
url: string;
}

export function GetChainId(props: GetChainIdProps) {
const [chainId, setChainId] = useState<bigint | null>(null);
const [error, setError] = useState<Error | null>(null);

console.log(props.url);

useEffect(() => {
const web3 = new Web3(props.url);
web3.eth.getChainId().then(setChainId).catch(setError);
}, []);

console.log(chainId);
return (
<>
{chainId !== null && <span>{chainId.toString()}</span>}
{error !== null && <span>Error: {error.message}</span>}
</>
);
}
Loading

0 comments on commit b582d00

Please sign in to comment.