Skip to Content
Assetera Docs
Distribution partners

Register a client's wallet

Register a verified client's wallet with Assetera from your own server: get a challenge, have any wallet sign it, send the signature, and wait for approval.

If you sell instruments through Assetera, your site registers each client's delivery wallet. Your server gets a challenge from the Compliance API. The client signs it with the wallet. Your server sends the signature back. Only an approved wallet can receive an instrument. The flow is the same for a browser wallet and for the Assetera Wallet. The calls, statuses and error codes are in the Compliance API reference.

The client must complete KYC first. Until then, the Compliance API refuses the registration with 403 Wallet.KycRequired. Offer "add wallet" only to a verified client.

Who does what

PartDoesNever does
BrowserGets the address, asks the wallet to sign the message, shows the status.Holds an Assetera access token or calls the Compliance API.
Your serverAdds the client's Assetera access token and forwards the three calls. Decides the chain.Uses a machine token, or takes the chain from the browser.
WalletShows the message and returns a personal_sign signature.Calls Assetera. The Assetera Wallet also does not register itself.
Compliance APIChecks the signature, records the wallet for the client, screens it.Accepts a signature from another address.

Before you start

You needWhere it comes from
A signed-in client, with their Assetera access token held on your serverTied-agent walkthrough
A client whose KYC is complete: GET /api/kyc/me/status returns "verified": trueKYC integration
The Compliance API base URL, for example in COMPLIANCE_API_URLAssetera, during partner onboarding
The chain of the instrument you sell, as a CAIP-2 id such as eip155:80002The instrument's market data from the Marketplace API
For the Assetera Wallet: the wallet URL and a listed site originAssetera Wallet

Register the wallet for the chain the instrument is delivered on. A browser wallet shows the network that the client last used, and that is often a different chain.

Step 1: forward the calls from your server

The examples use Next.js route handlers. getClientAccessToken and getInstrumentChain stand for your own session and instrument code.

lib/compliance.ts (server only)
import "server-only";

export async function compliance(accessToken: string, method: "GET" | "POST", path: string, body?: unknown) {
  const response = await fetch(`${process.env.COMPLIANCE_API_URL}${path}`, {
    method,
    headers: {
      authorization: `Bearer ${accessToken}`, // the client's own token
      accept: "application/json",
      ...(body === undefined ? {} : { "content-type": "application/json" }),
    },
    body: body === undefined ? undefined : JSON.stringify(body),
    cache: "no-store",
  });
  return { status: response.status, json: await response.json().catch(() => null) };
}

// Adding a wallet needs completed KYC. Check it before you ask the client to sign.
export async function isVerified(accessToken: string) {
  const { status, json } = await compliance(accessToken, "GET", "/api/kyc/me/status");
  return status === 200 && json?.verified === true;
}
app/api/wallet/challenge/route.ts
import { NextResponse, type NextRequest } from "next/server";
import { compliance, isVerified } from "@/lib/compliance";
import { getClientAccessToken } from "@/lib/session";
import { getInstrumentChain } from "@/lib/instrument";

export async function GET(request: NextRequest) {
  const token = await getClientAccessToken();
  if (!token) return NextResponse.json({ error: "not_signed_in" }, { status: 401 });
  if (!(await isVerified(token))) return NextResponse.json({ error: "Wallet.KycRequired" }, { status: 403 });

  const address = request.nextUrl.searchParams.get("address") ?? "";
  if (!/^0x[0-9a-fA-F]{40}$/.test(address)) return NextResponse.json({ error: "invalid_request" }, { status: 400 });

  const chain = await getInstrumentChain(); // decided here, never by the browser
  const query = new URLSearchParams({ address, chain });
  const { status, json } = await compliance(token, "GET", `/api/wallet/challenge?${query}`);
  if (status !== 200) return NextResponse.json({ error: json?.code ?? "unavailable" }, { status });
  return NextResponse.json({ message: json.message, chain, expiresAt: json.expiresAt });
}
app/api/wallet/route.ts
import { NextResponse, type NextRequest } from "next/server";
import { compliance } from "@/lib/compliance";
import { getClientAccessToken } from "@/lib/session";

type Wallet = { address: string; chain: string; status: string };

// The client's wallets with their status. The browser reads this while a wallet is in review.
export async function GET() {
  const token = await getClientAccessToken();
  if (!token) return NextResponse.json({ error: "not_signed_in" }, { status: 401 });
  const { status, json } = await compliance(token, "GET", "/api/wallet");
  if (status !== 200) return NextResponse.json({ error: json?.code ?? "unavailable" }, { status });
  return NextResponse.json({ wallets: json });
}

// Register a wallet with the message the client signed.
export async function POST(request: NextRequest) {
  const token = await getClientAccessToken();
  if (!token) return NextResponse.json({ error: "not_signed_in" }, { status: 401 });

  const { address, chain, message, signature, connectorId } = await request.json();
  const { status, json } = await compliance(token, "POST", "/api/wallet", {
    address,
    chain,
    proof: { message, signature },
    provider: connectorId === "assetera-wallet" ? "assetera" : "external",
    connectorId: connectorId ?? undefined,
  });
  if (status === 201) return NextResponse.json({ wallet: json }, { status: 201 });

  // The client registered this wallet before: show it, do not report an error.
  if (json?.code === "Wallet.Conflict") {
    const list = await compliance(token, "GET", "/api/wallet");
    const existing = (list.json as Wallet[] | null)?.find(
      (wallet) => wallet.address === String(address).toLowerCase() && wallet.chain === chain,
    );
    if (existing) return NextResponse.json({ wallet: existing });
  }
  // Includes 403 Wallet.KycRequired: the Compliance API checks KYC again at registration.
  return NextResponse.json({ error: json?.code ?? "unavailable" }, { status });
}

Send the browser the code only. The description in an error answer is for your server log. The challenge route checks KYC first and answers with the same code as the Compliance API. The Compliance API still checks KYC on both calls, so the route check is for a clear answer, not for security.

Step 2: sign in the browser

One browser function registers any wallet. It needs an address, a machine id of the wallet software, and a way to sign one text message.

lib/register-wallet.ts (browser)
export interface WalletSigner {
  address: string;
  connectorId: string | null; // for example "io.metamask", or "assetera-wallet"
  signMessage(message: string): Promise<string>; // EIP-191 personal_sign
}

export async function registerWallet(signer: WalletSigner) {
  const challengeResponse = await fetch(`/api/wallet/challenge?address=${encodeURIComponent(signer.address)}`, {
    cache: "no-store",
  });
  const challenge = await challengeResponse.json();
  if (!challengeResponse.ok) throw new Error(challenge.error);

  // The wallet shows this message to the client. Pass it unchanged.
  const signature = await signer.signMessage(challenge.message);

  const response = await fetch("/api/wallet", {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({
      address: signer.address,
      chain: challenge.chain,
      message: challenge.message,
      signature,
      connectorId: signer.connectorId,
    }),
  });
  const body = await response.json();
  if (!response.ok) throw new Error(body.error);
  return body.wallet as { address: string; chain: string; status: string };
}

Build the signer from the wallet the client uses.

register-button.tsx (browser)
import { useAccount, useSignMessage } from "wagmi";
import { registerWallet } from "@/lib/register-wallet";

export function RegisterButton() {
  const { address, connector } = useAccount();
  const { signMessageAsync } = useSignMessage();

  async function onClick() {
    if (!address) return;
    const wallet = await registerWallet({
      address,
      connectorId: connector?.id ?? null, // "assetera-wallet" when the Assetera Wallet connector is used
      signMessage: (message) => signMessageAsync({ message }),
    });
    showStatus(wallet.status);
  }

  return <button onClick={onClick}>Register this wallet</button>;
}

showStatus and showError are your own functions. A declined signature is the client's choice, not a fault. A browser wallet rejects with code 4001, and the Assetera Wallet rejects with the OnboardingError code cancelled. Say that the wallet is not registered, and offer to start again.

If the address is already in the client's list for this chain, skip the registration.

Step 3: wait for approval

The registration answer often carries the final status. If it is new or screening, show "in review" and read GET /api/wallet again every few seconds until the status changes. Offer only approved wallets as delivery wallets. Assetera checks the status again at purchase.

What each status means, and what to show, is in Wallet statuses.

Handle errors

Turn each error code into a short text for the client. Four need care:

  • Wallet.KycRequired: the client's KYC is not complete. Do not show "try again". Send the client to identity verification, and offer "add wallet" again when GET /api/kyc/me/status returns "verified": true.
  • WalletInUse.Conflict: another account holds the address. A retry never succeeds, so do not show "try again".
  • Wallet.ChallengeMissing: the challenge expired or was used. Start again from step 1.
  • Wallet.BadSignature: the signature did not come from this address. The client signed with another wallet or account.

The full list is in Wallet errors.

On this page