TronLink Docs
Homepage
  • Introduction
  • HD Wallets
  • TronLink App
    • Asset Management
      • Custom Token
    • DeepLink
      • Open Wallet
      • Open DApp
      • Login by TronLink
      • Transfer
      • Sign Transaction
      • Sign Message
      • Result Code
    • DApp Support
      • TronLink Integration
      • DApp Explorer
  • TronLink Wallet Extension
    • Request TronLink Extension
      • Connect Website
      • Add Token
    • Receive messages from TronLink
      • Account Change Message
      • Network Change Message
      • Successful connection message
      • Disconnect website message
      • Messages to Be Deprecated
        • User rejects connection
        • User disconnects from the website
        • User accepts connection
        • User requests to connect to the website
  • DApp
    • Start Developing
    • Multi-Signature Transfer
    • Message Signature
    • General Transfer
    • Stake2.0
Powered by GitBook
On this page
  1. DApp

Message Signature

Overview

DApp requires users to sign a hex message. The signed message will be forwarded to the back-end to verify whether a user's login is legitimate.

Prerequisite

The DApp sends a request asking the user to connect the wallet to the website, and the user approves to the connection.

Specification

Example

if (window.tronLink.ready) {
  const tronweb = tronLink.tronWeb;
  try {
    const message = "0x1e"; // any hex string
    const signedString = await tronweb.trx.sign(message);
  } catch (e) {}
}

Parameters

“tronLink.tronWeb.trx.sign” accepts a hexadecimal string as the parameter. The string represents the content to be signed.

Returns

If the user chooses to sign in the pop-up window, the DApp will get the signed hexadecimal string. For example:

0xaa302ca153b10dff25b5f00a7e2f603c5916b8f6d78cdaf2122e24cab56ad39a79f60ff3916dde9761baaadea439b567475dde183ee3f8530b4cc76082b29c341c

If an error occurs, the following information will be returned:

Uncaught (in promise) Invalid transaction provided

Interaction

If the user chooses “Reject” in the pop-up window, an exception will be thrown, which the developer can catch for further processing.

PreviousMulti-Signature TransferNextGeneral Transfer

Last updated 2 years ago

When “tronweb.trx.sign(message);” is executed, a pop-up window will show in the TronLink wallet asking the user to confirm, as shown below. The message content will be in hex: