# Receive

The `receive` operation is used to declare that your account expects to receive a certain token or asset from another account. It’s commonly used in swaps and other multi-party interactions where one party commits to sending something, and the other defines what they want in return.

This operator is added to a transaction using a `builder` and is usually paired with a corresponding `send` operation.

## When to Use

* Declaring part of a **swap** (e.g., “I send X, and expect to receive Y”)
* Defining expected incoming tokens or assets in a contract
* Building conditional transactions where value is exchanged

## How it works

When performing a swap, the `send()` operation defines what your account is giving, and the `receive()` operation defines what you expect in return.

You create a transaction using both operations, then **compute** the block — but **don’t publish it**. The resulting unsigned block is meant to be sent to the counterparty (e.g. via QR, API, or message).

They can then **verify, sign, and publish** the transaction on-chain. Once published with signatures, the swap is finalized.

```typescript
const signer = KeetaNet.lib.Account.fromSeed(DEMO_ACCOUNT_SEED, 0);
const client = KeetaNet.UserClient.fromNetwork('test', signer);

// Addresses
const recipient = KeetaNet.lib.Account.fromPublicKeyString('<recipient-address>');
const sendToken = KeetaNet.lib.Account.fromPublicKeyString('<abc-token-address>');
const receiveToken = KeetaNet.lib.Account.fromPublicKeyString('<xyz-token-address>');

// Amounts (assumes you’ve already fetched decimals and validated)
const sendAmount = Numeric.fromDecimalString("10.0", 2);     // 10 ABC
const receiveAmount = Numeric.fromDecimalString("5.0", 2);   // 5 XYZ

// Create transaction
const builder = client.initBuilder();

builder.send(recipient, sendAmount.valueOf(), sendToken);
builder.receive(recipient, receiveAmount.valueOf(), receiveToken, true);

// Compute the transaction block (not yet published)
const { blocks } = await client.computeBuilderBlocks(builder);

// This unsigned block can now be signed and published by the other party
const unsignedBytes = blocks[0].toBytes();

console.log("📦 Unsigned swap block ready for signature:", unsignedBytes);
```

## Signature Flow:

* You (Party A) compute the transaction with `send()` and `receive()`.
* You send the **unpublished block** to Party B (e.g., over API or QR code).
* Party B verifies it, signs it, and publishes the transaction to KeetaNet.
* Done — the atomic swap is complete!

{% hint style="warning" %}
You **must not publish** the block yourself if you're expecting a counterparty to sign it. The final publish should be done by the party who agrees to the trade — typically the one **receiving the assets**.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeta.com/components/blocks/operations/receive.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
