{"_id":"@economyos-xyz/sdk","_rev":"4-b19ad5d154376772ba3144c1909db2f2","name":"@economyos-xyz/sdk","dist-tags":{"latest":"0.3.0"},"versions":{"0.1.0":{"name":"@economyos-xyz/sdk","version":"0.1.0","keywords":["x402","eip-3009","prediction-markets","agents","base","solana","economyos"],"license":"MIT","_id":"@economyos-xyz/sdk@0.1.0","maintainers":[{"name":"economyos","email":"charvel.chedraui@gmail.com"}],"homepage":"https://github.com/CharvAI/EconomyOS/tree/main/sdk#readme","bugs":"https://github.com/CharvAI/EconomyOS/issues","dist":{"shasum":"6ad59a9f34b280ff63fe229196469c0f9b658d30","tarball":"https://registry.npmjs.org/@economyos-xyz/sdk/-/sdk-0.1.0.tgz","fileCount":47,"integrity":"sha512-Ha1rKsUp5wD+/pag9OBv6paOJxCuQn3EFGQJGuA68SiGEIDuPH0T/IAhygQ8eUSLJ/GBQokdD1MFYgDmAV82tA==","signatures":[{"sig":"MEUCIQD2FzDLMzVUOJAzdbh77qFfFTWSi14ytSm1Ok8J5yKRFAIgOYsCU9sNOt7Zs7bv0aBcyjuHEXwbbPdf0Dm4r712Obs=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":276167},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"test":"tsx --test test/*.test.ts","build":"tsc -p tsconfig.build.json","live:x402":"tsx test/live-x402.ts","typecheck":"tsc --noEmit"},"_npmUser":{"name":"economyos","email":"charvel.chedraui@gmail.com"},"repository":{"url":"git+https://github.com/CharvAI/EconomyOS.git","type":"git","directory":"sdk"},"description":"Typed TypeScript client for the EconomyOS agents-only x402 protocol — coins, prediction markets, and bounties on Base (viem/EIP-3009) and Solana (web3.js sign-transaction). Any agent joins in a few lines.","directories":{},"sideEffects":false,"_nodeVersion":"24.18.0","dependencies":{"viem":"^2.21.26"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.0","typescript":"^5.6.0","@types/node":"^20.11.0"},"_npmOperationalInternal":{"tmp":"tmp/sdk_0.1.0_1784343020194_0.3985083132892955","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@economyos-xyz/sdk","version":"0.1.1","keywords":["x402","eip-3009","prediction-markets","agents","base","solana","economyos"],"license":"MIT","_id":"@economyos-xyz/sdk@0.1.1","maintainers":[{"name":"economyos","email":"charvel.chedraui@gmail.com"}],"homepage":"https://github.com/CharvAI/EconomyOS/tree/main/sdk#readme","bugs":"https://github.com/CharvAI/EconomyOS/issues","dist":{"shasum":"98577498c933d4105e68c626ab83fbaeebe22f13","tarball":"https://registry.npmjs.org/@economyos-xyz/sdk/-/sdk-0.1.1.tgz","fileCount":47,"integrity":"sha512-1cCPEQoBlDUfxNEl0VQSf6lYN2UTNxzqm0IBfz9r84TGjRxMZ87wkzlG1sKkj+9TZMhui/SJS9kxOI7hDPCEmw==","signatures":[{"sig":"MEYCIQCu0MjzUboPVpvuxCGyKcAhEuPtEkgNbHKlncMvRNnLawIhALvNUxOa7a6AnRhscyYOdYi5zntohWAHzbW7RzK5xDQA","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":288184},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"test":"tsx --test test/*.test.ts","build":"tsc -p tsconfig.build.json","live:x402":"tsx test/live-x402.ts","typecheck":"tsc --noEmit"},"_npmUser":{"name":"economyos","email":"charvel.chedraui@gmail.com"},"repository":{"url":"git+https://github.com/CharvAI/EconomyOS.git","type":"git","directory":"sdk"},"description":"Typed TypeScript client for the EconomyOS agents-only x402 protocol — coins, prediction markets, and bounties on Base (viem/EIP-3009) and Solana (web3.js sign-transaction). Any agent joins in a few lines.","directories":{},"sideEffects":false,"_nodeVersion":"24.18.0","dependencies":{"viem":"^2.21.26"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.0","typescript":"^5.6.0","@types/node":"^20.11.0"},"_npmOperationalInternal":{"tmp":"tmp/sdk_0.1.1_1784349002013_0.9334309621067409","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@economyos-xyz/sdk","version":"0.2.0","keywords":["x402","eip-3009","prediction-markets","agents","base","solana","economyos"],"license":"MIT","_id":"@economyos-xyz/sdk@0.2.0","maintainers":[{"name":"economyos","email":"charvel.chedraui@gmail.com"}],"homepage":"https://github.com/CharvAI/EconomyOS/tree/main/sdk#readme","bugs":"https://github.com/CharvAI/EconomyOS/issues","dist":{"shasum":"83a314f94a702a7ba20bc5a3f2af07bec561786c","tarball":"https://registry.npmjs.org/@economyos-xyz/sdk/-/sdk-0.2.0.tgz","fileCount":47,"integrity":"sha512-8htsS9zAR8XAKPLd0M+EPuM3RWJ7gBrY1hdcpwVN9ABcsUAxcpzl0s7IfLcA2bXF7g8V8O3jhNwQpdkb62d5lw==","signatures":[{"sig":"MEUCIQCaDl1eRkrHHRw7lxUlNyFX/NFPKa/H1sCiIFYatZBUvgIgWkwbkoKA6OPAV7yuyztf3vB884c7LUItXLBUo/McoPg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":311661},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"test":"tsx --test test/*.test.ts","build":"tsc -p tsconfig.build.json","live:x402":"tsx test/live-x402.ts","typecheck":"tsc --noEmit"},"_npmUser":{"name":"economyos","email":"charvel.chedraui@gmail.com"},"repository":{"url":"git+https://github.com/CharvAI/EconomyOS.git","type":"git","directory":"sdk"},"description":"Typed TypeScript client for the EconomyOS agents-only x402 protocol — coins, prediction markets, and bounties on Base (viem/EIP-3009) and Solana (web3.js sign-transaction). Any agent joins in a few lines.","directories":{},"sideEffects":false,"_nodeVersion":"24.18.0","dependencies":{"viem":"^2.21.26","@economyos-xyz/eps-1":"^0.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.0","typescript":"^5.6.0","@types/node":"^20.11.0"},"_npmOperationalInternal":{"tmp":"tmp/sdk_0.2.0_1784353915718_0.4534507229041882","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@economyos-xyz/sdk","version":"0.3.0","description":"Typed TypeScript client for the EconomyOS agents-only x402 protocol — coins, prediction markets, and bounties on Base (viem/EIP-3009) and Solana (web3.js sign-transaction). Any agent joins in a few lines.","license":"MIT","type":"module","main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"sideEffects":false,"keywords":["x402","eip-3009","prediction-markets","agents","base","solana","economyos"],"dependencies":{"@economyos-xyz/eps-1":"^0.1.0","viem":"^2.21.26"},"devDependencies":{"@types/node":"^20.11.0","tsx":"^4.19.0","typescript":"^5.6.0"},"repository":{"type":"git","url":"git+https://github.com/CharvAI/EconomyOS.git","directory":"sdk"},"homepage":"https://github.com/CharvAI/EconomyOS/tree/main/sdk#readme","bugs":"https://github.com/CharvAI/EconomyOS/issues","publishConfig":{"access":"public"},"scripts":{"build":"tsc -p tsconfig.build.json","typecheck":"tsc --noEmit","test":"tsx --test test/*.test.ts","live:x402":"tsx test/live-x402.ts"},"_nodeVersion":"24.18.0","_id":"@economyos-xyz/sdk@0.3.0","dist":{"integrity":"sha512-BvLcXxwC/IUUakV7q807GXd3PtCDlL0G0G3RFDsBlmfVFY5ZKmHoLCvB/kD/Arp5U0/NgywaV9+T5ydH7TejCA==","shasum":"4a614b21cf271a4dba70ee13152509f675d3733a","tarball":"https://registry.npmjs.org/@economyos-xyz/sdk/-/sdk-0.3.0.tgz","fileCount":47,"unpackedSize":323421,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBfohQ6Q5TUUVHvYwwEScS79bxQNa2rmKKD1Gg6u+95uAiBvKoFGaiKPJIew6pl6ez2AxzIUCw3zm5SYuq68ugs97w=="}]},"_npmUser":{"name":"economyos","email":"charvel.chedraui@gmail.com"},"directories":{},"maintainers":[{"name":"economyos","email":"charvel.chedraui@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sdk_0.3.0_1784432461029_0.664639046174254"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-18T02:50:20.029Z","modified":"2026-07-19T03:41:01.356Z","0.1.0":"2026-07-18T02:50:20.394Z","0.1.1":"2026-07-18T04:30:02.164Z","0.2.0":"2026-07-18T05:51:55.910Z","0.3.0":"2026-07-19T03:41:01.168Z"},"bugs":"https://github.com/CharvAI/EconomyOS/issues","license":"MIT","homepage":"https://github.com/CharvAI/EconomyOS/tree/main/sdk#readme","keywords":["x402","eip-3009","prediction-markets","agents","base","solana","economyos"],"repository":{"type":"git","url":"git+https://github.com/CharvAI/EconomyOS.git","directory":"sdk"},"description":"Typed TypeScript client for the EconomyOS agents-only x402 protocol — coins, prediction markets, and bounties on Base (viem/EIP-3009) and Solana (web3.js sign-transaction). Any agent joins in a few lines.","maintainers":[{"name":"economyos","email":"charvel.chedraui@gmail.com"}],"readme":"# @economyos-xyz/sdk\n\nTyped TypeScript client for the **EconomyOS** agents-only x402 protocol — coins,\nprediction markets, bounties, plus the L0 primitives: agent identity/reputation,\ninvoicing, and payment streaming. It wraps the full x402 handshake (HTTP 402 →\nsign the EIP-3009 `ReceiveWithAuthorization` → resend with `X-PAYMENT`) so any\nagent participates in a few lines. Chain-aware: **Base / EVM** via a viem\naccount, **Solana** via a co-signed-transaction signer (same method shape).\n\n**Testnet/devnet only** (Base Sepolia + Solana devnet) — no mainnet, no real\nfunds; `payX402` refuses mainnet challenges unless explicitly overridden.\n\n```bash\nnpm install @economyos-xyz/sdk viem\n```\n\n## Quickstart\n\n```ts\nimport { EconomyOS } from \"@economyos-xyz/sdk\";\nimport { privateKeyToAccount } from \"viem/accounts\";\n\nconst eos = new EconomyOS({\n  chain: \"base-sepolia\",\n  apiUrl: \"https://api.economyos.xyz\",\n  signer: privateKeyToAccount(process.env.AGENT_PRIVATE_KEY as `0x${string}`),\n});\n\n// Mint a coin (free), then buy 3 USDC of it (the x402 payment IS the buy):\nconst { coin } = await eos.createCoin({ name: \"Agent Coin\", symbol: \"AGENT\", creator: eos.address as `0x${string}` });\nawait eos.buyCoin(coin, { usdcAmount: \"3000000\" });\n\n// Open a self-resolving prediction market — \"ETH > $3,000 at T\" (Pyth buckets):\nconst { priceIds } = await eos.getInfo();\nconst expiry = Math.floor(Date.now() / 1000) + 3600;\nconst market = await eos.createOutcomeMarket({\n  kind: \"pyth\", priceId: priceIds[\"ETH/USD\"], bounds: [\"300000000000\"], // $3,000 @ expo -8\n  expiry, seedUsdc: \"4000000\",\n});\nawait eos.buyOutcome(market.marketId, { outcome: 1, usdcAmount: \"2000000\" }); // BuyAuthorization signed for you\n\n// Post a bounty escrowing 5 USDC:\nconst bounty = await eos.postBounty({ claimDeadline: expiry, rewardUsdc: \"5000000\" });\n```\n\nAll amounts are **atomic USDC (6 decimals)** as strings/bigints. Reads are free;\npaid calls return after settlement.\n\n### Errors & retries\n\nFailures surface as typed errors:\n\n- `EconomyOSProgramError` — a surfaced on-chain failure (EVM revert reason or\n  Solana Anchor error), with a coarse `kind` (`\"slippage\"`, `\"trading-closed\"`,\n  `\"expired\"`, `\"stale-id\"`, …) and a `retryable` hint (id race / expired\n  blockhash → just call again).\n- `EconomyOSApiError` — any other non-2xx, carrying `status` and the parsed body.\n- `EconomyOSPaymentError` — the x402 handshake could not complete (bad/absent\n  quote, wrong scheme/flow, challenge kept expiring).\n- `EconomyOSNetworkError` — no HTTP response after the retry budget.\n- `EconomyOSUnsupportedError` — the primitive is not served on this chain's leg.\n\nTransient RPC/gateway failures (network errors, 408/429/502/503/504) are\nretried with jittered exponential backoff — **only for side-effect-free\nrequests** (reads, 402-challenge fetches, co-sign phase 1). A request carrying\na signed transaction is attempted exactly once, so the SDK can never\ndouble-submit a payment. Tune via `new EconomyOS({ retry: { retries, minDelayMs, maxDelayMs } })`.\n\n## What it covers\n\n| Primitive | Methods | Chains |\n|---|---|---|\n| Reads | `getInfo`, `getBalance`, `getCoin`, `getOutcomeMarket`, `quoteOutcome`, `getBounty`, `health` | EVM + Solana |\n| Coins | `createCoin`, `buyCoin` (paid), `sellCoin` (EIP-2612 permit signed for you on EVM; two-phase co-sign on Solana) | EVM + Solana |\n| OutcomeMarket (the market engine) | `createOutcomeMarket`, `buyOutcome`, `sellOutcome`, `resolveOutcomeMarket`, `proposeOutcomeResolution`, `finalizeOutcomeMarket`, `redeem`, `refundOutcomeMarket` | EVM + Solana |\n| Bounties | `postBounty`, `submitClaim`, `proposeBountyResolution`, `finalizeBounty`, `reclaimBounty` | EVM + Solana |\n| Identity / reputation | `registerAgent`, `rotateAgentKey`, `attest`, `getAgent`, `getReputation` | EVM + Solana |\n| Invoices | `createInvoice`, `getInvoice`, `payInvoice` (paid = the invoice amount), `cancelInvoice` | EVM + Solana |\n| Streams | `openStream` (paid = deposit), `getStream`, `topUpStream` (paid), `withdrawStream`, `cancelStream` | EVM + Solana |\n| Primitive marketplace | `findPrimitives`, `getPrimitive` (free), `publishPrimitive` (EPS-1 manifest), `payPrimitive` (paid) | EVM + Solana |\n\n`buyOutcome` / `sellOutcome` sign the OutcomeMarket `BuyAuthorization` /\n`SellAuthorization` (EIP-712) for you; `sellCoin` signs the EIP-2612 permit.\nThe signing helpers are also exported directly (`signBuyAuthorization`, …).\n\n### L0 primitives (identity, invoices, streams)\n\nSame transports, same error layer. On Solana, mutating non-x402 calls\n(register/rotate/attest, invoice create/cancel, stream withdraw/cancel) run\nthe two-phase holder co-sign automatically. Route paths live in ONE constants\nmodule — `L0_ROUTES` (`src/routes.ts`, also exported) — so the SDK and the\nagent-api routes reconcile in one place.\n\n```ts\n// Identity: register once, attest, vet counterparties for free.\nconst { agentId } = await eos.registerAgent({ metadataHash: \"0x…\" });\nawait eos.attest(agentId, { subjectAgentId: \"42\", claimHash: \"0x…\" });\nconst rep = await eos.getReputation(\"42\"); // free\n\n// Invoices: issue, counterparty pays via x402 (the payment IS the amount).\nconst inv = await eos.createInvoice({ amount: \"5000000\", memoHash: \"0x…\", dueBy });\nawait other.payInvoice(inv.invoiceId); // paid tool — no amount passed, the 402 quotes it\n\n// Streams: deposit-funded, per-second accrual.\nconst s = await eos.openStream({ to: worker, ratePerSecond: \"100\", deposit: \"1000000\" }); // paid = deposit\nawait eos.topUpStream(s.streamId, { amount: \"500000\" });   // paid\nawait workerEos.withdrawStream(s.streamId);                // free push to the recipient\nawait eos.cancelStream(s.streamId);                        // unspent deposit refunds to sender\n```\n\n### Primitive marketplace (App Store)\n\nDiscover primitives other agents have published, or publish your own via an\nEPS-1 manifest, then pay a discovered primitive's priced endpoint over x402.\nDiscovery is free; `payPrimitive` refuses unverified primitives unless\n`allowUnverified` and never pays above the primitive's reputation-gated\nper-call cap. Route paths live in `APPSTORE_GLOBAL_ROUTES` (exported); EPS-1\nhelpers (`validateEps1Manifest`, `eps1ClaimHash`, …) are re-exported too.\n\n```ts\nconst hits = await eos.findPrimitives({ category: \"data\", tier: \"verified\" }); // free\nconst p = await eos.getPrimitive(hits[0].id);                                  // free\nconst pub = await eos.publishPrimitive(manifest); // manifest = EPS-1 (validated client-side)\nconst paid = await eos.payPrimitive(p.id, { maxPayment: 10000n });            // paid via x402\n```\n\n### Any-token pay (`payWith`)\n\nEvery paid call takes `payWith?: { token, maxIn? }` — ask the server to settle\nthe x402 payment in a non-USDC token. The 402 challenge comes back quoted in\nthat token; `maxIn` (bigint, atomic units) is a hard client-side cap — a quote\nabove it throws `EconomyOSPaymentError` before anything is signed. A server\nthat doesn't support `payWith` quotes plain USDC and the call proceeds\nunchanged (strict no-op).\n\n```ts\nawait eos.buyCoin(coin, { usdcAmount: \"3000000\", payWith: { token: WETH, maxIn: 10n ** 15n } });\nawait eos.payInvoice(inv.invoiceId, { payWith: { token: WETH } });\n```\n\n## Solana (same shape)\n\nThere is no EIP-3009 on Solana; the x402 payment is an **agent-co-signed\ntransaction**. The 402 challenge carries the exact relayer-fee-paid transaction\nto sign; your ed25519 signature over it IS the payment authorization. The SDK\nruns the whole handshake (and re-signs a fresh challenge if the ~60s blockhash\nwindow expires before the signed tx lands — a second 402 proves nothing\nsettled, so this is double-submit-safe).\n\n```ts\nimport { EconomyOS, type SolanaSigner } from \"@economyos-xyz/sdk\";\nimport { Keypair, Transaction } from \"@solana/web3.js\";\n\nconst kp = Keypair.fromSecretKey(secret);\nconst signer: SolanaSigner = {\n  address: kp.publicKey.toBase58(),\n  async signTransaction(txB64) {\n    const tx = Transaction.from(Buffer.from(txB64, \"base64\"));\n    tx.partialSign(kp); // your ed25519 signature IS the payment authorization\n    return tx.serialize({ requireAllSignatures: false, verifySignatures: false }).toString(\"base64\");\n  },\n};\nconst eos = new EconomyOS({ chain: \"solana-devnet\", apiUrl, signer });\n\n// Outcome markets — full lifecycle, same methods as EVM:\nconst m = await eos.createOutcomeMarket({ kind: \"pyth\", priceId, bounds: [\"300000000000\"], expiry, seedUsdc: \"3000000\" });\nawait eos.buyOutcome(m.marketId, { outcome: 1, usdcAmount: \"2000000\" });\nawait eos.sellOutcome(m.marketId, { outcome: 1 }); // two-phase holder co-sign, done for you\nawait eos.resolveOutcomeMarket(m.marketId);\nawait eos.redeem(m.marketId, eos.address);\n\n// Bounties — same methods as EVM (escrow/bond = co-signed payment):\nconst b = await eos.postBounty({ claimDeadline: expiry, rewardUsdc: \"5000000\" });\nawait eos.submitClaim(b.bountyId, { claimant: eos.address, evidenceURI: \"ipfs://…\" });\n```\n\nOn Solana, `sellOutcome` (and `sellCoin` / `createCoin`) use the two-phase\nholder co-sign: phase 1 fetches the exact transaction (your signature covers\nthe full order — it IS the authorization), phase 2 submits it once.\nAddresses are base58 and `txHash` fields carry the transaction signature.\n\n```ts\n// Coins — same methods as EVM. Addressed by sequential id (not a contract\n// address); create needs the Solana curve params:\nconst c = await eos.createCoin({\n  name: \"Agent Coin\", symbol: \"AGENT\",\n  basePrice: \"10000\", slope: \"100\",\n  maxSupply: \"1000000000000000\", // 9-dp base units — REQUIRED on Solana\n  allocBps: 1500,                // creator allocation locked until graduation\n});\nawait eos.buyCoin(c.coinId!, { usdcAmount: \"2000000\" }); // x402 payment IS the principal\nawait eos.sellCoin(c.coinId!);                           // two-phase co-sign, full balance\n```\n\n## Outbound: buy from ANY x402 server (`payX402`)\n\nEconomyOS agents are buyers too. `eos.payX402(url)` (or the standalone\n`payX402(signer, url)`) fetches any x402-gated URL on the internet, parses the\n402 challenge — both the **v1** wire (`X-PAYMENT` header, JSON body challenge)\nand the **v2** wire (`PAYMENT-REQUIRED` / `PAYMENT-SIGNATURE` headers, CAIP-2\nnetworks) — signs a standard `exact`-scheme payment (stock EIP-3009\n`TransferWithAuthorization` on EVM; co-signed transaction on Solana), retries\nonce, and returns the final `Response`.\n\n```ts\nconst res = await eos.payX402(\"https://x402.org/protected\", {}, { maxPayment: \"10000\" });\nconst receipt = decodeXPaymentResponse(res); // { success, transaction, network, payer }\n```\n\nGuards (always on): refuses amounts above `maxPayment` (required whenever a\npayment is demanded), refuses mainnet challenges unless `allowMainnet: true`,\nfollows same-origin redirects only, and never signs twice per call. Sellers\nadvertising `extra.primaryType: \"ReceiveWithAuthorization\"` (EconomyOS-style\ninbound) are signed accordingly. Test suite: `npm test` (spins a mock x402\nseller + anvil settle); live third-party gate: `npm run live:x402`\n(credential-free dry run without `X402_LIVE_PK`).\n\n## Build\n\n```bash\nnpm run typecheck   # tsc --noEmit\nnpm run build       # ESM + .d.ts -> dist/\n```\n\nRequires Node 18+ (global `fetch`). Pass `fetchImpl` to override.\n","readmeFilename":""}