Smart contracts for the x402 payment protocol on TRON and EVM chains. Enables gasless, signature-based (EIP-712) payment authorizations and native token settlement.
x402 is an open, neutral standard for internet-native payments. It brings to life the HTTP 402 Payment Required status code so that servers can request payment from clients in a programmatic way—ideal for API paywalls, agent-to-agent payments, and micropayments.
- Zero protocol fees — only network fees
- HTTP-native — payment flows fit into normal HTTP requests
- Multi-chain — this repo provides the TRON and EVM implementation
- EIP-712 typed permits — Users sign payment details off-chain; a relayer or backend calls
permitTransferFromwith the signature. - Gasless for the signer — The submitter pays gas; the signer only needs a one-time
approveof the Permit402 contract. - Optional fee — Permit can include
feeToandfeeAmountfor protocol or facilitator fees. - Replay protection — Nonce bitmap per owner; time window via
validAfter/validBefore.
| Component | Role | File(s) |
|---|---|---|
| Permit402 (EVM) | Entry point for EVM chains (Ethereum, BSC, etc.) | contracts/evm/Permit402.sol |
| Permit402 (TRON) | Entry point for TRON (USDT-compatible) | contracts/tron/Permit402.sol |
| Permit402Base | Shared logic, EIP-712, nonce | contracts/core/Permit402Base.sol |
| PermitHash | EIP-712 struct hashes | contracts/libraries/PermitHash.sol |
| EIP712 | Domain separator and typed data hashing | contracts/core/EIP712.sol |
| IPermit402 | Structs and interface for permits | contracts/interface/IPermit402.sol |
Flow: User signs Permit402Details (payment, fee, validity, nonce) → Relayer/backend calls permitTransferFrom(permit, owner, signature) → Contract pulls tokens from owner to payTo (and optional feeTo) in one shot.
| Network | Chain / Environment | Permit402 Address |
|---|---|---|
| TRON Mainnet | Mainnet | TT8rEWbCoNX7vpEUauxb7rWJsTgs8vDLAn |
| TRON Nile | Testnet | TFxDcGvS7zfQrS1YzcCMp673ta2NHHzsiH |
| TRON Shasta | Testnet | TR2XninQ3jsvRRLGTifFyUHTBysffooUjt |
| Network | Chain / Environment | Permit402 Address |
|---|---|---|
| BSC Mainnet | Mainnet | 0x105a6f4613a1d1c17ef35d4d5f053fa2e659a958 |
| BSC Testnet | Testnet | — |
- EVM (ethereum, sepolia, bsc, bscTestnet):
npx hardhat deploy --network <network> - TRON (tron, nile, shasta):
npx hardhat deploy --network <network>
# Compile (Hardhat, with tronSolc for TRON targets)
npx hardhat compile
# Test with Foundry
forge test -vvv
# Test with Hardhat
npx hardhat test├── contracts/
│ ├── core/
│ │ ├── Permit402Base.sol # Shared permit logic (abstract)
│ │ └── EIP712.sol # EIP-712 domain and hashing
│ ├── evm/
│ │ └── Permit402.sol # EVM implementation (Ethereum, BSC, etc.)
│ ├── tron/
│ │ └── Permit402.sol # TRON implementation (USDT-compatible)
│ ├── interface/
│ │ ├── IPermit402.sol # Permit structs and interface
│ │ ├── IEIP712.sol
│ │ └── IERC1271.sol
│ └── libraries/
│ ├── PermitHash.sol # TypeHashes and struct hashes
│ └── SafeTransferLib.sol # EVM safe transfer (returns bool)
├── deploy/ # EVM deploy scripts (hardhat-deploy)
├── deployTron/ # TRON deploy scripts (sunhat)
├── test/
├── hardhat.config.ts # Hardhat + sunhat + hardhat-foundry config
├── foundry.toml # Foundry config (tests & remappings)
└── AGENTS.md # Guidelines for AI/agent use of this repo
- Domain & types — Use the same EIP-712 domain name
"Permit402"and the struct definitions fromIPermit402.solandPermitHash.solso that hashes match the contract. Domain separator usesblock.chainidand contract address (seecontracts/core/EIP712.sol). - ChainId for signing — When building EIP-712 typed data, use the chainId of the target network so the signature matches the contract. Wallet/TronLink must use the same chainId.
- Sign off-chain — Build
Permit402Details(meta, buyer, caller, payment, fee, delivery), hash withPermitHashand domain separator, then sign (e.g. 65-byter || s || v). - Submit on-chain — Call
permitTransferFrom(permit, transferDetails, owner, signature). Theownermust have approved the Permit402 contract for thepayToken(and have sufficient balance foramountplus optionalfeeAmount).
For full struct and field definitions, see contracts/interface/IPermit402.sol.
- Access: Only the signer's signature authorizes transfers; no single admin can move user funds.
- Replay: Nonces and
validAfter/validBeforelimit replay across chains and time.
We welcome responsible disclosure. Please report issues privately before public disclosure when possible.
MIT. See LICENSE for full text.
- Fork the repo and open a branch from
main. - Follow existing style (Solidity ^0.8.20, existing patterns in
Permit402Base.solandPermitHash.sol). - Add or update tests for new behavior.
- Open a PR with a clear description; maintainers will review.
For agent/AI usage of this codebase, see AGENTS.md.