This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: integrate "Add to MetaMask" buttons for zkSync networks (#1004
) Co-authored-by: hsyndeniz <huseyin.deniz1@hotmail.com> Co-authored-by: 吕大卫 <dawei.lv@matrixport.com> Co-authored-by: Antonio <tonioufa@gmail.com>
- Loading branch information
1 parent
cd41088
commit ee55390
Showing
3 changed files
with
69 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<template> | ||
<button type="button" class="add-network" @click="addNetwork"> | ||
<img width="18" src="/images/metamask_logo.svg" alt="Metamask"> | ||
Add {{ chainName }} | ||
</button> | ||
</template> | ||
|
||
<script setup> | ||
const props = defineProps(['network']) | ||
const {network} = props | ||
const chainName = props.network === 'mainnet' ? 'zkSync Era Mainnet' : 'zkSync Era Sepolia Testnet' | ||
function addNetwork() { | ||
const config = { | ||
mainnet: { | ||
chainId: '0x144', | ||
rpcUrls: ['https://mainnet.era.zksync.io'], | ||
blockExplorerUrls: ['https://explorer.zksync.io/'], | ||
}, | ||
testnet: { | ||
chainId: '0x12c', | ||
rpcUrls: ['https://sepolia.era.zksync.dev'], | ||
blockExplorerUrls: ['https://sepolia.explorer.zksync.dev/'], | ||
}, | ||
}[network]; | ||
window.ethereum.request({ | ||
method: 'wallet_addEthereumChain', | ||
params: [ | ||
{ | ||
chainId: config.chainId, | ||
chainName: chainName, | ||
nativeCurrency: {name: 'Ethereum', symbol: 'ETH', decimals: 18}, | ||
iconUrls: ['https://docs.zksync.io/favicon-32x32.png'], | ||
rpcUrls: config.rpcUrls, | ||
blockExplorerUrls: config.blockExplorerUrls, | ||
}, | ||
], | ||
}); | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.add-network { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 4px 8px; | ||
gap: 4px; | ||
cursor: pointer; | ||
} | ||
img[src*="/images/metamask_logo.svg"] { | ||
content: url("/images/metamask_logo.svg"); | ||
} | ||
</style> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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