> 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-solana.md).

# Signing an Intent for Solana

On Solana, intent approval is performed by **cosigning a prebuilt versioned transaction**.

Blockz returns a hex-encoded Solana transaction generated from the accepted quote and intent parameters. The user signs it locally and submits the signed transaction as the intent approval.

The signature order must be preserved. This ensures the resolver can complete execution using the exact transaction authorized by the user.

Funds remain under user control until execution, and the resolver can only execute what the signed transaction permits.

***

#### **Script to cosign a versioned transaction on Solana:**

```javascript
import { Keypair, VersionedTransaction } from '@solana/web3.js';
import bs58 from 'bs58';

import { HotPotApiClient } from '@hot-pot/hotpot-sdk-ts';
import {
    type CosignApprovalToSign,
    type DepositType,
    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 secretKeyBytes = bs58.decode(privateKey);
    const keypair = Keypair.fromSecretKey(secretKeyBytes);

    // 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 = 4; // Solana mainnet
    const sourceToken = 'So11111111111111111111111111111111111111112'; // WSOL token address
    const destChain = 1; // Ethereum mainnet
    const destToken = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';  // WETH token address on Ethereum
    const amount = 0.01; // Amount in WSOL
    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 = keypair.publicKey.toBase58();
    const userDestinationAddress = destinationAddress;
    const refundAddress = keypair.publicKey.toBase58();

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

    const { transaction } = intentData.params_to_sign as CosignApprovalToSign;

    // Decode hex-encoded transaction from HotPot backend
    const bytes = Uint8Array.from(Buffer.from(transaction, 'hex'));
    // Construct VersionedTransaction
    const tx = VersionedTransaction.deserialize(bytes);
    // Save old signatures that might be overwritten by `tx.sign`
    const signatures = [...tx.signatures];
    tx.sign([keypair]);

    // Adjust signature positions: user's signature must appear at position 1,
    // resolver's signature must appear at position 0,
    // and optionally backend signature must appear at position 2.
    tx.signatures[0] = signatures[0];
    if (tx.signatures[2] !== undefined) {
        tx.signatures[2] = signatures[2];
    }

    const signedApproval: SignedApproval = {
        type: 'cosign',
        signed_data: {
            transaction: Buffer.from(tx.serialize()).toString('hex'),
            user_address: keypair.publicKey.toBase58(),
        },
    };

    // 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);
```
