HomeGuidesAPI ReferenceChangelog
GuidesAPI ReferenceCommunityDiscordBlogFAQBug BountyAnnouncementsChange Log
Guides

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

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']
    }
  }
});

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