Installation
Get started with OpenLibx402 Go packages in minutes.
Prerequisites
Go : 1.21 or later
Solana Wallet : For testing (testnet/devnet tokens recommended)
Git : For cloning the repository
Package Installation
Option 1: Using go get (Recommended for Users)
Install the packages you need:
# Core protocol (required)
go get github.com/openlibx402/go/openlibx402-core
# Client for consuming APIs
go get github.com/openlibx402/go/openlibx402-client
# Middleware for your framework
go get github.com/openlibx402/go/openlibx402-nethttp
# or
go get github.com/openlibx402/go/openlibx402-echo
Option 2: Development Installation (for Contributors)
# Clone the repository
git clone https://github.com/openlibx402/openlibx402.git
cd openlibx402
# Navigate to a package
cd packages/go/openlibx402-core
# Install dependencies
go mod tidy
# Build and test
go build
go test ./...
Verifying Installation
Verify with Go
go list -m github.com/openlibx402/go/openlibx402-core
Output should show:
github.com/openlibx402/go/openlibx402-core v0.1.0
Verify with pkg.go.dev
Visit: https://pkg.go.dev/github.com/openlibx402/go/openlibx402-core
Import Statements
Once installed, you can import in your code:
package main
import (
"github.com/openlibx402/go/openlibx402-core"
"github.com/openlibx402/go/openlibx402-client"
)
Or with aliases:
import (
nethttp "github.com/openlibx402/go/openlibx402-nethttp"
echox402 "github.com/openlibx402/go/openlibx402-echo"
)
Environment Setup
For Server Development
Create a .env file:
# Your Solana wallet address
X402_PAYMENT_ADDRESS = "YOUR_SOLANA_WALLET_ADDRESS"
# USDC token mint (devnet: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v)
X402_TOKEN_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
# Network (solana-devnet, solana-mainnet)
X402_NETWORK = "solana-devnet"
# RPC endpoint
X402_RPC_URL = "https://api.devnet.solana.com"
# Server port
PORT = 8080
Load in your code:
import "os"
paymentAddress := os . Getenv ( "X402_PAYMENT_ADDRESS" )
tokenMint := os . Getenv ( "X402_TOKEN_MINT" )
For Client Development
# Your wallet's private key (base58 encoded)
export X402_PRIVATE_KEY = "your-base58-private-key"
# Optional: RPC endpoint
export X402_RPC_URL = "https://api.devnet.solana.com"
Getting Devnet Tokens
To test on Solana devnet:
Create a Solana wallet:
Get devnet SOL:
solana airdrop 2 $( solana address) --url devnet
Get devnet USDC:
Use spl-token
Or visit a devnet faucet
Troubleshooting
Module not found error
go: github.com/openlibx402/go/openlibx402-core@latest:
reading go.sum: no matching version found
Solution : Clear module cache and retry:
go clean -modcache
go get github.com/openlibx402/go/openlibx402-core@latest
Version mismatch
different modules with the same import path
Solution : Ensure you're using the correct import path:
# Wrong (old path)
import "github.com/openlibx402/openlibx402/go/openlibx402-core"
# Correct (simplified path)
import "github.com/openlibx402/go/openlibx402-core"
Missing Go version
Solution : Update Go:
# macOS with Homebrew
brew upgrade go
# Or download from https://golang.org/dl/
Next Steps
After installation:
Choose Your Path :
Server Quick Start - Build a payment-required API
Client Quick Start - Build a payment client
Explore Examples :
net/http Server Example
Echo Server Example
Learn More :
Core Library
Client Library
Support