Integrate RelAI facilitator for x402 payment processing
RelAI is a hosted facilitator service that simplifies x402 payment processing on SKALE Network. Instead of running your own facilitator infrastructure, you can use RelAI’s SDK to handle payment verification and settlement across multiple tokens.
The RelAI facilitator has enabled BITE transactions for both SKALE Base and SKALE Base Sepolia.What does this mean?
When a merchant settles any x402 transaction through RelAI facilitator it gets automatically encrypted through BITE and only decrypted at the consensus level
For more inforamtion around BITE please check here.
# Your wallet address to receive paymentsPAYMENT_RECEIVER_ADDRESS=0xYourWalletAddressHere# Private key for client (NEVER commit this!)PRIVATE_KEY=0xYourPrivateKeyHere# Server portPORT=3000# Price for premium endpoint (in USD)PREMIUM_PRICE=0.01
import express from 'express';import cors from 'cors';import dotenv from 'dotenv';import Relai from '@relai-fi/x402/server';dotenv.config();const app = express();const PORT = process.env.PORT || 3000;// Middlewareapp.use(cors());app.use(express.json());// Initialize RelAI SDK for SKALE Base Sepoliaconst relai = new Relai({ network: 'skale-base-sepolia', facilitatorUrl: 'https://facilitator.x402.fi'});// Public endpoint - no payment requiredapp.get('/api/public', (req, res) => { res.json({ message: 'This is a public endpoint - no payment required', network: 'SKALE Base Sepolia' });});// Premium endpoint - protected by x402 paymentapp.get( '/api/premium', relai.protect({ payTo: process.env.PAYMENT_RECEIVER_ADDRESS!, price: parseFloat(process.env.PREMIUM_PRICE || '0.01'), }), (req, res) => { // Payment is automatically verified by the middleware // req.payment contains the payment details res.json({ success: true, message: 'Premium data unlocked via RelAI!', payment: req.payment }); });// Start serverapp.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`);});
Copy
import dotenv from 'dotenv';import { createX402Client } from '@relai-fi/x402/client';import { privateKeyToAccount } from 'viem/accounts';dotenv.config();async function main() { const SERVER_URL = process.env.SERVER_URL || 'http://localhost:3000'; // Create account from private key const privateKey = process.env.PRIVATE_KEY as `0x${string}`; const account = privateKeyToAccount(privateKey); // Create x402 client with RelAI const client = createX402Client({ wallets: { evm: { address: account.address, signTypedData: (params) => account.signTypedData(params as any), }, }, }); // Access RelAI-protected resource const response = await client.fetch(`${SERVER_URL}/api/premium`); if (response.ok) { const data = await response.json(); console.log('Data received:', data); }}main().catch(console.error);
This entity — RelAI — is deployed and actively supporting SKALE. These are 3rd party services that may have their own terms and conditions and privacy policies. Use these services at your own risk. AI and agents is a highly experimental space; the 3rd party software solutions may have bugs or be unaudited. You and your agents and your customers use all 3rd party services chosen at your own risk and per their terms.