> ## Documentation Index
> Fetch the complete documentation index at: https://layerswaplabsv0-babgev-deposit-actions-guide.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Tron

> Execute deposit transactions on Tron for TRC-20 token transfers.

## Overview

Tron deposits require building a TRC-20 token transfer transaction using TronWeb, then appending the `call_data` as hex-encoded data before signing and broadcasting.

**Prerequisites:**

* [tronweb](https://github.com/tronprotocol/tronweb) for transaction building and RPC communication

**Supported networks:** Tron Mainnet, Tron Testnet (Shasta/Nile)

## call\_data Format

For Tron, `call_data` is a **plain string** (a memo identifier). It is converted to hex and embedded in the transaction data field:

```javascript theme={null}
const hexData = Buffer.from(callData).toString("hex");
```

This hex data is appended to the transaction using TronWeb's `addUpdateData` method, which Layerswap uses to identify and match the deposit.

## Full Example

The `Server-side` tab signs with a raw private key. The `Browser` tab uses a Tron wallet adapter (TronLink, etc.) and its `signTransaction` method.

<CodeGroup>
  ```typescript Server-side theme={null}
  import { TronWeb } from "tronweb";

  async function executeTronDeposit(
    depositAction: any,
    senderAddress: string,
    privateKey: string
  ) {
    const { call_data, to_address, amount, token, network } = depositAction;

    const tronWeb = new TronWeb({
      fullNode: network.node_url,
      solidityNode: network.node_url,
      privateKey,
    });

    const amountInBaseUnits = Math.floor(
      amount * Math.pow(10, token.decimals)
    );

    // Build the TRC-20 transfer via smart contract
    const { transaction: initialTransaction } =
      await tronWeb.transactionBuilder.triggerSmartContract(
        token.contract,
        "transfer(address,uint256)",
        {
          feeLimit: 100_000_000, // 100 TRX fee limit
        },
        [
          { type: "address", value: to_address },
          { type: "uint256", value: amountInBaseUnits },
        ],
        senderAddress
      );

    // Append call_data as hex data
    const hexData = Buffer.from(call_data).toString("hex");
    const transaction = await tronWeb.transactionBuilder.addUpdateData(
      initialTransaction,
      hexData,
      "hex"
    );

    // Sign and broadcast
    const signedTransaction = await tronWeb.trx.sign(transaction);
    const result = await tronWeb.trx.sendRawTransaction(signedTransaction);

    if (result.result) {
      return signedTransaction.txID;
    }

    throw new Error("Transaction broadcast failed");
  }
  ```

  ```typescript Browser theme={null}
  import { TronWeb } from "tronweb";

  async function executeTronDeposit(
    depositAction: any,
    senderAddress: string,
    signTransaction: (tx: any) => Promise<any>
  ) {
    const { call_data, to_address, amount, token, network } = depositAction;

    const tronWeb = new TronWeb({
      fullNode: network.node_url,
      solidityNode: network.node_url,
    });

    const amountInBaseUnits = Math.floor(
      amount * Math.pow(10, token.decimals)
    );

    const { transaction: initialTransaction } =
      await tronWeb.transactionBuilder.triggerSmartContract(
        token.contract,
        "transfer(address,uint256)",
        { feeLimit: 100_000_000 },
        [
          { type: "address", value: to_address },
          { type: "uint256", value: amountInBaseUnits },
        ],
        senderAddress
      );

    const hexData = Buffer.from(call_data).toString("hex");
    const transaction = await tronWeb.transactionBuilder.addUpdateData(
      initialTransaction,
      hexData,
      "hex"
    );

    // Sign using the wallet adapter
    const signedTransaction = await signTransaction(transaction);
    const result = await tronWeb.trx.sendRawTransaction(signedTransaction);

    if (result.result) {
      return signedTransaction.txID;
    }

    throw new Error("Transaction broadcast failed");
  }
  ```
</CodeGroup>

## Funding via the Depository

The example above covers the standard transfer flow. If you created the swap with `use_depository: true`,
the deposit action targets Layerswap's on-chain [Depository](/api-reference/depository) contract. On Tron
the Depository supports **TRC-20 tokens only** — approve the contract, then call `depositERC20`:

```ts TronWeb theme={null}
import { TronWeb } from "tronweb";

// `swap` is the POST /api/v2/swaps response; PRIVATE_KEY signs the deposit
const action = swap.deposit_actions[0];
const [id, , receiverHex, amountHex] = action.encoded_args; // [id, token, receiver, amount]
const amount = BigInt(amountHex).toString();

const tronWeb = new TronWeb({
  fullNode: action.network.node_url,
  solidityNode: action.network.node_url,
  privateKey: PRIVATE_KEY,
});
const sender = tronWeb.defaultAddress.base58;

// encoded_args carry EVM-style hex addresses — convert the receiver to a Tron address
const receiver = tronWeb.address.fromHex("41" + receiverHex.replace(/^0x/, ""));

// 1) Approve the Depository (to_address) to spend the TRC-20 amount
const approveTx = (
  await tronWeb.transactionBuilder.triggerSmartContract(
    action.token.contract, // TRC-20 token (base58)
    "approve(address,uint256)",
    { feeLimit: 100_000_000 },
    [
      { type: "address", value: action.to_address },
      { type: "uint256", value: amount },
    ],
    sender,
  )
).transaction;
await tronWeb.trx.sendRawTransaction(await tronWeb.trx.sign(approveTx));

// 2) Call depositERC20(bytes32 id, address token, address receiver, uint256 amount)
//    on the Depository (wait for the approval to confirm first)
const depositTx = (
  await tronWeb.transactionBuilder.triggerSmartContract(
    action.to_address, // Depository contract (base58)
    "depositERC20(bytes32,address,address,uint256)",
    { feeLimit: 100_000_000 },
    [
      { type: "bytes32", value: id },
      { type: "address", value: action.token.contract },
      { type: "address", value: receiver },
      { type: "uint256", value: amount },
    ],
    sender,
  )
).transaction;
await tronWeb.trx.sendRawTransaction(await tronWeb.trx.sign(depositTx));
```

See [Choosing a method](/api-reference/deposit-actions/choosing-a-method) for when to use each.

## Next Step

After the transaction is submitted, notify Layerswap so it can match your deposit faster:

```bash theme={null}
curl -X POST https://api.layerswap.io/api/v2/swaps/{swap_id}/deposit_speedup \
  -H "X-LS-APIKEY: your_api_key" \
  -H "Content-Type: application/json" \
  -d '{ "transaction_id": "YOUR_TX_HASH" }'
```

See the [full deposit flow](/api-reference/deposit-actions/overview) for details, or the [Depository](/api-reference/depository) guide to fund via the on-chain contract (`use_depository`, TRC-20 tokens).
