Skip to content

feat: replace manual Solana x402 with official x402 SDK#4

Closed
notorious-d-e-v wants to merge 1 commit intoBlockRunAI:mainfrom
notorious-d-e-v:feat/use-official-x402-sdk
Closed

feat: replace manual Solana x402 with official x402 SDK#4
notorious-d-e-v wants to merge 1 commit intoBlockRunAI:mainfrom
notorious-d-e-v:feat/use-official-x402-sdk

Conversation

@notorious-d-e-v
Copy link
Contributor

Summary

  • Replace ~200 lines of manual Solana transaction construction (ATA derivation, signing, instruction building) with the official x402 Python SDK (pip install x402[svm])
  • This fixes both bugs from fix: correct Associated Token Program ID for Solana payments #2 (wrong ATA program ID + missing v0 signing prefix) by delegating to the battle-tested SDK maintained by Coinbase
  • Net reduction of ~210 lines of code while gaining future protocol compatibility

Changes

File Change
pyproject.toml Replace solders+base58 with x402[svm] in solana optional deps
blockrun_llm/x402.py Remove entire Solana section (~180 lines), keep EVM code unchanged
blockrun_llm/solana_client.py Use x402ClientSync + KeypairSigner + ExactSvmScheme for payment signing
tests/unit/test_x402.py Replace manual Solana payload tests with x402 SDK integration tests

How it works

# Before: ~150 lines of manual transaction building
payload = create_solana_payment_payload(
    private_key=key, recipient=addr, amount=amt, fee_payer=fp, ...
)

# After: x402 SDK handles everything
payment_required = decode_payment_required_header(header)
payment_payload = x402_client.create_payment_payload(payment_required)
encoded = encode_payment_signature_header(payment_payload)

Notes

  • The solana optional dependency now requires Python ≥3.10 (x402 SDK requirement). Base EVM functionality still works on Python 3.9.
  • The x402 SDK adds a memo instruction to transactions (optional per protocol spec, accepted by facilitator)
  • Backwards-compatible key handling: supports both full 64-byte keypairs and 32-byte seeds via fallback

Test plan

  • All 89 unit tests pass
  • Live Solana payment verified — tx on Solscan

Closes #3

Replace ~200 lines of manual Solana transaction construction, ATA
derivation, and signing code with the official x402 Python SDK
(pip install x402[svm]).

This fixes two known bugs in the manual implementation:
- Wrong Associated Token Program ID (caused recipient_mismatch errors)
- Missing v0 version prefix when signing (caused signature failures)

The official SDK handles all of this correctly and is maintained by
Coinbase, ensuring future protocol compatibility.

Changes:
- pyproject.toml: replace solders+base58 with x402[svm] in solana deps
- x402.py: remove Solana section (~180 lines), keep EVM code unchanged
- solana_client.py: use x402ClientSync + KeypairSigner + ExactSvmScheme
  for payment creation instead of manual transaction construction
- tests: replace manual Solana payload tests with x402 SDK integration
  tests (ATA derivation, signer, header decoding)

Closes BlockRunAI#3
@1bcMax 1bcMax closed this in 517355d Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace manual x402 Solana implementation with official x402 Python SDK

1 participant