WalletConnect-TRON

What is walletconnect-tron

walletconnect-tron helps DApp to connect with the WalletConnect TRON Chain.

Get Started

Installation

You can install @tronweb3/walletconnect-tron with npm/yarn/pnpm.

npm i @tronweb3/walletconnect-tron
//or
yarn add @tronweb3/walletconnect-tron

Create WalletConnect Wallet

Request Parameters

ArgumentDescriptionType
networkThe Chain (Mainnet, Shasta, Nile)string
optionsThe options Info of the walletobject
web3ModalConfigThe options for Web3Modal[object](https://docs.walletconnect.com/2.0/web/web3modal/html/wagmi/options)
interface WalletConnectWalletAdapterConfig {
  network: WalletConnectChainID;
  options: SignClientTypes.Options;
  /**
   * Config for web3Modal constructor.
   * Detailed documentation can be found in WalletConnect page:
   * https://docs.walletconnect.com/2.0/web3modal/options.
   * - `walletConnectVersion` will be ignored and will be set to 2.
   * - `projectId` will be ignored and will be set with `options.projectId`.
   */
  web3ModalConfig?: WalletConnectWeb3ModalConfig;
}
enum WalletConnectChainID {
  Mainnet = 'tron:0x2b6653dc',
  Shasta = 'tron:0x94a9059e',
  Nile = 'tron:0xcd8690dc'
}

Example

import { WalletConnectWallet, WalletConnectChainID } from '@tronweb3/walletconnect-tron';
const wallet = new WalletConnectWallet({
  network: WalletConnectChainID.Mainnet,
  options: {
    relayUrl: 'wss://relay.walletconnect.com',
    projectId: '....',
    metadata: {
      name: 'JustLend',
      description: 'JustLend WalletConnect',
      url: 'https://app.justlend.org/',
      icons: ['https://app.justlend.org/mainLogo.svg']
    }
  },
  web3ModalConfig: {
    themeMode: 'dark',
    themeVariables: {
      '--w3m-z-index': 1000
    },
    /**
     * Recommended Wallets are fetched from WalletConnect explore api:
     * https://walletconnect.com/explorer?type=wallet&version=2.
     * You can copy these ids from the page.
     */ 
    explorerRecommendedWalletIds: [
      '1ae92b26df02f0abca6304df07debccd18262fdf5fe82daa81593582dac9a369',
      '4622a2b2d6af1c9844944291e5e7351a6aa24cd7b23099efac1b2fd875da31a0'
    ]
  }
});

Connect to the Wallet

Use wallet.connect() to connect to your wallet. Your DApp will connect automatically, if it has been connected before. Otherwise, a WalletConnect QRCode will be displayed.

Response

Return the wallet address if connected.

Example

const { address } = await wallet.connect();

Disconnect to the Wallet

Use wallet.disconnect() to disconnect to your wallet.

Example

try {
  await wallet.disconnect();
} catch (error) {
  console.log('disconnect:' + error);
}

Sign Transaction

Sign a provided transaction object

Request Parameters

ArgumentDescriptionType
transationTron Transactionobject

Example

try {
  const signature = await wallet.signTransaction(transaction);
} catch (error) {
  console.log('signTransaction:' + error);
}

Sign Message

Sign a String Message

Request Parameters

ArgumentDescriptionType
messagemessagestring

Example

try {
  const signature = await wallet.signMessage('hello world');
} catch (error) {
  console.log('signTransaction:' + error);
}

Check Connect Status

Check the Connect Status

Response

Return the wallet address. If the wallet is not connected, return NULL.

Example

const { address } = await wallet.checkConnectStatus();

Note

Since the connection is based on the relayUrl service, DApp developers should handle network errors, connection errors, and timeout errors properly according to the scenario.

To see all error messages and error codes, refer to WalletConnect Errors.

License

MIT