Skip to content

purl should auto-select network based on wallet balance #31

@MajorTal

Description

@MajorTal

Problem

When an x402 server offers multiple networks (e.g. both Base mainnet eip155:8453 and Base Sepolia eip155:84532), purl always selects the first one listed. If the wallet only has funds on the second network, the payment fails with:

Error: Payment was not accepted by the server

No indication is given that the failure is due to insufficient funds on the selected network.

Steps to reproduce

  1. Create a wallet funded on Base Sepolia only (purl balance shows 0.249 USDC on base-sepolia, 0.000 USDC on base)
  2. Hit an endpoint that offers both networks:
purl inspect https://api.run402.com/v1/ping
# Shows: eip155:8453 (compatible: true), eip155:84532 (compatible: true)
  1. Try to pay:
PURL_PASSWORD=xxx purl https://api.run402.com/v1/ping --max-amount 10000
# Error: Payment was not accepted by the server
  1. Workaround — force network manually:
PURL_PASSWORD=xxx purl https://api.run402.com/v1/ping --max-amount 10000 --network eip155:84532
# Works! Payment settled on Sepolia.

Expected behavior

purl should check the wallet's balance on each offered network and automatically select one where the wallet has sufficient funds. If no network has sufficient funds, show a clear error like:

Error: Insufficient balance on all offered networks.
  eip155:8453:  0.000 USDC (need 0.001)
  eip155:84532: 0.249 USDC (need 0.001) ← sufficient

Or at minimum, when the payment is rejected, suggest trying --network eip155:84532 if the wallet has funds there.

Environment

  • purl v0.1.1
  • macOS (Apple Silicon)
  • Server: Run402 (api.run402.com), offers both Base mainnet and Base Sepolia

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions