<a href="https://chrome.google.com/webstore/detail/tronlink/ibnejdfjmmkpcnlpebklmnkoeoihofec" target="_blank">TronLink</a>, similar to MetaMask, is a bridge for allowing TRON DApps to run in the browser without having to deploy a TRON Full Node. If a user has TronLink already installed in the Chrome extension, then TronLink injects a version of TronWeb into every browser page. This allows for the web DApp to interact with the TRON network. Let's learn it with a simple example:
Of course, tronweb has many [functions](🔗) waiting for you to use.
In the process of completing the transaction, tronweb needs to let tronlink perform the signature. Here tronlink rewrites the signature. The signature process is completed in tronlink, and then the signed transaction is returned to tronweb for broadcasting. Let's learn it with a simple example:
When the code is executed to `
tronweb.trx.sign (tx)`, TronLink will pop up a window to confirm the signature.
Now, I believe you have been able to complete TronWeb function calls in conjunction with TronLink.
# TronLink events
TronLink currently supports sidechains and mainchains. Developers can detect the event message sent by TronLink in DAPP, what we can learn from this event message contain the sidechain or mainchain currently selected by TronLink, and which account is currently selected. Let's learn it with a simple example.
The above code involves three events: tabReply, setAccount, and setNode. The following are the triggering scenarios of these events:
|Column Title||Column Title|
|The completing TronLink initialization(after page load)||tabReply|
|Main chain and side chain switching in TronLink:||setAccount、setNode|
|Setting nodes in TronLink||setAccount、setNode|
Before the DAPP page is loaded, you can judge the data.message.data.data.node.chain field of the tabReply event to determine whether TronLink chose the side chain or the main chain when the page was loaded. If it is '_', it means the main chain. , Otherwise it is the side chain, and the number of the side chain represented by chain, the number of each side chain is unique.
After the DAPP page is loaded, you can judge the data.message.data.data.node.chain field of the setNode event to determine whether the user manually selected the side chain or the main chain in TronLink. If it is '_', it means the main chain , Otherwise it is the side chain, and the number of the side chain represented by chain, the number of each side chain is unique.
MainChain` is selected, the node in the returned message event is the selected network.
DAppChain` is selected, the node in the returned message event is the selected network.
Actually, when calling the functions, for the main chain and side chain, it can be called according to the method,because [SunWeb](🔗) inherits [Tronweb](🔗).
When the `
Shasta` test network is selected, the node in the returned message event is the selected network.