> For the complete documentation index, see [llms.txt](https://docs.aqua.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aqua.network/developers/code-examples/prerequisites-and-basics.md).

# Prerequisites & basics

Install the official Aquarius SDK and set up its client — prerequisites, network presets, signers, assets, trustlines, amounts, and transaction fees used across the code examples.

Every code example uses the [official SDKs](https://docs.aqua.network/developers/integrating-with-aquarius.md#official-sdks) (0.6.0 or later). This page covers what the examples need and the client setup they share.

### Prerequisites

Before executing scripts, install the Aquarius SDK:

{% tabs %}
{% tab title="Python" %}

* **Python 3.10+**: the SDK requires Python version 3.10 or higher.
* **Aquarius SDK**: install via pip. It installs the Stellar SDK (`stellar-sdk` 17) as a dependency:

```bash
pip install "aquarius-sdk>=0.6.0"
```

{% endtab %}

{% tab title="JavaScript" %}

* **Node.js 22.12+**: the SDK requires Node.js version 22.12 or higher.
* **Aquarius SDK** with its peer dependency, the Stellar SDK (`@stellar/stellar-sdk` 17.4 or a later 17.x): install via npm or yarn.

```bash
npm install "@aquariusdefi/sdk@>=0.6.0" @stellar/stellar-sdk@^17.4.0
```

or

```bash
yarn add "@aquariusdefi/sdk@>=0.6.0" @stellar/stellar-sdk@^17.4.0
```

{% endtab %}
{% endtabs %}

The examples that submit transactions also need the secret key of a funded Stellar account: it pays the swap or deposit amounts, the transaction fees, and the reserve of each new trustline. On [testnet](https://docs.aqua.network/developers/testing-on-testnet.md), `fund_with_friendbot()` (`fundWithFriendbot()` in JavaScript) creates and funds the signer's account, as in the [Quickstart](https://docs.aqua.network/developers/quickstart.md).

### Constants

The SDK carries a preset for each network: the router address, the Backend API URL, the Soroban RPC and Horizon endpoints, and the network passphrase. The code examples use these presets and define no constants of their own. Read the preset values from the SDK as shown below; the canonical contract addresses are listed in [Addresses & networks](https://docs.aqua.network/developers/reference/addresses-and-networks.md).

#### For mainnet

{% tabs %}
{% tab title="Python" %}

```python
from aquarius import NETWORKS

mainnet = NETWORKS["mainnet"]
print(mainnet.router)        # the AMM router contract
print(mainnet.api_url)       # the Backend API
print(mainnet.rpc_url)       # Soroban RPC
print(mainnet.horizon_url)   # Horizon
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { NETWORKS } from "@aquariusdefi/sdk";

const mainnet = NETWORKS.mainnet;
console.log(mainnet.router);       // the AMM router contract
console.log(mainnet.apiUrl);       // the Backend API
console.log(mainnet.rpcUrl);       // Soroban RPC
console.log(mainnet.horizonUrl);   // Horizon
```

{% endtab %}
{% endtabs %}

#### For testnet

{% tabs %}
{% tab title="Python" %}

```python
from aquarius import NETWORKS

testnet = NETWORKS["testnet"]
print(testnet.router)        # the AMM router contract
print(testnet.api_url)       # the Backend API
print(testnet.rpc_url)       # Soroban RPC
print(testnet.horizon_url)   # Horizon
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { NETWORKS } from "@aquariusdefi/sdk";

const testnet = NETWORKS.testnet;
console.log(testnet.router);       // the AMM router contract
console.log(testnet.apiUrl);       // the Backend API
console.log(testnet.rpcUrl);       // Soroban RPC
console.log(testnet.horizonUrl);   // Horizon
```

{% endtab %}
{% endtabs %}

Testnet assets have their own issuers: the testnet AQUA issuer differs from the mainnet one. See [Testing on testnet](https://docs.aqua.network/developers/testing-on-testnet.md).

{% hint style="info" %}
**API versions:** the presets use `v2` of the Backend API. Version `v1` remains available and is identical except for one endpoint — see [Backend API](https://docs.aqua.network/developers/reference/backend-api.md).
{% endhint %}

### Create a client

A client is bound to one network: `"mainnet"` or `"testnet"`, and uses that network's [preset](#constants). Pass a signer to submit transactions; reads and quotes work without one:

{% tabs %}
{% tab title="Python" %}

```python
from stellar_sdk import Keypair
from aquarius import AquariusClient

reader = AquariusClient(network="mainnet")                                   # reads and quotes only
aqua = AquariusClient(network="mainnet", signer=Keypair.from_secret("S..."))  # reads and writes

print(aqua.network.router)   # the AMM router of this network
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { Keypair } from "@stellar/stellar-sdk";
import { AquariusClient } from "@aquariusdefi/sdk";

const reader = new AquariusClient({ network: "mainnet" });                                  // reads and quotes only
const aqua = new AquariusClient({ network: "mainnet", signer: Keypair.fromSecret("S...") }); // reads and writes

console.log(aqua.network.router);   // the AMM router of this network
```

{% endtab %}
{% endtabs %}

The examples use mainnet. Each one runs on [testnet](https://docs.aqua.network/developers/testing-on-testnet.md) with `network="testnet"` and the testnet asset issuer; every address is listed in [Addresses & networks](https://docs.aqua.network/developers/reference/addresses-and-networks.md). To use your own infrastructure, pass `rpc_url`, `horizon_url`, or `api_url` (`rpcUrl`, `horizonUrl`, `apiUrl` in JavaScript).

### Signers

A Stellar SDK `Keypair` works as a signer as-is. To sign in a wallet, a hardware device, or a separate service, pass any object that exposes the account's public key and signs a transaction envelope:

* **Python:** a `public_key` attribute and `sign(tx_xdr) -> str`, which returns the signed envelope XDR.
* **JavaScript:** `publicKey()` and `sign(txXdr)`, which returns the signed envelope XDR or a promise of it.

**Multisig accounts.** The authorization the SDK builds uses source-account credentials, so the envelope signatures cover it and the account's signature thresholds apply as for any Stellar transaction. The signer's public key is the multisig account:

* **All required keys in one process:** add every required signature inside your signer's `sign` and return the envelope with all of them.
* **Signatures collected separately:** build the transaction unsigned, collect the signatures, and submit it yourself. In JavaScript liquidity writes and swap quotes have a `build*` twin that returns the simulated, unsigned envelope XDR (for example `pool.buildDeposit` or `quote.buildTransaction`). In Python a swap quote has `build_transaction()`; other writes sign through the signer. If pool state changes while signatures are collected — another deposit into the same pool, for example — the transaction fails; build it again.

`ensure_trustline` / `ensureTrustline` and `fund_with_friendbot` / `fundWithFriendbot` always sign through the signer and have no unsigned form.

The SDK builds the authorization for every call it signs on the client, from the exact arguments of the call; [Contract authorization](https://docs.aqua.network/developers/reference/contract-authorization.md) describes the pattern.

### Assets

`XLM` is the native asset. Classic assets take a code and an issuer; Soroban tokens take a contract ID. `contract_id` returns an asset's contract address on a network:

{% tabs %}
{% tab title="Python" %}

```python
from aquarius import Asset, XLM

AQUA = Asset.classic("AQUA", "GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA")
token = Asset.contract("C...")   # a Soroban token known only by contract ID

print(XLM.contract_id(aqua.network.passphrase))    # CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA on mainnet
print(AQUA.contract_id(aqua.network.passphrase))
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { Asset, XLM } from "@aquariusdefi/sdk";

const AQUA = Asset.classic("AQUA", "GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA");
const token = Asset.contract("C...");   // a Soroban token known only by contract ID

console.log(XLM.contractId(aqua.network.passphrase));   // CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA on mainnet
console.log(AQUA.contractId(aqua.network.passphrase));
```

{% endtab %}
{% endtabs %}

The SDK sorts token vectors for the contracts, so the examples pass assets in any order.

### Trustlines

An account holds a classic asset only through a trustline, and only the account itself can open one. `ensure_trustline` creates the trustline on the signer's account when it has none and does nothing otherwise. It cannot open a trustline for another address, such as a swap recipient — that account opens its own:

{% tabs %}
{% tab title="Python" %}

```python
aqua.ensure_trustline(AQUA)
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
await aqua.ensureTrustline(AQUA);
```

{% endtab %}
{% endtabs %}

Each trustline raises the account's minimum XLM balance; see [Stellar essentials](https://docs.aqua.network/ecosystem-overview/stellar-essentials.md).

### Amounts

Every amount is an integer in the token's base units: stroops for classic assets, where 1 token is 10,000,000 stroops (10^7). Python uses `int`; JavaScript uses `bigint`, so `10_0000000n` is 10 tokens.

### Transaction fees

`base_fee` (`baseFee` in JavaScript, default 100,000 stroops) is your inclusion-fee bid. On top of it, every Soroban transaction declares a resource fee from simulation, raised by `resource_fee_headroom` (default 50%), and its declared CPU instructions are raised by `instruction_headroom` (default 25%). The declared resource fee is a cap: the network refunds the part a transaction does not use. The source account must hold the full declared fee before the transaction executes.

### Get pool contract ID and pool hash

A pool's contract address and pool hash are listed in the pool details on its [pool page](https://aqua.network/pools/CCY2PXGMKNQHO7WNYXEWX76L2C5BH3JUW3RCATGUYKY7QQTRILBZIFWV/) in the Aquarius app:

<figure><img src="https://3649863591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5QUy59hBUnouBhx8gNSS%2Fuploads%2FzdSycir12RGRr2vOIAY9%2Fimage.png?alt=media&amp;token=2c1bbe3e-ce7a-4dcb-b036-bb5ef56047dd" alt="Pool details with the Pool hash row and the highlighted Pool address row, each with a copy icon"><figcaption><p>The copy icon next to Pool address copies the contract address.</p></figcaption></figure>

To find pools programmatically, see [Get pools info](https://docs.aqua.network/developers/code-examples/get-pools-info.md).
