{"_id":"@devswayam/x402-axios","_rev":"2-3b62355fbb004b5026ab9e2ca9dc6c22","name":"@devswayam/x402-axios","dist-tags":{"latest":"0.6.0"},"versions":{"0.5.1":{"name":"@devswayam/x402-axios","version":"0.5.1","keywords":[],"author":{"name":"Coinbase Inc."},"license":"Apache-2.0","_id":"@devswayam/x402-axios@0.5.1","maintainers":[{"name":"devswayam","email":"swayamkarle2@gmail.com"}],"homepage":"https://github.com/DevSwayam/x402#readme","bugs":{"url":"https://github.com/DevSwayam/x402/issues"},"dist":{"shasum":"9079831a35148930dcd5e2680c1664ab9da70193","tarball":"https://registry.npmjs.org/@devswayam/x402-axios/-/x402-axios-0.5.1.tgz","fileCount":8,"integrity":"sha512-UIv+TVJQPmbS/k2Zh2KZmXQkp0pGCxfSOUhhEtpaJ8jO8EDvutMPCLXqbkinFuBBuXHI5akB4VN938zC2Mv2pw==","signatures":[{"sig":"MEUCIFahe7gFDxA0yxmvWDhqhNCoUF0uLt5X1PZQEiSt1pVlAiEA0ENvHBB6yBN87iBt6zJJ35aJ0UZHGn00QpsEMTq0GXk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":20567},"main":"./dist/cjs/index.js","_from":"file:devswayam-x402-axios-0.5.1.tgz","types":"./dist/index.d.ts","module":"./dist/esm/index.js","exports":{".":{"import":{"types":"./dist/esm/index.d.mts","default":"./dist/esm/index.mjs"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.js"}}},"scripts":{"lint":"eslint . --ext .ts --fix","test":"vitest run","build":"tsup","start":"tsx --env-file=.env index.ts","watch":"tsc --watch","format":"prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"","lint:check":"eslint . --ext .ts","test:watch":"vitest","format:check":"prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\""},"_npmUser":{"name":"devswayam","email":"swayamkarle2@gmail.com"},"_resolved":"/private/var/folders/mm/pn7zw65s2n994mhcr3vrpxq00000gn/T/3fec0be7f5850fbfaf00cb8c7e46d0e0/devswayam-x402-axios-0.5.1.tgz","_integrity":"sha512-UIv+TVJQPmbS/k2Zh2KZmXQkp0pGCxfSOUhhEtpaJ8jO8EDvutMPCLXqbkinFuBBuXHI5akB4VN938zC2Mv2pw==","repository":{"url":"git+https://github.com/DevSwayam/x402.git","type":"git","directory":"typescript/packages/x402-axios"},"_npmVersion":"11.3.0","description":"x402 Payment Protocol","directories":{},"_nodeVersion":"24.1.0","dependencies":{"zod":"^3.24.2","viem":"^2.21.26","axios":"^1.7.9","unwallet-horizen":"^0.1.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","tsup":"^8.4.0","vite":"^6.2.6","eslint":"^9.24.0","vitest":"^3.0.5","prettier":"3.5.2","@eslint/js":"^9.24.0","typescript":"^5.7.3","@types/node":"^22.13.4","eslint-plugin-jsdoc":"^50.6.9","vite-tsconfig-paths":"^5.1.4","eslint-plugin-import":"^2.31.0","eslint-plugin-prettier":"^5.2.6","@typescript-eslint/parser":"^8.29.1","@typescript-eslint/eslint-plugin":"^8.29.1"},"_npmOperationalInternal":{"tmp":"tmp/x402-axios_0.5.1_1756292400391_0.43785248516237374","host":"s3://npm-registry-packages-npm-production"}},"0.6.0":{"name":"@devswayam/x402-axios","version":"0.6.0","main":"./dist/cjs/index.js","module":"./dist/esm/index.js","types":"./dist/index.d.ts","keywords":[],"license":"Apache-2.0","author":{"name":"Coinbase Inc."},"repository":{"type":"git","url":"git+https://github.com/DevSwayam/x402.git","directory":"typescript/packages/x402-axios"},"publishConfig":{"access":"public"},"description":"x402 Payment Protocol","devDependencies":{"@eslint/js":"^9.24.0","@types/node":"^22.13.4","@typescript-eslint/eslint-plugin":"^8.29.1","@typescript-eslint/parser":"^8.29.1","eslint":"^9.24.0","eslint-plugin-import":"^2.31.0","eslint-plugin-jsdoc":"^50.6.9","eslint-plugin-prettier":"^5.2.6","prettier":"3.5.2","tsup":"^8.4.0","tsx":"^4.19.2","typescript":"^5.7.3","vite-tsconfig-paths":"^5.1.4","vitest":"^3.0.5","vite":"^6.2.6"},"dependencies":{"axios":"^1.7.9","viem":"^2.21.26","zod":"^3.24.2","unwallet-horizen":"^0.2.0"},"exports":{".":{"import":{"types":"./dist/esm/index.d.mts","default":"./dist/esm/index.mjs"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.js"}}},"scripts":{"start":"tsx --env-file=.env index.ts","test":"vitest run","test:watch":"vitest","build":"tsup","watch":"tsc --watch","format":"prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"","format:check":"prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"","lint":"eslint . --ext .ts --fix","lint:check":"eslint . --ext .ts"},"_id":"@devswayam/x402-axios@0.6.0","bugs":{"url":"https://github.com/DevSwayam/x402/issues"},"homepage":"https://github.com/DevSwayam/x402#readme","_integrity":"sha512-gEhxMJjJ1eWUn/Fogu3rVeyS4A0QFf9wdlh/E3EQbWrGt5PeEwzK6/XPCaBCWP+n6eNq9T9nYSo6QkXImPRtIA==","_resolved":"/private/var/folders/mm/pn7zw65s2n994mhcr3vrpxq00000gn/T/fc554f094d78e085e8a2c4fca1180f7a/devswayam-x402-axios-0.6.0.tgz","_from":"file:devswayam-x402-axios-0.6.0.tgz","_nodeVersion":"24.1.0","_npmVersion":"11.3.0","dist":{"integrity":"sha512-gEhxMJjJ1eWUn/Fogu3rVeyS4A0QFf9wdlh/E3EQbWrGt5PeEwzK6/XPCaBCWP+n6eNq9T9nYSo6QkXImPRtIA==","shasum":"a6e0cb33fc1ec55397a4a66960760f5c0935e500","tarball":"https://registry.npmjs.org/@devswayam/x402-axios/-/x402-axios-0.6.0.tgz","fileCount":8,"unpackedSize":20567,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIG69m6R+5QeLXs6zGPsYy+69iYtfe7h1bJXG2xFSxjd2AiEA2NNhDlK8E9mC+oHU6Stfc/rovNG8bWruJg3A64zX6nw="}]},"_npmUser":{"name":"devswayam","email":"swayamkarle2@gmail.com"},"directories":{},"maintainers":[{"name":"devswayam","email":"swayamkarle2@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/x402-axios_0.6.0_1756316347651_0.8766109267026949"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-27T11:00:00.303Z","modified":"2025-08-27T17:39:07.998Z","0.5.1":"2025-08-27T11:00:00.572Z","0.6.0":"2025-08-27T17:39:07.816Z"},"bugs":{"url":"https://github.com/DevSwayam/x402/issues"},"author":{"name":"Coinbase Inc."},"license":"Apache-2.0","homepage":"https://github.com/DevSwayam/x402#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/DevSwayam/x402.git","directory":"typescript/packages/x402-axios"},"description":"x402 Payment Protocol","maintainers":[{"name":"devswayam","email":"swayamkarle2@gmail.com"}],"readme":"# x402-axios\n\nA utility package that extends Axios to automatically handle 402 Payment Required responses using the x402 payment protocol. This package enables seamless integration of payment functionality into your applications when making HTTP requests with Axios.\n\n## Installation\n\n```bash\nnpm install x402-axios\n```\n\n## Quick Start\n\n```typescript\nimport { createWalletClient, http } from \"viem\";\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport { withPaymentInterceptor } from \"x402-axios\";\nimport axios from \"axios\";\nimport { baseSepolia } from \"viem/chains\";\n\n// Create a wallet client\nconst account = privateKeyToAccount(\"0xYourPrivateKey\");\nconst client = createWalletClient({\n  account,\n  transport: http(),\n  chain: baseSepolia,\n});\n\n// Create an Axios instance with payment handling\nconst api = withPaymentInterceptor(\n  axios.create({\n    baseURL: \"https://api.example.com\",\n  }),\n  client\n);\n\n// Make a request that may require payment\nconst response = await api.get(\"/paid-endpoint\");\nconsole.log(response.data);\n```\n\n## Features\n\n- Automatic handling of 402 Payment Required responses\n- Automatic retry of requests with payment headers\n- Payment verification and header generation\n- Exposes payment response headers\n\n## API\n\n### `withPaymentInterceptor(axiosClient, walletClient)`\n\nAdds a response interceptor to an Axios instance to handle 402 Payment Required responses automatically.\n\n#### Parameters\n\n- `axiosClient`: The Axios instance to add the interceptor to\n- `walletClient`: The wallet client used to sign payment messages (must implement the x402 wallet interface)\n\n#### Returns\n\nThe modified Axios instance with the payment interceptor that will:\n1. Intercept 402 responses\n2. Parse the payment requirements\n3. Create a payment header using the provided wallet client\n4. Retry the original request with the payment header\n5. Expose the X-PAYMENT-RESPONSE header in the final response\n","readmeFilename":"README.md"}