HubClient SDK (Go)
Installation
go get github.com/sigweihq/x402payQuick Start
import (
"fmt"
"github.com/sigweihq/x402pay/pkg/hubclient"
x402paytypes "github.com/sigweihq/x402pay/pkg/types"
)
func main() {
// Create client (uses https://hub.sigwei.com by default)
client := hubclient.NewHubClient(nil)
// Get authentication message
msg, err := client.Auth.GetAuthMessage("0xYourWalletAddress")
if err != nil {
panic(err)
}
// Sign message with wallet (user does this)
signature := signWithWallet(msg.Message)
// Login
auth, err := client.Auth.Login(msg.Message, signature)
if err != nil {
panic(err)
}
fmt.Println("Logged in:", auth.User.WalletAddress)
// Get transaction history
history, err := client.History.GetHistory(&x402paytypes.HistoryParams{
Network: "base",
Limit: 50,
})
for _, tx := range history.Transactions {
fmt.Printf("Transaction: %s (%s)\n", tx.Status, tx.Network)
}
}Architecture
Hub-Specific Extensions
Authentication
Basic Authentication Flow
Check Authentication Status
Get Current User
Token Refresh
Manual Token Management
Logout
Transaction History
Basic Query
Auto-Refresh
Pagination
x402 Protocol Operations
Check Supported Networks
Verify Payment
Settle Payment (Standard)
Settle Payment with Options
Transfer (Hub-Specific)
Configuration
Default Configuration
Custom Configuration
Error Handling
HTTP Errors
Common Errors
Type Reference
Auth Types
History Types
Thread Safety
Testing with HubClient
Before: Manual HTTP Calls (~70 lines)
After: Using HubClient (~15 lines)
Benefits in Tests
Complete Examples
Best Practices
Related Documentation
Source Code
Last updated