> ## Documentation Index
> Fetch the complete documentation index at: https://docs.yield.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Tron signing

> Parse the TronGrid transaction object and sign it with TronWeb.

On Tron, `unsignedTransaction` is a JSON string of a TronGrid transaction object, the same shape `tronWeb.trx.sign()` expects. Parse it and pass it through unchanged.

## Prerequisites

* An action's `transactions[]`; see [Transaction signing](https://docs.yield.xyz/guides/transaction-signing/index.md) for decoding by chain family and [Enter and exit flows](https://docs.yield.xyz/guides/earn/enter-exit-flows.md) for the request and poll loop.
* `tronweb@^6`. `TronWeb` is a named export in v6 (`import { TronWeb } from "tronweb"`); a default import throws `TronWeb is not a constructor`.
* For native staking, `tronResource` (one of `ENERGY` or `BANDWIDTH`) and `validatorAddresses` (an array) in the enter or exit arguments, alongside `amount`. Confirm exact required fields via `mechanics.arguments.enter.fields` before building the request.

## Parse, sign, and submit

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

const tronWeb = new TronWeb({
  fullHost: "https://api.trongrid.io",
  privateKey: process.env.TRON_PRIVATE_KEY!,
});

for (const tx of transactions) {
  const txData = JSON.parse(tx.unsignedTransaction as string);

  const signedTx = await tronWeb.trx.sign(txData);
  const result = await tronWeb.trx.sendRawTransaction(signedTx);

  if (!result.result) {
    throw new Error(`Tron broadcast rejected: ${result.code} ${result.message ?? ""}`);
  }
  const txid = result.txid;

  // A Tron transaction can be accepted at broadcast but still fail during execution
  // (for example OUT_OF_ENERGY). Poll the receipt before treating it as settled.
  let receiptResult: string | undefined;
  for (let attempt = 0; attempt < 30; attempt++) {
    const info = await tronWeb.trx.getTransactionInfo(txid);
    receiptResult = info?.receipt?.result;
    if (receiptResult) break;
    await new Promise((resolve) => setTimeout(resolve, 3_000));
  }
  if (receiptResult !== "SUCCESS") {
    throw new Error(`Tron tx ${txid} did not succeed: ${receiptResult ?? "not confirmed in time"}`);
  }

  await fetch(`https://api.yield.xyz/v1/transactions/${tx.id}/submit-hash`, {
    method: "PUT",
    headers: { "x-api-key": process.env.YIELD_API_KEY!, "content-type": "application/json" },
    body: JSON.stringify({ hash: txid }),
  });
}
```

## Submit the signed transaction instead

To hand Yield.xyz the signed payload rather than broadcasting yourself, call `POST /v1/transactions/{tx.id}/submit` with `{ "signedTransaction": ... }` instead of `submit-hash`. Use one path per transaction, never both. See [Transaction signing](https://docs.yield.xyz/guides/transaction-signing/index.md#sign-and-choose-a-submission-path) for when each fits.

> [!NOTE]
>
> Tron staking uses BANDWIDTH and ENERGY resources instead of gas, and native staking's unstaking period runs a fixed number of days on-chain; check the yield's own `mechanics.cooldownPeriod` rather than assuming a duration.

## Next steps

> [card] [Transaction signing](https://docs.yield.xyz/guides/transaction-signing/index.md)
>
> The shared contract across chain families: decode, validate, sign, submit.

> [card] [Enter and exit flows](https://docs.yield.xyz/guides/earn/enter-exit-flows.md)
>
> Build the request, branch on executionPattern, and poll to a terminal status.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.