Skip to main content
All use cases
TreasuryOperations

Below your floor, a Pix to fund the wallet.

The agent reads the wallet's BRL balance with codespar_wallet. When it is below the floor your code sets, it mints a dynamic Pix copia-e-cola for the amount you choose. Whoever holds the funding source pays it, and the statement shows the credit. CodeSpar does not watch the balance or refill it on its own: the floor and the decision are your agent's.

BeforeWatch the balance and top up by hand
AfterYour agent mints a Pix for the gap; the funding source pays it
Pix
a dynamic charge to fund the wallet
Try it in the Sandbox
balance
Balance
action=balance reads the balance per currency
receive
Dynamic Pix
action=receive with dynamic=true mints a copia-e-cola for the amount
floor
Your floor
Your code compares; the platform does not watch the balance
Pix
Someone pays
The funding source pays the Pix; nothing is funded before that
Illustrative example · demo data

Below the floor, a Pix to fund the wallet.

An example with demo data: the agent reads BRL 180.00, below the R$ 500.00 floor your code sets, and mints a dynamic Pix of R$ 1,000.00. The funding source pays it and the statement shows the credit.

  • The floor is your code's, not a platform setting
  • The dynamic Pix funds the wallet only once someone pays it
  • The statement shows the credit after the payment
Wallet · BRL
codespar_wallet
Agent
codespar_wallet · action: "balance"
BRL180.00
via codespar_wallet · Wallet
BRL 180.00 < 500.00
codespar_wallet · action: "receive" · dynamic: true
Pix · Funding sourceR$ 1.000,00
00020126…5204
via codespar_wallet · Pix
✓ Pix
codespar_wallet · action: "statement"
BRL1180.00
via codespar_wallet · Wallet
✓ BRL 180.00 → 1180.00topup_demo
The pain

The conversation is the easy part.

Payout floats run dry at the worst time. Someone tops them up by hand, and until they do, every payout waits.

Watch the balance by hand

The agent reads the balance with codespar_wallet

Generate a Pix charge in the bank portal

action=receive mints a dynamic Pix for the amount

Copy the code and send it to whoever pays

The copia-e-cola comes back in the answer, ready to send

Check later whether the money arrived

action=statement lists the wallet's entries

How the agent does it

A top-up your code decides, a Pix someone pays.

codespar_wallet reads the balance (action=balance), mints a dynamic Pix copia-e-cola to fund the wallet (action=receive, dynamic=true) and lists the entries (action=statement). Your agent holds the floor and decides when to mint; the funding source pays the Pix. CodeSpar does not watch the balance or top it up on its own.

01
Read
codespar_wallet

BRL balance

Wallet
02
Compare
Your code

Below your floor?

03
Mint
codespar_wallet

A dynamic Pix

Pix
04
Pay
Funding source

The funding source pays

05
Check
codespar_wallet

The statement shows the credit

Wallet
Architecture

codespar_wallet with action=balance returns the wallet's balance per currency. With action=receive and dynamic=true it mints a dynamic Pix charge on the Celcoin account behind the wallet and returns its copia-e-cola. Once the funding source pays, the credit shows in action=statement. The floor and the decision to top up are your agent's code.

In code

The code, and what it assumes.

wallet-auto-topup.ts
// Prerequisites: CODESPAR_API_KEY set to a test key (csk_test_…) and a consumer
// (user_0000) with a wallet. The floor is your code: CodeSpar does not watch the
// balance, and the Pix funds the wallet only once someone pays it.
import { CodeSpar } from "@codespar/sdk";

const session = await new CodeSpar().create("user_0000", { preset: "brazilian" });
const FLOOR_MINOR = 50_000; // R$ 500.00, your floor
const TOP_UP_MINOR = 100_000; // R$ 1,000.00

const read = await session.execute("codespar_wallet", { action: "balance", consumer_id: "user_0000" });
const { balances } = read.data as { balances: { currency: string; balance_minor: number | string }[] };
const brl = Number(balances.find((b) => b.currency === "BRL")?.balance_minor ?? 0);

if (brl < FLOOR_MINOR) {
  const pix = await session.execute("codespar_wallet", {
    action: "receive",
    consumer_id: "user_0000",
    amount: TOP_UP_MINOR,
    dynamic: true,
    description: "Wallet top-up",
  });
  console.log(pix.data); // the copia-e-cola for the funding source to pay
}

Example with the published SDK (@codespar/sdk 0.16.11). Its prerequisites are in the comments. Compiling does not prove the integration: run it in test mode first.

Featured tools
codespar_wallet

Reads the balance and the statement, and mints a dynamic Pix to fund the wallet.

See the meta-tool reference
MCP servers wired

Start with a test key.

Test keys are free. Open the sandbox, connect the providers your project uses and see which tools it can call before you build.

Wallet top-up agent — CodeSpar | CodeSpar