Skip to main content

b402 payments on BSC

Project description

b402

Gasless crypto payments on BSC. Users pay zero gas fees.

Install

pip install b402

Quick Start

from b402 import B402

b402 = B402()

# One-time setup (approve relayer)
b402.setup("USD1")

# Send payment (gasless!)
result = b402.pay(
    amount="0.01",
    token="USD1",
    recipient="0x..."
)

if result.success:
    print(f"TX: https://bscscan.com/tx/{result.tx_hash}")

Or use the one-liner (after setup):

from b402 import pay

result = pay(amount="0.01", token="USD1", recipient="0x...")

Reads PRIVATE_KEY from environment. Defaults to BSC mainnet.

Complete Example

from b402 import B402

b402 = B402()

# Step 1: Check if setup is needed
approved, allowance = b402.check_approval("USD1")

if not approved:
    print("Setting up (one-time)...")
    result = b402.setup("USD1")
    print(f"Approved! TX: {result['tx_hash']}")

# Step 2: Send payment (gasless!)
payment = b402.pay(
    amount="0.01",
    token="USD1",
    recipient="0x96625c0e209b4e0d4741d8a3ffb6b91c0da6fa5f"
)

if payment.success:
    print(f"Paid {payment.amount} {payment.token}")
    print(f"TX: https://bscscan.com/tx/{payment.tx_hash}")
else:
    print(f"Error: {payment.error}")

Run the complete demo: python examples/complete_demo.py

How It Works

  1. Setup (one-time): Approve B402 relayer to spend tokens (costs gas, ~$0.10)
  2. Payment (gasless): Sign EIP-712 authorization, relayer submits transaction and pays gas
  3. Settlement: Payment settles on-chain in <3 seconds

Supported Tokens

Mainnet: USD1, USDT, USDC Testnet: USDT

API Reference

B402()

Create B402 client. Defaults to mainnet.

b402 = B402()  # mainnet
b402_test = B402(network="testnet")

b402.setup(token)

One-time setup: approve relayer to spend tokens.

result = b402.setup("USD1")
# Returns: {"approved": True, "allowance": int, "tx_hash": "0x..."}

b402.check_approval(token)

Check if token is approved.

approved, allowance = b402.check_approval("USD1")

b402.pay(amount, token, recipient)

Send gasless payment.

result = b402.pay(amount="0.01", token="USD1", recipient="0x...")
# Returns: PaymentResult(success, tx_hash, error, payer, recipient, amount, token)

pay() - One-liner

Factory function for simple usage (after setup).

from b402 import pay

result = pay(amount="0.01", token="USD1", recipient="0x...")

Environment Variables

  • PRIVATE_KEY - Required. Your wallet private key (with 0x prefix)

Examples

Network Details

BSC Mainnet (Chain ID: 56)

  • Relayer: 0xE1C2830d5DDd6B49E9c46EbE03a98Cb44CD8eA5a
  • USD1: 0x8d0d000ee44948fc98c9b98a4fa4921476f08b0d
  • USDT: 0x55d398326f99059fF775485246999027B3197955
  • USDC: 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d

BSC Testnet (Chain ID: 97)

  • Relayer: 0x62150F2c3A29fDA8bCf22c0F22Eb17270FCBb78A
  • USDT: 0x337610d27c682E347C9cD60BD4b3b107C9d34dDd

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

b402-1.0.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

b402-1.0.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file b402-1.0.0.tar.gz.

File metadata

  • Download URL: b402-1.0.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for b402-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f4c7766686d90019bd6e2bdc624463684ee6ecb77ad3c23c0d5c19151565938c
MD5 ab171414271b4919420382ca68805186
BLAKE2b-256 9723938d56cf6b32ac0e15a44f6b125e0f923b88c0046a68c4cbc9ea8efacb76

See more details on using hashes here.

File details

Details for the file b402-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: b402-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for b402-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25403dafd8075b080eea73fdcb668a1d6d9145170c947fea267f7a88bad2033d
MD5 2784094c5398f66508f0d5969bf4dd1a
BLAKE2b-256 9c4e4010f08886e802791ab7300e19fd7f791dada237d7109237279d86ac9671

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page