Getting started with Go (net/http)
Make x402 payments with Go’s standardnet/http client in 2 minutes.
You can find the full code for this example here.
Step 1: Create a Go module and install dependencies
Step 2: Set your environment variables
Your.env file should look like this:
EVM_PRIVATE_KEY: Hex EVM private key of the paying accountSVM_PRIVATE_KEY: Base58 Solana private key (optional if only using EVM)RESOURCE_SERVER_URL: Base URL of the server (e.g. http://localhost:4021)ENDPOINT_PATH: Path to a paid endpoint (e.g. /weather)
SERVER_URL (full URL, e.g. http://localhost:4021/weather). You can use that instead by setting a single SERVER_URL and building the request URL from it.
Step 3: Preview the client code
This example loads your env, creates an x402 client with EVM and SVM schemes (using the mechanism-helper registration pattern), wrapshttp.DefaultClient with payment handling, makes a GET request, and logs the response body and payment settlement from the PAYMENT-RESPONSE header.
main.go, utils.go, mechanism_helper_registration.go, builder_pattern.go).
Step 4: Run the client
Your client is now making x402 payments!
Step 5: Test the client
You can test your client against a local server by running the Gin example, or the Express, Hono, or Next.js examples. You can also test your client against a live merchant for free. You will receive a full refund of any tokens that you send, and PayAI will pay for the network fees.x402 reference
For a deeper dive into message shapes, headers, verification and settlement responses, see the x402 Reference.Need help?
Join our Community
Have questions or want to connect with other developers? Join our Discord server.

