-
Notifications
You must be signed in to change notification settings - Fork 3
Closed
Description
Problem
blockrun_llm/x402.py manually reimplements the x402 client-side payment logic for Solana (ATA derivation, transaction building, v0 signing, blockhash fetching). This has led to two bugs that break all Solana payments:
- Wrong Associated Token Program ID —
ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJe1bRSinstead ofATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL(causesrecipient_mismatch) - Missing v0 version prefix when signing —
bytes(message)instead ofb'\x80' + bytes(message)(causesSignatureFailure)
Both are fixed in #2, but the root cause is maintaining a parallel implementation of logic that already exists in the official SDK.
Proposed Solution
Replace the manual Solana x402 implementation with the official x402 Python SDK (v2.3.0+):
pip install "x402[svm]"The official SDK's ExactSvmScheme already handles:
- Correct ATA derivation (including Token-2022 support)
- v0 message signing with
0x80prefix - Token program detection from on-chain mint owner
- Decimals fetched from mint data (not hardcoded)
- Memo instruction with random nonce for uniqueness
- Compute budget instructions
Example integration
from x402 import x402ClientSync
from x402.mechanisms.svm.exact import ExactSvmScheme
from x402.mechanisms.svm.signers import KeypairSigner
signer = KeypairSigner.from_base58(private_key)
client = x402ClientSync()
client.register("solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp", ExactSvmScheme(signer=signer))
# Create payment payload from 402 response
payload = client.create_payment_payload(payment_required)This would replace ~200 lines of manual transaction construction in x402.py and eliminate an entire class of bugs by staying in sync with the facilitator's expectations.
Benefits
- Correctness: maintained alongside the x402 facilitator, so client and server always agree on transaction format
- Future-proof: new features (Token-2022, new instructions) are handled upstream
- Less code to maintain: removes
_get_ata(),_get_latest_blockhash(),create_solana_payment_payload(), and all the Solana constants
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels