WalletConnect / walletconnect-monorepo

WalletConnect Monorepo
Apache License 2.0
1.3k stars 650 forks source link

@walletconnect/ethereum-provider bug #4334

Closed xqingWong closed 5 months ago

xqingWong commented 6 months ago

Describe the bug Using the @walletconnect/ethereum-provider plugin, version 2.11.2 Create the provider: EthereumProvider.init({ ... methods: ['eth_sendTransaction', 'personal_sign', 'wallet_switchEthereumChain'] }) But when calling the wallet_switchEthereumChain method, I get the error 'w5.startsWith is not a function'

SDK Version (if relevant)

Desktop (please complete the following information):

Additional context Can't quite figure out what's wrong.

xqingWong commented 6 months ago

Modified to: EthereumProvider.init({ ... optionalMethods: ['eth_sendTransaction', 'personal_sign', 'wallet_switchEthereumChain'] })

Calling the wallet_switchEthereumChain method gives an error: w4.startsWith is not a function

rouzwelt commented 5 months ago

I get the same error, did you figure out anything? @xqingWong

glitch-txs commented 5 months ago

please share a minimal reproducible example + steps to reproduce. Thanks!

xqingWong commented 5 months ago

demo: import { ref } from 'vue' import { EthereumProvider } from '@walletconnect/ethereum-provider'

const provider = ref() async function getProvider () { provider.value = await EthereumProvider.init({ projectId: 'you projectId', showQrModal: true, optionalChains: [ 11155111, 421611, 42161, 1 ], optionalMethods: ['eth_sendTransaction', 'personal_sign', 'wallet_switchEthereumChain'] }) } getProvider()

async function changeChain () { try { await provider.value.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: 1 }] }) console.log('success') } catch (err) { console.log('err:', err) } }

setTimeout(() => { changeChain() }, 60000)

Please run the demo to check the issue. The changeChain function needs to be executed after establishing the WalletConnect connection @glitch-txs

xqingWong commented 4 months ago

@rouzwelt await provider.value.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: ’0x1‘ }] })
Use the hexadecimal chain ID of the blockchain.