> For the complete documentation index, see [llms.txt](https://docs.blockz.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.blockz.fi/api/submit-intent/approvals/signing-an-intent-for-tron.md).

# Signing an Intent for Tron

On Tron networks, Blockz uses **Permit2** to authorize execution.

The user signs a Permit2 payload off-chain to grant the resolver permission to move the specified amount into escrow under the intent constraints. This signature is then submitted as an approval for the intent.

Funds remain under user control until execution, and the resolver can only act within the signed parameters.

***

#### **Script to create a Permit2 signature:**

```javascript
import { TronWeb } from 'tronweb';

import { HotPotApiClient } from '@hot-pot/hotpot-sdk-ts';
import { preparePermit2Approval } from '@hot-pot/hotpot-sdk-ts';
import {
    type DepositType,
    type Permit2ApprovalToSign,
    type SignedApproval,
    SwapType,
} from '@hot-pot/hotpot-sdk-ts';

async function main() {
    const apiKey = process.env['API_KEY'];
    const privateKey = process.env['PRIVATE_KEY'];
    const destinationAddress = process.env['DESTINATION_ADDRESS'];

    if (!apiKey) {
        throw new Error('API_KEY environment variable is not set');
    }
    if (!privateKey) {
        throw new Error('PRIVATE_KEY environment variable is not set');
    }
    if (!destinationAddress) {
        throw new Error('DESTINATION_ADDRESS environment variable is not set');
    }

    const tronWeb = new TronWeb({
        fullHost: 'https://api.trongrid.io',
        privateKey: privateKey,
    });

    // Initialize the HotPot API client with the API key from environment variables
    const client = new HotPotApiClient('https://api.hotpot.tech/affiliate', apiKey);

    // Example parameters for getting a quote
    const sourceChain = 2; // Tron mainnet
    const sourceToken = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'; // USDT token address on Tron
    const destChain = 1; // Ethereum mainnet
    const destToken = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; // WETH token address
    const amount = 2; // Amount in USDT
    const slippageBps = 50n; // 0.5% slippage
    const swapType = SwapType.Standard; // Use standard swap type for cross-chain swap
    const depositType: DepositType = 'escrowed'; // Use escrowed deposit (funds will be escrowed in a proxy contract)

    // Get a quote for the swap
    console.log('Getting quote...');
    const quote = await client.getQuote(
        sourceChain,
        sourceToken,
        destChain,
        destToken,
        amount,
        slippageBps,
        swapType,
        null, // retail user id: null or your custom user ID
        depositType,
    );
    console.log('Quote received:', quote);

    // Set user addresses
    const userSourceAddress = tronWeb.address.fromPrivateKey(privateKey);
    const userDestinationAddress = destinationAddress;
    const refundAddress = tronWeb.address.fromPrivateKey(privateKey);
    if (!userSourceAddress || !refundAddress) {
        throw new Error('User source address or refund address is invalid');
    }

    // Create an intent based on the quote
    console.log('Creating intent...');
    const intentData = await client.createIntent(
        quote.id,
        null, // userSourcePublicKey (null for EVM)
        userSourceAddress,
        userDestinationAddress,
        refundAddress,
    );
    console.log('Intent created:', intentData);

    // Prepare the permit2 approval for signing
    const permit2Approval = preparePermit2Approval(
        intentData.params_to_sign as Permit2ApprovalToSign, // Cast to Permit2ApprovalToSign
        quote,
        userSourceAddress,
        intentData.deadline_secs,
    );
    console.log('Permit2 approval prepared:', permit2Approval);

    const signature = tronWeb.trx.signTypedData(
        permit2Approval.domain,
        permit2Approval.types,
        permit2Approval.message,
        privateKey,
    );
    const signedApproval: SignedApproval = {
        type: 'permit2',
        signed_data: signature,
    };

    // Add the approval to the intent
    console.log('Adding approval...');
    await client.addApproval(signedApproval, intentData.intent_id);
    console.log('Approval added');
}

await main()
    .then(() => console.log('Example completed'))
    .catch(console.error);
```
