@erudite-intelligence/x402-ftm
v1.0.0
Published
x402 exact payment scheme implementation for Fantom/Sonic FTM
Downloads
48
Maintainers
Readme
@erudite-intelligence/x402-ftm
x402
exactpayment scheme implementation for Fantom/Sonic FTM.
Part of the EruditePay x402 multi-chain payment infrastructure by Erudite Intelligence LLC.
Overview
This package implements the x402 protocol's exact payment scheme for the Fantom Opera and Sonic networks. Standard EVM-compatible native FTM transfers using ethers.js.
- CAIP-2 Network ID:
eip155:250(Opera) /eip155:146(Sonic) - Unit: wei (1 FTM = 10^18 wei)
- Signing: ECDSA secp256k1 via ethers.js
- Verification: EVM RPC (Ankr, Fantom public, Sonic)
- Tx type: EIP-1559
Installation
npm install @erudite-intelligence/x402-ftmUsage
Client — Create a Payment
import { createPayment } from "@erudite-intelligence/x402-ftm";
const paymentHeader = await createPayment({
senderPrivateKey: "0xabc123...",
recipientAddress: "0xdef456...",
amountWei: "1000000000000000000", // 1 FTM
network: "mainnet",
});Server — Verify & Settle
import { verifyAndSettle } from "@erudite-intelligence/x402-ftm";
const result = await verifyAndSettle({
paymentHeader: req.headers["x-payment"],
expectedRecipient: "0xdef456...",
expectedAmountWei: "1000000000000000000",
network: "mainnet",
});
if (result.success) {
console.log("Settled:", result.txHash);
}Sonic Support
Pass network: "sonic" to use the Sonic (S) chain (chain ID 146):
const paymentHeader = await createPayment({
senderPrivateKey: "0xabc123...",
recipientAddress: "0xdef456...",
amountWei: "1000000000000000000",
network: "sonic",
});Security
- Replay protection: In-memory Map with 1-hour TTL. Multi-instance deployments MUST use Redis/DB.
- Fail-closed: If balance query or RPC fails, the payment is REJECTED.
- On-chain verification: Signed transaction fields (to, value, chainId) are parsed and verified before broadcast.
License
MIT — Erudite Intelligence LLC
