> For the complete documentation index, see [llms.txt](https://utyabswap.gitbook.io/utyabswap-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://utyabswap.gitbook.io/utyabswap-docs/sdk/how-to-swap.md).

# how to swap

{% stepper %}
{% step %}

### Find the Pool

```typescript
import { Asset, Factory, PoolV1 } from "@utyablabs/sdk";

const factory = client.open(Factory.createFromAddress(Factory.FACTORY_ADDRESS));

const tokenAddress = Address.parse("EQAw63ZqLmnwRA77PW07CWIEngwg-eIiysaqZ8IWpUL0nP7a")

const poolAddress = await factory.getPoolAddress({
    asset0: Asset.native(),
    asset1: Asset.token(tokenAddress)
});

const pool = client.open(PoolV1.createFromAddress(poolAddress));
```

{% endstep %}

{% step %}

### Check if the pool is ready

```typescript
import { PoolStatus } from "@utyablabs/sdk";

const status = await pool.getStatus()

if(status !== PoolStatus.Ready) throw new Error("Pool is not ready");
```

{% endstep %}

{% step %}

### Swap

{% code title="TON -> Token" %}

```typescript
// Swap 1 TON
await pool.sendNativeSwap(sender, {
    amount: toNano("1"), // Swap 1 TON
    minOut: 0n, // Minimum amount of tokens to receive
    sender: userAddress,
    referral: null, // Referral address
});
```

{% endcode %}

{% code title="Swap Token -> TON" %}

```typescript
import { JettonMaster } from "@ton/ton";

// Get the wallet address
const master = client.open(JettonMaster.create(tokenAddress));
const walletAddress = await master.getWalletAddress(userAddress);

// Swap 1000 tokens
await pool.sendTokenSwap(sender, {
	sender: userAddress,
	walletAddress: walletAddress,
	jetton_amount: toNano("1000"),
	minOut: 0n,
	referral: null,
	assetIn: Asset.token(tokenAddress),
	assetOut: Asset.native(),
});
```

{% endcode %}
{% endstep %}
{% endstepper %}
