Step 1: Create a Go module and install dependencies
Copy
go mod init myclientgo get github.com/coinbase/x402/go github.com/joho/godotenv
To run from the x402 repo instead: clone coinbase/x402, then cd examples/go/clients/http, copy .env-example to .env, and run go run . mechanism-helper-registration (or go run . builder-pattern).
The upstream example uses 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.
This example loads your env, creates an x402 client with EVM and SVM schemes (using the mechanism-helper registration pattern), wraps http.DefaultClient with payment handling, makes a GET request, and logs the response body and payment settlement from the PAYMENT-RESPONSE header.
For a full runnable example with payment-response decoding and both builder-pattern and mechanism-helper registration, see the upstream Go HTTP client (main.go, utils.go, mechanism_helper_registration.go, builder_pattern.go).
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.