Skip to content

Commit

Permalink
Udhay/add to metamask button (#98)
Browse files Browse the repository at this point in the history
* add to metamask button added

* discord link fixed
  • Loading branch information
udhaykumarbala authored Jan 14, 2025
1 parent 679074a commit 90d1ba1
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/run-a-node/testnet-information.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
---
sidebar_position: 3
---

import MetaMaskButton from '@site/src/components/MetaMaskButton';

# Testnet Information
---

Welcome to Testnet-V2, where you can contribute to our network by operating various node types, including Validator, Storage, and DA (Data Availability) nodes. This page provides an overview of the testnet process and important information for participants.

<MetaMaskButton />

## 0G Testnet Configuration

Summary Table
Expand Down
2 changes: 1 addition & 1 deletion docs/run-a-node/validator-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ For the testnet, due to stress testing with a large number of transactions, a fu
0gchaind keys add <key_name> --eth
0gchaind keys unsafe-export-eth-key <key_name>
```
**8. Acquire Testnet Tokens:** Obtain testnet tokens from the 0G faucet from our [website](https://faucet.0g.ai) or by requesting them on their [Discord](disord/0glabs). These tokens are necessary for staking and becoming a validator.
**8. Acquire Testnet Tokens:** Obtain testnet tokens from the 0G faucet from our [website](https://faucet.0g.ai) or by requesting them on their [Discord](https://discord.com/invite/0glabs). These tokens are necessary for staking and becoming a validator.

**9. Become a Validator:** Register your node as a validator on the 0G network, specifying your stake amount, commission rates, and other important parameters.

Expand Down
76 changes: 76 additions & 0 deletions src/components/MetaMaskButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from 'react';

declare global {
interface Window {
ethereum?: any;
}
}

export default function MetaMaskButton(): JSX.Element {
const getChainID = (networkId: string): string => {
return '0x' + parseInt(networkId).toString(16);
};

const addNetwork = async () => {
if (typeof window.ethereum === 'undefined') {
alert('MetaMask is not installed! Please install MetaMask first.');
return;
}

const currentChainId = await window.ethereum.request({ method: 'eth_chainId' });
if (currentChainId === getChainID('16600')) {
alert('0G Testnet is already added!');
return;
}

const params = [{
chainId: getChainID('16600'),
chainName: '0G-Newton-Testnet',
nativeCurrency: {
name: 'A0GI',
symbol: 'A0GI',
decimals: 18
},
rpcUrls: ['https://evmrpc-testnet.0g.ai'],
blockExplorerUrls: ['https://chainscan-newton.0g.ai/']
}];

try {
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params
});
alert('Network added successfully');
} catch (error) {
alert('Failed to add network');
console.error(error);
}
};

return (
<div style={{ margin: '20px 0' }}>
<button
onClick={addNetwork}
style={{
backgroundColor: '#1fa588',
color: 'white',
padding: '10px 20px',
border: 'none',
borderRadius: '5px',
cursor: 'pointer',
fontSize: '16px',
fontWeight: 'bold',
display: 'inline-flex',
alignItems: 'center',
gap: '10px'
}}>
<img
src="https://raw.githubusercontent.com/MetaMask/brand-resources/master/SVG/SVG_MetaMask_Icon_Color.svg"
alt="MetaMask Fox"
style={{ height: '18px' }}
/>
Add 0G Testnet
</button>
</div>
);
}

0 comments on commit 90d1ba1

Please sign in to comment.