Quickstart
Five minutes from npm install to a working integration.
3
Build
import { Brain, PolicyApprovalRequiredError } from "@brainfinance/sdk";
const brain = new Brain({ apiKey: process.env.BRAIN_API_KEY!, environment: "sandbox" });
// Read sandbox ledger data.
const accounts = await brain.accounts.list({ limit: 10 });
console.log(accounts.accounts);
// Ask the tenant's financial brain a question.
const answer = await brain.ask("acme", "What did we spend on AWS last month?");
console.log(answer.text);
console.log(answer.citations);
// Propose a payment.
let paymentId: string | undefined;
try {
const result = await brain.pay("acme", {
action_type: "ach_outbound",
source_account_id: "acct_demo_ap",
destination_counterparty_id: "cp_demo_vendor",
amount: "125.00",
currency: "USD",
evidence_ids: ["raw_demo_invoice"],
idempotencyKey: "quickstart-demo-001",
});
paymentId = result.intent.id;
} catch (error) {
if (!(error instanceof PolicyApprovalRequiredError)) throw error;
paymentId = error.intent.id;
if (paymentId) {
await brain.approve(paymentId);
await brain.payments.execute(paymentId);
}
}
// Pull a verifiable receipt.
const proof = await brain.proof(paymentId!);
console.log(proof.anchorTx); // on-chain anchor on Base Sepolia
console.log(proof.merklePath); // verifiable without trusting BrainWhere to Go Next
Stuck?
Problem
Fix
Last updated
