> For the complete documentation index, see [llms.txt](https://sodex.com/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sodex.com/documentation/for-developers/developers/wealth/referrals.md).

# Referrals

A Wealth referral is a `bytes32` on a **vault** request. It attributes that deposit or redemption to a referral code. Encode it before you submit or sign. Use `bytes32(0)` when no code applies.

This value is not used for SoDEX RWA tokens (`clob`) or CLOB trades. Claim methods (`claimDeposit`, `claimRedeem`, `claimDelayedRedeem`) do not take a referral.

Use the **Referral Code** shown on [sodex.com/referrals](https://sodex.com/referrals). The Wealth API does not return or validate referrals. Encoding checks format only, not whether the code is registered.

## When it is written

The same `bytes32` must appear in:

* Direct `requestDeposit` / `requestRedeem`
* EIP-712 `RequestDeposit` / `RequestRedeem` and the matching `requestDepositOnBehalf` / `requestRedeemOnBehalf` call

Changing the code after signing invalidates the signature. Rebuild and re-sign. To submit `requestDepositOnBehalf` / `requestRedeemOnBehalf` without the user paying gas, use the [Transaction Relayer](/documentation/for-developers/developers/valuechain-evm/relayer.md).

## Encode a referral code

Only a string that is exactly `0x` plus 64 hex characters is a ready `bytes32`. Any other value is a text code: UTF-8, right-padded to 32 bytes. Longer than 32 UTF-8 bytes is invalid. An empty value is `bytes32(0)`.

Install `viem` and save as `referral.mjs`.

```javascript
import { stringToHex, zeroHash } from "viem";

const code = process.env.REFERRAL_CODE ?? "";
let referral;
if (/^0x[0-9a-fA-F]{64}$/.test(code)) {
  referral = code;
} else if (code.startsWith("0x")) {
  throw new Error("Hex referral must be 0x plus exactly 64 hex characters");
} else if (new TextEncoder().encode(code).length > 32) {
  throw new Error("Referral code exceeds 32 UTF-8 bytes");
} else {
  referral = code ? stringToHex(code, { size: 32 }) : zeroHash;
}
console.log(referral);
```

```bash
npm install viem
# Text code from https://sodex.com/referrals (illustrative).
REFERRAL_CODE='ABC' node referral.mjs
# Existing bytes32, passed through unchanged.
REFERRAL_CODE='0x4142430000000000000000000000000000000000000000000000000000000000' node referral.mjs
# No referral.
REFERRAL_CODE='' node referral.mjs
```

The first two commands produce the same `bytes32`. Pass this value into the vault call and, for a signed request, into the EIP-712 message before signing.

Submit and settle with [Vault Lifecycle](/documentation/for-developers/developers/wealth/vault-lifecycle.md). Direct and signed how-tos live there; this page does not broadcast a transaction.

{% content-ref url="/pages/a1uIUuv4ujFrQ0lk4JjC" %}
[Vault Lifecycle](/documentation/for-developers/developers/wealth/vault-lifecycle.md)
{% endcontent-ref %}
