# Tron

Tronlink dapp (opens new window).

# installed or not

const isSafePalInstalled = window.SafePalHook && window.tronWeb;
1

# get platform

const plaform = window.sfpPlatform;
1

If dapp is opened in SafePal App, the platform is "iOS" or "Android", if dapp is opened in PC brower, the platform is "ext"

In the SafePal App, the connection is automatic and no connection method needs to be called.

# extension plaform connect

# tron_requestAccounts(request authorization to connect)

try {
  await SafePalHook.request({ method: 'tron_requestAccounts' });
  const address = SafePalHook.defaultAddress.base58;
  const balance = await tronWeb.trx.getBalance(address);
} catch {}
1
2
3
4
5

# connected

  window.tronWeb.ready;
1

# sign transaction

  const transaction = xxx; // build transaction here 
  const result = await window.tronWeb.trx.sign(transaction);
1
2

# sign message

  const message = "Hello, World!"; // for sign text message
  const result = await window.tronWeb.trx.sign(message);
1
2