-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1180 from iotaledger/shimmerevm-connect
Adds ShimmerEVM and Hardhat tutorial
- Loading branch information
Showing
13 changed files
with
488 additions
and
89 deletions.
There are no files selected for viewing
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
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
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
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
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
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 |
---|---|---|
@@ -1,51 +1,69 @@ | ||
import React from 'react'; | ||
import type { MetaMaskInpageProvider } from '@metamask/providers'; | ||
import type {MetaMaskInpageProvider} from '@metamask/providers'; | ||
|
||
declare global { | ||
interface Window { | ||
ethereum?: MetaMaskInpageProvider; | ||
} | ||
interface Window { | ||
ethereum?: MetaMaskInpageProvider; | ||
} | ||
} | ||
|
||
export const EVMNetworks = { | ||
"shimmerevm-testnet": { | ||
chainId: '0x430', | ||
chainName: 'ShimmerEVM Testnet', | ||
nativeCurrency: { | ||
name: 'Shimmer', | ||
symbol: 'SMR', | ||
decimals: 18, // Replace with the number of decimals of the native currency | ||
}, | ||
rpcUrls: ['https://json-rpc.evm.testnet.shimmer.network'], | ||
blockExplorerUrls: [ | ||
'https://explorer.evm.testnet.shimmer.network/', | ||
], | ||
}, | ||
"shimmerevm": { | ||
chainId: '0x94', | ||
chainName: 'ShimmerEVM', | ||
nativeCurrency: { | ||
name: 'Shimmer', | ||
symbol: 'SMR', | ||
decimals: 18, // Replace with the number of decimals of the native currency | ||
}, | ||
rpcUrls: ['https://json-rpc.evm.shimmer.network'], | ||
blockExplorerUrls: [ | ||
'https://explorer.evm.shimmer.network/', | ||
], | ||
} | ||
}; | ||
|
||
interface MetaMaskButtonProps { | ||
cfg: unknown; | ||
} | ||
|
||
export default function AddToMetaMaskButton() { | ||
async function addNetwork() { | ||
if (window.ethereum) { | ||
try { | ||
await window.ethereum.request({ | ||
method: 'wallet_addEthereumChain', | ||
params: [ | ||
{ | ||
chainId: '0x430', // Replace with the chain ID of the network you want to add | ||
chainName: 'ShimmerEVM Testnet', // Replace with the name of the network | ||
nativeCurrency: { | ||
name: 'Shimmer', // Replace with the name of the native currency | ||
symbol: 'SMR', // Replace with the symbol of the native currency | ||
decimals: 18, // Replace with the number of decimals of the native currency | ||
}, | ||
rpcUrls: ['https://json-rpc.evm.testnet.shimmer.network'], // Replace with the RPC URL(s) of the network | ||
blockExplorerUrls: [ | ||
'https://explorer.evm.testnet.shimmer.network/', | ||
], // Replace with the block explorer URL(s) of the network (optional) | ||
}, | ||
], | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
console.log('Error adding network: ' + error.message); | ||
} | ||
} else { | ||
alert( | ||
'MetaMask is not installed. Please install MetaMask and try again.', | ||
); | ||
export function AddToMetaMaskButton(props: MetaMaskButtonProps) { | ||
async function addNetwork() { | ||
if (!window.ethereum) { | ||
alert('MetaMask is not installed. Please install MetaMask and try again.'); | ||
return; | ||
} | ||
|
||
try { | ||
await window.ethereum.request({ | ||
method: 'wallet_addEthereumChain', | ||
params: [props.cfg], | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
console.log('Error adding network: ' + error.message); | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<button | ||
className={`button button--primary button--lg margin-bottom--md`} | ||
onClick={() => addNetwork()} | ||
> | ||
Add to MetaMask | ||
</button> | ||
); | ||
return ( | ||
<button | ||
className={`button button--primary button--md margin-bottom--md`} | ||
onClick={() => addNetwork()} | ||
> | ||
Add to MetaMask | ||
</button> | ||
); | ||
} |
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
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
Oops, something went wrong.