Background Script

The background script is where all the actual wallet functionality takes place. It’s an essential script that manages a persistent state while the browser is running. It receives a request for confirmation from the website and sends it to the user to be displayed.

The background script also manages the private keys of the users, which are encrypted and safely stored. This could be considered the Backend of the extension.

Page Hook

The page hook is what connects the TronLink extension to the website. It provides an API that gets injected into the page, enabling it to ask the user to sign transactions, call smart contracts, send TRX to a certain address, or even cast votes.

It also comes with utility functions that makes life easier for developers.

Here are the currently available API methods:

Node

getLastestBlock()

getWitnesses()

getTokens()

getBlock(blockID)

getTransaction(transactionID)

getAccount(address)

Wallet

sendTron(recipient, amount)

sendAsset(recipient, amount, assetID)

sendTransaction(transaction)

signTransaction(transaction)

simulateSmartContract(address, data)

getAccount()

createSmartContract(options)

triggerSmartContract(options)

Utils

validateAddress(input)

sunToTron(sun)

tronToSun(tron)

Below is an example which asks the user to send 5000 SUN to an address:

let response = await window.TronLink.v1().sendTrx(“TDGmmTC7xDgQGwH4FYRGuE7SFH2MePHYeH”, 5000);

If you have the extension installed, you can test it here: https://tronwatch.github.io/TronLink-Examples/

We are currently waiting for the TRON developers to add HTTP service endpoints for smart contract related methods to java-tron. This allows us to completely move away from protobufs, improving many aspects of our extension.

The next step for the API is to make it fully web3 compatible.

Popup

The popup is what the user interacts with. It provides wallet functionality, and is used to present the user with confirmation requests from websites.

Its written in Reactjs and should be fairly straightforward to understand.

On a Final Note

While we encourage users to test out and play around with the extension, please keep in mind that TronLink is still in active development. We are running on a private TestNet for the time being, and because of that, we recommend users to be very careful when handling transactions.

For help with integration, or if you just want to get involved, we would like to invite everyone to join us in our Telegram: https://t.me/TronWatch.

If you find any bugs, have feature requests, or would like to leave a comment, please open an issue in our TronLink Github repository.