Comments (4)
`import type { AddEthereumChainParameter } from '@web3-react/types'
const ETH: AddEthereumChainParameter['nativeCurrency'] = {
name: 'Ether',
symbol: 'ETH',
decimals: 18,
}
const LAVA: AddEthereumChainParameter['nativeCurrency'] = {
name: 'Lava',
symbol: 'LAVA',
decimals: 18,
}
const MATIC: AddEthereumChainParameter['nativeCurrency'] = {
name: 'Matic',
symbol: 'MATIC',
decimals: 18,
}
const CELO: AddEthereumChainParameter['nativeCurrency'] = {
name: 'Celo',
symbol: 'CELO',
decimals: 18,
}
interface BasicChainInformation {
urls: string[]
name: string
}
interface ExtendedChainInformation extends BasicChainInformation {
nativeCurrency: AddEthereumChainParameter['nativeCurrency']
blockExplorerUrls: AddEthereumChainParameter['blockExplorerUrls']
}
function isExtendedChainInformation(
chainInformation: BasicChainInformation | ExtendedChainInformation
): chainInformation is ExtendedChainInformation {
return !!(chainInformation as ExtendedChainInformation).nativeCurrency
}
export function getAddChainParameters(chainId: number): AddEthereumChainParameter | number {
const chainInformation = CHAINS[chainId]
if (isExtendedChainInformation(chainInformation)) {
return {
chainId,
chainName: chainInformation.name,
nativeCurrency: chainInformation.nativeCurrency,
rpcUrls: chainInformation.urls,
blockExplorerUrls: chainInformation.blockExplorerUrls,
}
} else {
return chainId
}
}
const getInfuraUrlFor = (network: string) =>
process.env.infuraKey ? https://${network}.infura.io/v3/${process.env.infuraKey}
: undefined
const getAlchemyUrlFor = (network: string) =>
process.env.alchemyKey ? https://${network}.alchemyapi.io/v2/${process.env.alchemyKey}
: undefined
type ChainConfig = { [chainId: number]: BasicChainInformation | ExtendedChainInformation }
export const MAINNET_CHAINS: ChainConfig = {
1: {
urls: [getInfuraUrlFor('mainnet'), getAlchemyUrlFor('eth-mainnet'), 'https://cloudflare-eth.com'].filter(Boolean),
name: 'Mainnet',
},
10: {
urls: [getInfuraUrlFor('optimism-mainnet'), 'https://mainnet.optimism.io'].filter(Boolean),
name: 'Optimism',
nativeCurrency: ETH,
blockExplorerUrls: ['https://optimistic.etherscan.io'],
},
42161: {
urls: [getInfuraUrlFor('arbitrum-mainnet'), 'https://arb1.arbitrum.io/rpc'].filter(Boolean),
name: 'Arbitrum One',
nativeCurrency: ETH,
blockExplorerUrls: ['https://arbiscan.io'],
},
137: {
urls: [getInfuraUrlFor('polygon-mainnet'), 'https://polygon-rpc.com'].filter(Boolean),
name: 'Polygon Mainnet',
nativeCurrency: MATIC,
blockExplorerUrls: ['https://polygonscan.com'],
},
42220: {
urls: ['https://forno.celo.org'],
name: 'Celo',
nativeCurrency: CELO,
blockExplorerUrls: ['https://explorer.celo.org'],
},
1339: {
urls: ['https://rpc.elysiumchain.tech'],
name: 'Elysium Mainnet',
nativeCurrency: LAVA,
blockExplorerUrls: ['https://blockscout.elysiumchain.tech/'],
},
}
export const TESTNET_CHAINS: ChainConfig = {
5: {
urls: [getInfuraUrlFor('goerli')].filter(Boolean),
name: 'Görli',
},
420: {
urls: [getInfuraUrlFor('optimism-goerli'), 'https://goerli.optimism.io'].filter(Boolean),
name: 'Optimism Goerli',
nativeCurrency: ETH,
blockExplorerUrls: ['https://goerli-explorer.optimism.io'],
},
421613: {
urls: [getInfuraUrlFor('arbitrum-goerli'), 'https://goerli-rollup.arbitrum.io/rpc'].filter(Boolean),
name: 'Arbitrum Goerli',
nativeCurrency: ETH,
blockExplorerUrls: ['https://testnet.arbiscan.io'],
},
80001: {
urls: [getInfuraUrlFor('polygon-mumbai')].filter(Boolean),
name: 'Polygon Mumbai',
nativeCurrency: MATIC,
blockExplorerUrls: ['https://mumbai.polygonscan.com'],
},
44787: {
urls: ['https://alfajores-forno.celo-testnet.org'],
name: 'Celo Alfajores',
nativeCurrency: CELO,
blockExplorerUrls: ['https://alfajores-blockscout.celo-testnet.org'],
},
1338: {
urls: ['https://rpc.atlantischain.network'],
name: 'Elysium Testnet',
nativeCurrency: LAVA,
blockExplorerUrls: ['https://elysium-explorer-blockscout.vulcanforged.com/'],
},
}
export const CHAINS: ChainConfig = {
...MAINNET_CHAINS,
...TESTNET_CHAINS,
}
export const URLS: { [chainId: number]: string[] } = Object.keys(CHAINS).reduce<{ [chainId: number]: string[] }>(
(accumulator, chainId) => {
const validURLs: string[] = CHAINS[Number(chainId)].urls
if (validURLs.length) {
accumulator[Number(chainId)] = validURLs
}
return accumulator
},
{}
)
`
from web3-react.
Added chain.ts file above
from web3-react.
The issue is that the optional chains runs the default validations, to fix this for now just modify the code to include the regular chains with the defaults, IMO this is actually a bug in wallet connect
const [mainnet] = Object.keys(MAINNET_CHAINS).map(Number)
const [...optionalChains] = Object.keys(MAINNET_CHAINS).map(Number)
from web3-react.
I solved the same issue.
new WalletConnectV2({
actions,
options: {
projectId: '',
chains: [],
showQrModal: true,
rpcMap: { []: '' }. <------- Please check that you add rpcMap which is omitted in the example.
}
})
from web3-react.
Related Issues (20)
- Type 'WalletConnect' does not satisfy the constraint 'Connector' HOT 3
- Carte coinbase
- Compatibility Issue with @web3-react/walletconnect-v2 and Latest Versions of Next.js and React
- When using WalletConnect v2 provider getSigner seems to be going to the v1 API HOT 1
- Issue activating walletconnect v2: this.events.off is not a function HOT 2
- Issues with having ethers 6 and web3-react side by side HOT 1
- Coinbase Connecting Issue
- Module parse failed: Unexpected token walletconnect-v2 HOT 1
- Create Fork
- @mousewifhat, kind reminder: please pay fee: **500 TWT** with the memo **27116** to the address `bnb158fgd782we4tz9vwwcj9pmmxvxhl6z46lfm7c8`.
- How to connect Trezor wallet using web3-react v8
- How can I get provider url from connected wallet? HOT 2
- Why is `connector.deactivate` always undefined? HOT 1
- **The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)
- Walletconect v2 chains not supported
- V3-core
- TypeError: Object(...) is not a function (WalletConnectV2) HOT 1
- How can I sign a transaction using web3-react library?
- dotnet add package dotnetstandard-bip39 --version 1.0.2
- Something happend with intendation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web3-react.