> ## Documentation Index
> Fetch the complete documentation index at: https://docs.compasslabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create an Account

> Deploy a user's product account with one transaction. The address comes back right away and is the same on every chain.

Before a user can deposit, borrow or trade, they need a [product account](/v2/Products/Accounts) for that product on that chain. One call to the product's `create_account` endpoint returns the account address and a transaction that deploys the account.

This works the same way in Earn, Credit and Tokenized Assets. Perpetual Trading doesn't use a product account.

| Product | Endpoint | Address field |
| - | - | - |
| Earn | [`POST /v2/earn/create_account`](/v2/api-reference/earn/create-earn-account) | `earn_account_address` |
| Credit | [`POST /v2/credit/create_account`](/v2/api-reference/credit/create-credit-account) | `credit_account_address` |
| Tokenized Assets | [`POST /v2/tokenized_assets/create_account`](/v2/api-reference/tokenized-assets/create-account) | `tokenized_assets_account_address` |

## Request

Create an Earn Account on Base, with the user paying gas:

<CodeGroup>
  ```python Python theme={"system"}
  import httpx

  response = httpx.post(
      "https://api.compasslabs.ai/v2/earn/create_account",
      json={
          "chain": "base",
          "owner": "0xYourWalletAddress",
          "sender": "0xYourWalletAddress",
      },
      headers={"x-api-key": "YOUR_API_KEY"},
  )
  result = response.json()

  # result["earn_account_address"]: the account address, the same on every chain
  # result["transaction"]: unsigned tx that deploys the account (null if it already exists)
  ```

  ```typescript TypeScript theme={"system"}
  const response = await fetch(
    "https://api.compasslabs.ai/v2/earn/create_account",
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "x-api-key": "YOUR_API_KEY",
      },
      body: JSON.stringify({
        chain: "base",
        owner: "0xYourWalletAddress",
        sender: "0xYourWalletAddress",
      }),
    }
  );
  const result = await response.json();

  // result.earn_account_address: the account address, the same on every chain
  // result.transaction: unsigned tx that deploys the account (null if it already exists)
  ```
</CodeGroup>

| Field | Description |
| - | - |
| `owner` | The user's wallet. It becomes the account's only owner. |
| `sender` | The wallet that signs and sends the deployment transaction and pays its gas: the owner, or your own wallet if you sponsor it. |
| `chain` | The chain to deploy on. Required for Earn and Credit. Tokenized Assets defaults to `ethereum`. |

## Response

```json theme={"system"}
{
  "earn_account_address": "0xYourEarnAccountAddress",
  "transaction": {
    "chainId": "0x2105",
    "from": "0xYourWalletAddress",
    "to": "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67",
    "data": "0x1688f0b9...",
    "value": "0x0",
    "gas": "0xf4240",
    "nonce": "0x7",
    "maxFeePerGas": "0x1c9c380",
    "maxPriorityFeePerGas": "0x186a0"
  }
}
```

| Field | Description |
| - | - |
| `earn_account_address` | The account's address. It's returned before the account is deployed, and it's the same on every chain. Credit and Tokenized Assets return `credit_account_address` and `tokenized_assets_account_address` instead. |
| `transaction` | An unsigned transaction that deploys the account, with numbers as hex strings. It's `null` if the account already exists on this chain. |

## Sign and send

The `sender` signs `transaction` and sends it to the chain. Creation is a single transaction: once it's confirmed, the account is ready to [fund](/v2/account-lifecycle/fund-account). There's no pending state to poll.

## Who pays for deployment

| | Set `sender` to | What happens |
| - | - | - |
| **The user pays** | The owner's address | The user signs and sends the transaction from their wallet. |
| **You pay** | Your sponsor wallet | Your wallet signs and sends the transaction and pays the gas. The user doesn't sign anything, and they're still the account's only owner. |

## Good to know

* **Safe to call every time.** If the account already exists on that chain, you get the same address and `transaction: null`. You can call `create_account` whenever a user opens the product and skip the transaction when it's `null`.
* **One account per product.** The same wallet gets a different address for Earn, Credit and Tokenized Assets.
* **Deploy once per chain.** The address is the same everywhere, but the account has to be deployed on each chain where the user uses it.
* **Create before anything else.** Credit and Tokenized Assets endpoints return `400` (`Credit Account not deployed` or `Tokenized Assets Account not deployed`) until the account exists on that chain.

## Next

<Card title="Fund an Account" icon="arrow-right" href="/v2/account-lifecycle/fund-account">
  Move tokens from the user's wallet into their new account.
</Card>
