After setting up your wallet, you can have access to the Tron provider:
// reactconst{providers}=useTomo()const{tronProvider}=providers;// pure jsconsttronProvider=window.tomo_tron
Get Tron Address
the Tron address from the wallet state or provider. In React framework:
// get address from wallet stateconst{walletState}=useTomo()consttronAddress=walletState.tronAddress// or get address from providerconst{providers}=useTomo()consttronAddress=awaitproviders.tronProvider.getAddress()
Or Pure JS:
/** pure js */import{getWalletState}from'@tomo-inc/tomo-web-sdk';// get from wallet stateconstwalletState=getWalletState()consttronAddress=walletState.tronAddress// or get from providerconsttronAddress=awaitwindow.tomo_tron.getAddress()
Provider Functions
Signing a Message
It uses the Tron provider to sign a plain text offchain message, which returns the signature of the given message.
Sign Transaction
To sign a transaction, you need first initiate a client withtronweb for connecting to the network.
Then, create the transaction and sign with our tronProvider . Eventually, you need to send the transaction again through the tronWeb client.
Example
We provide an example of a tron provider as follows:
// interface
signMessage(message: string, privateKey?: string): Promise<string>;
// Social Wallet does not support signing messages currently, will support soon.
const signedMessage = await tronProvider.signMessage('hello world')
let tronWeb: TronWebType | null = null
export async function getTronWeb() {
if (tronWeb) return tronWeb
const {
default: { TronWeb }
} = await import('tronweb')
tronWeb = new TronWeb({
fullHost:
'https://orbital-dimensional-season.tron-mainnet.quiknode.pro/d14878573fe23f8f40621a303ee2eaa3c812ba1c'
})
return tronWeb as TronWebType
}