# Creating an AMM Pool

## Create an AMM Pool

Now that the receiver has tokens, we can use the receiver's account to create an AMM. Note that this is the usual architecture where the issuer account solely issues the token, and other proprietary accounts hold the token and can create liquidity.

For this example, we will use pools that have XRP as one side.

Here is the `createAMM.ts` file:

{% code title="createAMM.ts" %}

```javascript
import { AMMCreate } from "xrpl";

export const createAMM = async ({
  issuer,
  receiver,
  client,
  tokenCode,
}: any) => {
  console.log("create AMM", { issuer, receiver, tokenCode });
  let createAmm: AMMCreate = {
    TransactionType: "AMMCreate",
    Account: receiver.address,
    TradingFee: 600,
    Amount: {
      currency: tokenCode,
      issuer: issuer.classicAddress,
      value: "2000000", // 2M tokens
    },
    Amount2: "50000000", // 50 XRP in drops
  };
  console.log(createAmm);

  const prepared = await client.autofill(createAmm);
  const signed = receiver.sign(prepared);
  const result = await client.submitAndWait(signed.tx_blob);

  console.log(result);
  console.log("Create amm tx: ", result.result.hash);

  return;
};

```

{% endcode %}

Putting it all together, the final main function and `index.ts` should now look like this:

{% code title="index.ts" %}

```javascript
import {  Client,  Wallet }  from "xrpl" 
import { createToken } from "./createToken"
import { createAMM } from "./createAMM"
import { convertStringToHexPadded, enableRippling } from "./utils"

const client = new Client("wss://s.altnet.rippletest.net:51233")

// get these from https://xrpl.org/resources/dev-tools/xrp-faucets
const issuerSeed = "s...";
const receiverSeed = "s...;

const issuer = Wallet.fromSeed(issuerSeed);
const receiver = Wallet.fromSeed(receiverSeed);

// edit this to match your vibe
const token = "COOL"

const main = async () => {
  console.log("lets get started...");
  await client.connect();

  // enable ripling
  await enableRippling({ wallet: issuer, client });

  // create Token
  await createToken({
    issuer,
    receiver,
    client,
    tokenCode: convertStringToHexPadded(token),
  });

  // create AMM
  await createAMM({
    issuer,
    receiver,
    client,
    tokenCode: convertStringToHexPadded(token),
  });

  await client.disconnect();

  console.log("all done!");
};

main();


```

{% endcode %}

Don't forget to import `enableRippling`, `createToken`, `createAMM` and `convertStringToHexPadded` if needed.

You can now go to the training website at [https://amm.xrpl.at/](https://trainings.xrpl.at/) and interact with other pools.

You will need to set up Xaman with the **receiver account** you created above. You can use the family seed import route. If you are new to Xaman don't forget to enable developer mode in the advanced settings and then switch to testnet from the home page of the Xaman app.

#### Interact with your pool (swap)

Using the training app, connect and add your public address to the list. When you click a user in the list you can see that account's token holdings.

You can create Trustlines for tokens you have not interacted with yet. You can swap XRP for other tokens where you have trustlines using the pool view's swap feature.

You may need to mint more XRP for your receiver account. That's where the print money function might come in handy.

## Extra credits

**Become a liquidity provider for other pools**

You can become a Liquidity Provider for other pools by using the AMMDeposit function: (<https://xrpl.org/docs/references/protocol/transactions/types/ammdeposit/>)

**Withdraw from pools**

You can also withdraw from pools using your LP tokens by utilizing the AMMWithdraw transaction. (<https://xrpl.org/docs/references/protocol/transactions/types/ammwithdraw/>)


---

# 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.xrpl-commons.org/token-issuance-and-liquidity/creating-an-amm-pool.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.
