SDKsGoOverview

Go SDK

The T402 Go SDK provides comprehensive support for HTTP-native stablecoin payments.

Installation

go get github.com/t402-io/t402/sdks/go@latest

CLI Tool

Install the CLI for quick operations:

go install github.com/t402-io/t402/sdks/go/cmd/t402@latest

CLI Commands

# Verify a payment
t402 verify <base64-payload>
 
# Settle a payment
t402 settle <base64-payload>
 
# List supported networks
t402 supported
 
# Encode JSON to base64
t402 encode payment.json
 
# Decode base64 to JSON
t402 decode <base64-string>
 
# Show network info
t402 info eip155:8453
 
# Show version
t402 version

CLI Flags

-f, --facilitator URL    Facilitator URL (default: https://facilitator.t402.io)
-o, --output FORMAT      Output format: json, text (default: text)

Features

  • Multi-Chain: All 11 blockchain families (EVM, Solana, TON, TRON, NEAR, Aptos, Tezos, Polkadot, Stacks, Cosmos, Bitcoin)
  • Server: HTTP middleware for payment protection (Gin, Echo, Chi, Fiber)
  • Client: HTTP client with automatic 402 handling
  • Facilitator: Full facilitator implementation
  • CLI: Command-line tools for testing and debugging
  • MCP Server: AI agent payment integration (6 tools)
  • Smart Bridge Router: Cross-chain USDT0 bridging via LayerZero

Quick Start

Client

package main
 
import (
    t402 "github.com/t402-io/t402/sdks/go"
    "github.com/t402-io/t402/sdks/go/mechanisms/evm/exact/client"
)
 
func main() {
    // Create client
    c := t402.NewClient()
 
    // Register EVM scheme
    evmScheme := client.NewExactEvmScheme(privateKey)
    c.Register("eip155:8453", evmScheme)
 
    // Make request - 402 handled automatically
    resp, err := c.Fetch("https://api.example.com/premium")
}

Server

package main
 
import (
    "github.com/gin-gonic/gin"
    t402gin "github.com/t402-io/t402/sdks/go/http/gin"
)
 
func main() {
    r := gin.Default()
 
    r.Use(t402gin.PaymentMiddleware(t402gin.Config{
        Routes: map[string]t402gin.RouteConfig{
            "GET /api/premium": {
                Scheme:  "exact",
                Network: "eip155:8453",
                Price:   "$0.01",
                PayTo:   "0x...",
            },
        },
        FacilitatorURL: "https://facilitator.t402.io",
    }))
 
    r.GET("/api/premium", func(c *gin.Context) {
        c.JSON(200, gin.H{"data": "Premium content!"})
    })
 
    r.Run(":3000")
}

Modules

ModuleDescription
sdks/goCore client, server, facilitator
sdks/go/mechanisms/evmEVM chains (Ethereum, Base, etc.)
sdks/go/mechanisms/svmSolana blockchain
sdks/go/mechanisms/tonTON blockchain
sdks/go/mechanisms/tronTRON blockchain
sdks/go/mechanisms/nearNEAR Protocol
sdks/go/mechanisms/aptosAptos blockchain
sdks/go/mechanisms/tezosTezos blockchain
sdks/go/mechanisms/polkadotPolkadot Asset Hub
sdks/go/mechanisms/stacksStacks (Bitcoin L2)
sdks/go/mechanisms/cosmosCosmos/Noble
sdks/go/mechanisms/btcBitcoin (PSBT) and Lightning (BOLT11)
sdks/go/httpHTTP client and server
sdks/go/http/ginGin middleware
sdks/go/http/echoEcho middleware
sdks/go/http/chiChi middleware
sdks/go/http/fiberFiber middleware
sdks/go/signers/evmEVM wallet signers
sdks/go/signers/svmSolana wallet signers
sdks/go/signers/tonTON wallet signers
sdks/go/signers/tronTRON wallet signers
sdks/go/signers/nearNEAR wallet signers
sdks/go/signers/aptosAptos wallet signers
sdks/go/signers/tezosTezos wallet signers
sdks/go/signers/polkadotPolkadot wallet signers
sdks/go/signers/stacksStacks wallet signers
sdks/go/signers/cosmosCosmos wallet signers
sdks/go/extensions/bazaarAPI discovery extension
sdks/go/mcpMCP server library
sdks/go/cmd/t402CLI tool
sdks/go/cmd/t402-mcpMCP server binary

Module Structure

Multi-Chain Support

EVM Networks

import "github.com/t402-io/t402/sdks/go/mechanisms/evm"
 
// Get network config
config := evm.NetworkConfigs["eip155:8453"] // Base

TON Network

import "github.com/t402-io/t402/sdks/go/mechanisms/ton"
 
// Get network config
config := ton.NetworkConfigs[ton.TonMainnetCAIP2]

TRON Network

import "github.com/t402-io/t402/sdks/go/mechanisms/tron"
 
// Get network config
config := tron.NetworkConfigs[tron.TronMainnetCAIP2]

Solana

import "github.com/t402-io/t402/sdks/go/mechanisms/svm"
 
// Get network config
config := svm.NetworkConfigs[svm.SolanaMainnetCAIP2]

NEAR Protocol

import "github.com/t402-io/t402/sdks/go/mechanisms/near"
 
// Get network config
config := near.NetworkConfigs[near.NearMainnetCAIP2]

Aptos

import "github.com/t402-io/t402/sdks/go/mechanisms/aptos"
 
// Get network config
config := aptos.NetworkConfigs[aptos.AptosMainnetCAIP2]

Tezos

import "github.com/t402-io/t402/sdks/go/mechanisms/tezos"
 
// Get network config
config := tezos.NetworkConfigs[tezos.TezosMainnetCAIP2]

Polkadot Asset Hub

import "github.com/t402-io/t402/sdks/go/mechanisms/polkadot"
 
// Get network config
config := polkadot.NetworkConfigs[polkadot.PolkadotAssetHubCAIP2]

Stacks (Bitcoin L2)

import "github.com/t402-io/t402/sdks/go/mechanisms/stacks"
 
// Get network config
config := stacks.NetworkConfigs[stacks.StacksMainnetCAIP2]

Facilitator Client

import t402http "github.com/t402-io/t402/sdks/go/http"
 
client := t402http.NewHTTPFacilitatorClient(&t402http.FacilitatorConfig{
    URL:     "https://facilitator.t402.io",
    Timeout: 30 * time.Second,
})
 
// Verify payment
result, err := client.Verify(ctx, payload, requirements)
 
// Settle payment
result, err := client.Settle(ctx, payload, requirements)
 
// Get supported networks
supported, err := client.GetSupported(ctx)

Core Interfaces

// Client interface
type X402Client interface {
    Register(network string, scheme SchemeNetworkClient)
    CreatePaymentPayload(requirements PaymentRequirements) (*PaymentPayload, error)
    Fetch(url string, opts ...RequestOption) (*http.Response, error)
}
 
// Server interface
type X402ResourceServer interface {
    Register(network string, scheme SchemeNetworkServer)
    Verify(payload *PaymentPayload, req PaymentRequirements) (*VerifyResponse, error)
    Settle(payload *PaymentPayload, req PaymentRequirements) (*SettleResponse, error)
}
 
// Facilitator interface
type X402Facilitator interface {
    Register(network string, scheme SchemeNetworkFacilitator)
    Verify(payload *PaymentPayload, req PaymentRequirements) (*VerifyResponse, error)
    Settle(payload *PaymentPayload, req PaymentRequirements) (*SettleResponse, error)
    GetSupported() *SupportedResponse
}

Documentation

Requirements

  • Go 1.24+