Quickstart for Users
This guide walks you through how to use x402 to interact with PayPerScrape. By the end of this guide, you will be able to programmatically discover payment requirements, complete a payment, and scrape any website.
Prerequisites
Before you begin, ensure you have:
- A crypto wallet with USDC (any EVM-compatible wallet)
- Node.js and npm, or Python and pip
- Access to PayPerScrape API endpoint
Note: We have pre-configured examples available in our repo, including examples for fetch, Axios, and python.
Note: These Docs have been adapted from the Coinbase x402 documentation. For the full documentation, see the Official x402 documentation
Install Dependencies
Create a Wallet Client
Node.js (viem)
Install the required package:
Then instantiate the wallet account:
Python (eth-account)
Install the required package:
Then instantiate the wallet account:
Make Paid Requests Automatically
Node.js
You can use @x402/fetch with either native fetch or axios to automatically handle 402 Payment Required responses and complete payment flows.
Fetch
@x402/fetch extends the native fetch API to handle 402 responses and payment headers for you. Full example here
Axios
Use @x402/fetch with a custom axios wrapper to handle 402 responses and payment flows. Full example here
Python
Use x402.clients.httpx to automatically handle 402 Payment Required responses and complete payment flows with HTTPX.
Error Handling
Clients will throw errors if:
- The request configuration is missing
- A payment has already been attempted for the request
- There is an error creating the payment header
- The target URL is invalid or blocked
- The scraping failed after all escalation attempts
Summary
- Install @x402/fetch and @x402/evm packages
- Create a wallet account using viem
- Register the EVM scheme with x402Client
- Use the provided wrapper to make paid API requests to PayPerScrape
- Payment flows are handled automatically for you
