# Referrals

Integrator guide for using a referral code and checking/claiming referral fees.

## Get a code

Referral codes are issued by Liquid Labs. Request your code from the team on Discord.

## Ref code format

`refCode` is a `bytes32` hash, not a plain text string.

It should be the keccak256 hash of your issued code text (for example, hash `"mycode"` and pass that `bytes32` value on-chain).

Example in ethers:

```typescript
import { keccak256, toUtf8Bytes } from "ethers";

const refCode = keccak256(toUtf8Bytes("your-issued-code"));
```

## Use your code in swaps

Router and pool both support the referral swap overload:

```solidity
swap(tokenIn, tokenOut, amountIn, minAmountOut, refCode)
```

* Keep your normal execution flow the same (`minAmountOut`, approvals, quote/estimate checks).
* Use your issued `refCode` as the 5th parameter.

## Check and claim referral fees

The core referral functions are available on the **router** — pass the token pair and the router resolves the pool automatically.

### Via the router (recommended)

```solidity
function getRefClaimable(address tokenA, address tokenB, bytes32 refCode)
    external view returns (uint256 amount0, uint256 amount1)

function claimRefFees(address tokenA, address tokenB, bytes32 refCode)
    external returns (uint256 amount0, uint256 amount1)

function distributeRefFees() external
```

* `getRefClaimable` — check currently claimable amounts per pool token.
* `claimRefFees` — claim accrued fees for a specific ref code. Must be called by the configured claim wallet for that code.
* `distributeRefFees` — batch-distributes all pending referral fees across all pools. Iterates over every registered ref code and pays out accrued fees to each code's configured claim wallet. Anyone can call this.

### Via pool contracts (alternative)

`getRefClaimable` and `claimRefFees` are also available directly on pool contracts (without the `tokenA`/`tokenB` pair parameters). See the [Contract Reference](/liquidcore-integration/api-reference.md#direct-pool-interface) for pool-level signatures.


---

# 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.liqd.ag/liquidcore-integration/referrals.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.
