mechanisms/svm/exact/server
import "github.com/x402-foundation/x402/go/v2/mechanisms/svm/exact/server"
Constants
Server error constants for the exact SVM (Solana) scheme (V2)
Source: mechanisms/svm/exact/server/errors.go:5
const (
ErrAmountMustBeString = "invalid_exact_solana_server_amount_must_be_string"
ErrFailedToParsePrice = "invalid_exact_solana_server_failed_to_parse_price"
ErrInvalidPriceFormat = "invalid_exact_solana_server_invalid_price_format"
ErrFailedToConvertAmount = "invalid_exact_solana_server_failed_to_convert_amount"
ErrFailedToParseAmount = "invalid_exact_solana_server_failed_to_parse_amount"
)Functions
func NewExactSvmScheme(config ...*svm.ServerConfig) *ExactSvmScheme
Source: mechanisms/svm/exact/server/scheme.go:23
NewExactSvmScheme creates a new ExactSvmScheme
Types
type ExactSvmScheme
Source: mechanisms/svm/exact/server/scheme.go:17
ExactSvmScheme implements the SchemeNetworkServer interface for SVM (Solana) exact payments (V2)
type ExactSvmScheme struct {
// contains filtered or unexported fields
}func EnhancePaymentRequirements( ctx context.Context, requirements types.PaymentRequirements, supportedKind types.SupportedKind, extensionKeys []string, ) (types.PaymentRequirements, error)
Source: mechanisms/svm/exact/server/scheme.go:198
EnhancePaymentRequirements adds scheme-specific enhancements to V2 payment requirements
func ParsePrice(price x402.Price, network x402.Network) (x402.AssetAmount, error)
Source: mechanisms/svm/exact/server/scheme.go:84
ParsePrice parses a price and converts it to an asset amount (V2) If price is already an AssetAmount, returns it directly. If price is Money (string | number), parses to decimal and tries custom parsers. Falls back to default conversion if all custom parsers return nil.
Args:
price: The price to parse (can be string, number, or AssetAmount map)
network: The network identifierReturns:
AssetAmount with amount, asset, and optional extra fieldsfunc RegisterMoneyParser(parser x402.MoneyParser) *ExactSvmScheme
Source: mechanisms/svm/exact/server/scheme.go:66
RegisterMoneyParser registers a custom money parser in the parser chain. Multiple parsers can be registered - they will be tried in registration order. Each parser receives a decimal amount (e.g., 1.50 for $1.50). If a parser returns nil, the next parser in the chain will be tried. The default parser is always the final fallback.
Args:
parser: Custom function to convert amount to AssetAmount (or nil to skip)Returns:
The server instance for chainingExample:
svmServer.RegisterMoneyParser(func(amount float64, network x402.Network) (*x402.AssetAmount, error) {
// Use custom token for large amounts
if amount > 100 {
return &x402.AssetAmount{
Amount: fmt.Sprintf("%.0f", amount * 1e9),
Asset: "CustomTokenMint111111111111111111111",
Extra: map[string]interface{}{"token": "CUSTOM", "tier": "large"},
}, nil
}
return nil, nil // Use next parser
})func Scheme) Scheme() string
Source: mechanisms/svm/exact/server/scheme.go:35
Scheme returns the scheme identifier
