WalletConnect / walletconnect-monorepo

WalletConnect Monorepo
Apache License 2.0
1.46k stars 715 forks source link

How to use `tron ​​network` to `connect wallet`? #3807

Closed hhun closed 1 year ago

hhun commented 1 year ago

@glitch-txs

能不能帮我写一个 Web3Model V3 连接波场网络的例子? Can you help me write an example of connecting Web3Model V3 to the TRON network?

https://react-app.walletconnect.com/ 这个例子太复杂看不懂 https://react-app.walletconnect.com/ This example is too complicated to understand

code

Error reporting: Unsupported chains. connect() requiredNamespaces, chains must be defined as "namespace:chainId" e.g. "eip155:1": {...} in the namespace key OR as an array of CAIP-2 chainIds e.g. eip155: { chains: ["eip155:1", "eip155:5"] }

How to solve this problem?

How to generate client and pairingTopic?

import { ethers } from 'ethers'
import UniversalProvider from '@walletconnect/universal-provider'

const projectId = WALLET_CONNECT_PROJECT_ID

//  Initialize the provider
const provider = await UniversalProvider.init({
    logger: 'info',
    relayUrl: 'wss://relay.walletconnect.com',
    projectId: projectId,
    metadata: {
        name: 'React App',
        description: 'React App for WalletConnect',
        url: 'https://walletconnect.com/',
        icons: ['https://avatars.githubusercontent.com/u/37784886']
    },
    client: undefined // optional instance of @walletconnect/sign-client
})

//  create sub providers for each namespace/chain
await provider.connect({
    namespaces: {
        eip155: {
            chains: ['eip155:1', 'eip155:80001'],
            methods: ['eth_sendTransaction', 'eth_signTransaction', 'eth_sign', 'personal_sign', 'eth_signTypedData'],
            events: ['chainChanged', 'accountsChanged'],
            rpcMap: {
                1: 'https://rpc.walletconnect.com?chainId=eip155:1&projectId=' + projectId,
                80001: 'https://rpc.walletconnect.com?chainId=eip155:80001&projectId=' + projectId
            }
        },
        tron: {
            chains: ['tron:0x2b6653dc'],
            methods: ['tron_signTransaction', 'tron_signMessage'],
            events: [],
            rpcMap: {
                '0x2b6653dc': 'https://api.trongrid.io'
            }
        },
        pairingTopic: '282f083a841ba42b28a126a61f60ba24d2dc0674255e9081271bc25c56f38495', // optional topic to connect to
        skipPairing: false // optional to skip pairing ( later it can be resumed by invoking .pair())
    }
})

//  Create Web3 Provider
const web3Provider = new ethers.providers.Web3Provider(provider)
hhun commented 1 year ago

@glitch-txs @ganchoradkov Is this project being maintained?

ganchoradkov commented 1 year ago

Hey @hhun, please remove these parameters from the namespaces config

pairingTopic: '282f083a841ba42b28a126a61f60ba24d2dc0674255e9081271bc25c56f38495', // optional topic to connect to
skipPairing: false // 

Your config should look like


await provider.connect({
    namespaces: {
        eip155: {
            chains: ['eip155:1', 'eip155:80001'],
            methods: ['eth_sendTransaction', 'eth_signTransaction', 'eth_sign', 'personal_sign', 'eth_signTypedData'],
            events: ['chainChanged', 'accountsChanged'],
            rpcMap: {
                1: 'https://rpc.walletconnect.com?chainId=eip155:1&projectId=' + projectId,
                80001: 'https://rpc.walletconnect.com?chainId=eip155:80001&projectId=' + projectId
            }
        },
        tron: {
            chains: ['tron:0x2b6653dc'],
            methods: ['tron_signTransaction', 'tron_signMessage'],
            events: [],
            rpcMap: {
                '0x2b6653dc': 'https://api.trongrid.io'
            }
        }
    },
        pairingTopic: '282f083a841ba42b28a126a61f60ba24d2dc0674255e9081271bc25c56f38495', // optional topic to connect to
    skipPairing: false // optional to skip pairing ( later it can be resumed by invoking .pair())
})
hhun commented 1 year ago

@ganchoradkov

An error message appears after modifying the code:

Verify iframe failed to load: https://verify.walletconnect.org verify iframe load timeout

No matching key. pairing topic doesn't exist: 282f083a841ba42b28a126a61f60ba24d2dc0674255e9081271bc25c56f38495

And modal will not pop up.

Please help me write a complete example of connecting to the TRON network

code

import { ethers } from 'ethers'
import UniversalProvider from '@walletconnect/universal-provider'

const projectId = WALLET_CONNECT_PROJECT_ID

//  Initialize the provider
const provider = await UniversalProvider.init({
    logger: 'info',
    relayUrl: 'wss://relay.walletconnect.com',
    projectId: projectId,
    metadata: {
        name: 'React App',
        description: 'React App for WalletConnect',
        url: 'https://walletconnect.com/',
        icons: ['https://avatars.githubusercontent.com/u/37784886']
    },
    client: undefined // optional instance of @walletconnect/sign-client
})

//  create sub providers for each namespace/chain
await provider.connect({
    namespaces: {
        eip155: {
            chains: ['eip155:1', 'eip155:80001'],
            methods: ['eth_sendTransaction', 'eth_signTransaction', 'eth_sign', 'personal_sign', 'eth_signTypedData'],
            events: ['chainChanged', 'accountsChanged'],
            rpcMap: {
                1: 'https://rpc.walletconnect.com?chainId=eip155:1&projectId=' + projectId,
                80001: 'https://rpc.walletconnect.com?chainId=eip155:80001&projectId=' + projectId
            }
        },
        tron: {
            chains: ['tron:0x2b6653dc'],
            methods: ['tron_signTransaction', 'tron_signMessage'],
            events: [],
            rpcMap: {
                '0x2b6653dc': 'https://api.trongrid.io'
            }
        }
    },
    pairingTopic: '282f083a841ba42b28a126a61f60ba24d2dc0674255e9081271bc25c56f38495', // optional topic to connect to
    skipPairing: false // optional to skip pairing ( later it can be resumed by invoking .pair())
})

//  Create Web3 Provider
const web3Provider = new ethers.providers.Web3Provider(provider)
ganchoradkov commented 1 year ago

@hhun please update to latest version, there shouldn't error log regarding, just warn, in which case you can ignore it as it don't prevent normal SDK usage.

Verify iframe failed to load: https://verify.walletconnect.org/
verify iframe load timeout

Please help me write a complete example of connecting to the TRON network

which parts are you having difficulties with? WalletConnect v2 is chain agnostic so connecting with any network is the same as say, ethereum(eip155). Are you getting any additional errors? We have web-examples that implement Tron

hhun commented 1 year ago

@ganchoradkov It is because the dapp-example is too complicated to understand, so I would like to trouble you to help me write a simple example of connecting to the TRON network.

salemalem commented 2 weeks ago

@hhun any update? same issue