本页目录
交易
先连接 provider,并使用同一钱包对应的 TronWeb 实例。将省略的地址和合约方法替换为有效值。准备交易前,检查所选网络。
了解如何在 TRON 上签署和发送交易。
签署交易
签署交易但不广播:
// Build transaction
const tx = await tronWeb.transactionBuilder.sendTrx(
'TRecipientAddress...',
tronWeb.toSun(10),
tronWeb.defaultAddress.base58
)
// Sign via provider
const signedTx = await provider.sign(tx)
console.log('Signed transaction:', signedTx)
// Broadcast manually
const result = await tronWeb.trx.sendRawTransaction(signedTx)智能合约交互
const contract = await tronWeb.contract().at(contractAddress)
// Read (view function)
const result = await contract.someViewFunction().call()
// Write (requires signing)
const tx = await contract.someWriteFunction(param1, param2).send({
feeLimit: 100_000_000, // 100 TRX
callValue: 0,
})触发智能合约
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 result = await tronWeb.trx.sendRawTransaction(signedTx)使用 SunWeb
用于 DappChain(侧链)操作:
const sunWeb = window.sunWeb
// Main chain to side chain
await sunWeb.depositTrx(
amount,
depositFee,
feeLimit
)
// Side chain to main chain
await sunWeb.withdrawTrx(
amount,
withdrawFee,
feeLimit
)最后更新于