> For the complete documentation index, see [llms.txt](https://docs.abapays.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.abapays.com/build/sdk.md).

# TypeScript SDK

> `abapay-sdk`

Two functions, matching the two protocol-driven paths in this handbook. Signs with whatever [viem](https://viem.sh) account your agent already has — nothing hidden, the source is the same wire format documented in [x402](/protocols/x402.md) and [A2A](/protocols/a2a.md).

**Live on npm** — `npm install abapay-sdk viem`

## Zero setup: payBillViaX402

Fetches the 402 challenge, signs it, retries, returns the settlement.

```ts
import { privateKeyToAccount } from "viem/accounts";
import { payBillViaX402 } from "abapay-sdk";

const account = privateKeyToAccount(process.env.PRIVATE_KEY);

const result = await payBillViaX402({
  signer: account,
  bill: {
    serviceID: "mtn", serviceCategory: "AIRTIME",
    network: "MTN", billersCode: "08012345678",
    nairaAmount: 1000, token: "USDT",
  },
});

console.log(result.status, result.tx_hash);
```

## Linked wallet: AbaPayAgent

Links once, sets the PIN in that same call, then reuses the api\_key for the full tool catalog.

```ts
import { privateKeyToAccount } from "viem/accounts";
import { AbaPayAgent } from "abapay-sdk";

const account = privateKeyToAccount(process.env.PRIVATE_KEY);

// One-time -- no browser, PIN chosen right here.
const agent = await AbaPayAgent.link({ signer: account, pin: "1234" });

console.log(await agent.checkBalance());
await agent.payBill({
  pin: "1234", service: "AIRTIME", provider: "mtn",
  account_number: "08012345678", amount_ngn: 1000,
});
```

## Correctness, not just types

A test in the package asserts the signed typed-data's domain and message match a real 402 challenge byte-for-byte — the exact contract AbaPay's own server-side verification reconstructs to check the signature against. A silent drift there would be a signature that fails to verify; the test exists so that drift fails loudly instead.

[Source, tests, and the full README →](https://github.com/investorphem/AbaPay/tree/main/sdk/README.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.abapays.com/build/sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
