Transfers
This walkthrough covers how to sign transactions through UKey Wallet TRON Provider, broadcast transactions, and use TronWeb for contract interaction.
signature transaction
The following example first constructs the transaction, then requests the UKey Wallet signature, and finally the application manually broadcasts:
// Build transaction
const tx = await tronWeb.transactionBuilder.sendTrx(
"TR7x6W5v4U3t2S1r0Q9p8NmLyKjHgFeDcB",
tronWeb.toSun(10),
tronWeb.defaultAddress.base58,
);
// Sign through the provider
const signedTx = await provider.sign(tx);
console.log("Signed payload:", signedTx);
// Broadcast manually
const callResult = await tronWeb.trx.sendRawTransaction(signedTx);
Smart contract interaction
const contract = await tronWeb.contract().at(contractAddress);
// call the read-only view function
const callResult = await contract.someViewFunction().call();
// 写操作需要签名确认
const tx = await contract.someWriteFunction(param1, param2).send({
feeLimit: 100_000_000, // fee cap: 100 TRX
callValue: 0,
});
Trigger smart contract
const tx = await tronWeb.transactionBuilder.triggerSmartContract(
contractAddress,
"transfer(address,uint256)",
{ feeLimit: 100_000_000 },
[
{ type: "address", value: recipientAddress },
{ type: "uint256", value: amount },
],
tronWeb.defaultAddress.base58,
);
const signedTx = await provider.sign(tx.transaction);
const callResult = await tronWeb.trx.sendRawTransaction(signedTx);
Use SunWeb
SunWeb can be used for DAppChain (side chain) related operations:
const sunWeb = window.sunWeb;
// Move from main chain to side chain
await sunWeb.depositTrx(amount, depositFee, feeLimit);
// Move from side chain to main chain
await sunWeb.withdrawTrx(amount, withdrawFee, feeLimit);