The ArcenAgent class is the primary entry point for @arcenpay/agent.
Constructor
AgentConfig Options
Core Methods
agent.fetch(url, options?)
Drop-in replacement for global fetch(). Automatically intercepts HTTP 402 Payment Required, verifies the requested price against guardrails, signs a cryptographic voucher, and retries the request transparently.
The signed voucher is replayed in the X-PAYMENT request header after the 402 challenge; the provider verifies it and returns the resource.
Payment Link Methods
agent.resolvePaymentLink(urlOrSlug)
Fetches and normalizes the machine-readable specification (AgenticPaymentLinkSpec) for a checkout link. Does not spend funds.
agent.payPaymentLink(urlOrSlug, options?)
Executes end-to-end payment for a link:
- Resolves spec and checks chain compatibility.
- Validates
options.maxPrice, maxAutoApprove, and daily spend limits.
- Initiates checkout session via backend.
- Executes on-chain ERC-20 transfer (EVM), SAC payment (Stellar), or SPL transfer (Solana).
- Confirms session and returns cryptographic
AgentPaymentReceipt.
agent.createPaymentLink(params)
Allows autonomous agents acting as merchants to create payment links programmatically (isAgentic: true). Requires apiKey in the constructor (or per-call via params.apiKey).
Token handling is fully automatic — currency ("USDC", "USDT") is resolved to the chain’s token contract address, or you can pass a raw address via acceptedToken. expiresInMinutes is converted to an ISO expiresAt for the control plane.
The returned spec also carries slug, sessionUrl, and confirmUrl for the machine-readable /spec endpoint and checkout session flow.
sessionUrl is directly callable. confirmUrl is a template — confirmation is scoped to a checkout session, so substitute :sessionId with the id returned by sessionUrl before calling it:
Session & Accounting Methods
agent.fundSession(amount)
Deposits amount USDC/USDT into the agent’s on-chain SessionVault. Returns the created sessionId.
Under the hood, funding is chain-specific: EVM approves the token and calls SessionVault.fundSession; Stellar transfers SAC USDC then calls the Soroban fund_session; Solana invokes the Anchor fund_session instruction, which creates or tops up the session vault.
agent.getBalance()
Returns the agent’s remaining unspent balance locked in the active session vault in atomic micros (bigint).
agent.getSpendSummary()
Returns structured diagnostic metrics:
Auto-Topup & Dispatch Notifications
ArcenAgent supports human-in-the-loop and autonomous treasury replenishment when available balance drops below a threshold.
Configuration Example
agent.sendDispatchRequest(amount, reason)
Sends a top-up approval request to all enabled dispatch providers (Telegram inline buttons, Discord webhook, Slack, or Email):
On Telegram, this sends an HTML message with interactive ✅ Approve and ❌ Deny callback buttons.
agent.getPendingDispatchRequests()
Returns all active dispatch requests awaiting human approval:
agent.resolveDispatchRequest(requestId, approved)
Marks a dispatch request as approved or denied. If approved, the agent automatically executes the on-chain session top-up:
Last modified on October 4, 2026