Skip to content

X402 example#197

Open
1evi7eo wants to merge 2 commits intobnb-chain:mainfrom
1evi7eo:x402-example
Open

X402 example#197
1evi7eo wants to merge 2 commits intobnb-chain:mainfrom
1evi7eo:x402-example

Conversation

@1evi7eo
Copy link

@1evi7eo 1evi7eo commented Jan 24, 2026

Description

Adds an x402 payment protocol implementation on BNB Chain, demonstrating HTTP 402 "Payment Required" for internet-native payments with sign-to-pay.

This example:

  • Implements the x402 standard using HTTP 402 status codes
  • Demonstrates EIP-712 signature-based payment authorization
  • Shows sign-to-pay without API keys, registrations, or KYC
  • Includes payment request creation, signature verification, and on-chain execution
  • Provides an interactive web frontend for testing x402 payments
  • Integrates with MCP for AI agent interactions

X402 Interface

Motivation: x402 enables autonomous payments between AI agents, APIs, and services. This implementation shows how to use HTTP 402, EIP-712 signatures, and blockchain payments to create a payment flow without traditional authentication.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Unit tests: pytest test_x402_payment.py -v — all 10 tests pass
  • Manual testing:
    • Started server with ./run.sh
    • Verified frontend loads at http://localhost:5001
    • Created payment requests and verified EIP-712 signature generation
    • Tested signature verification with valid and invalid signatures
    • Executed payments and verified on-chain transaction completion
    • Tested payment status tracking and history
  • Integration testing:
    • Tested MCP tool integration (create_payment_request, verify_payment_signature, execute_payment, get_payment_status, list_payment_requests)
    • Verified virtual environment setup and dependency installation
    • Confirmed EIP-712 typed data signing works correctly
    • Tested payment request uniqueness with counter-based ID generation
    • Verified error handling for invalid addresses, signatures, and payment states

Test coverage includes:

  • Payment request creation with EIP-712 signatures
  • Signature verification and validation
  • Payment execution on-chain
  • Payment status tracking
  • Payment history and filtering
  • Error handling for edge cases

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Additional Notes

  • Implements EIP-712 typed data signing for cryptographic payment authorization
  • Demonstrates HTTP 402 "Payment Required" status code usage
  • Includes interactive frontend for testing the complete payment flow
  • Full MCP protocol support for AI agent integration
  • Comprehensive README with demo examples and usage instructions
  • Virtual environment setup script for easy deployment
  • All dependencies documented in requirements.txt
  • Fixed payment ID uniqueness issue using counter-based generation to prevent collisions

@vivixu-cmd
Copy link

Congratulations! You have received a Cookbook reward. Please reply with your BSC wallet address.Thanks

@1evi7eo
Copy link
Author

1evi7eo commented Jan 27, 2026

Congratulations! You have received a Cookbook reward. Please reply with your BSC wallet address.Thanks

Thank you for the opportunity to contribute!
0x23b23556c3CAA3C582EeE23Fc0D972352FB2a62c

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.

2 participants