x402/SDK RootStock

Payment Integrations dead simple: A x402 based sdk and payment system for RootStock.

x402/SDK RootStock

Created At

ETHGlobal New Delhi

Project Description

X402 is a blockchain-based micropayment system built on RootStock that enables pay-per-use access to APIs and digital services using USDRIF stablecoin tokens. The system automatically processes payments through smart contracts and grants time-limited access to premium endpoints, creating a decentralized marketplace where users only pay for what they use while leveraging Bitcoin's security through RootStock's merged mining technology.

How it's Made

This project majorly uses solidity and JS/TS along with popular OSS libraries such as ethers.

This project is spread apart in 2 parts:

  • Contracts - These manage payments processing on chain
  • SDK - This interacts with the above contracts to make it dead simple to integrate x402 payments in their applications.

Also created a sample backend and frontend to test the system and SDK. Backend is simply to store/show the paywallet resource + some helper GET API's for getting payment status etc.

Frontend is the meat where everything is managed. User's can just either make a service, or subscribe to one. Once subscribed they can view the paywalled content.

The goal was to have a sdk which makes it dead simple to integrate in your Backend on paywalled resources, and in FE to make purchases on resources.

Have also built postman collection for supporting backend. Deployed the backend at `https://x402.prix0007.dev which is deployed on a simple server via a nginx proxy. For frontend it's simply built from the pipeline of vercel on push to main trunk branch.

Package is available at https://www.npmjs.com/package/@prix0007/x402-payments-sdk and can be installed simply by: npm i @prix0007/x402-payments-sdk makes it dead simple to integrate since everything is available in package including client and server code.

Available Addresses on rskTestnet: https://explorer.testnet.rootstock.io/address/0x7ce9684f7216d5b6a628447a7572b03753b9ea2d -> Paymentgateway https://explorer.testnet.rootstock.io/address/0xa1fbd37f47fd9cdfec3386ee3d80af5b6b4fabd7 -> Service Registry https://explorer.testnet.rootstock.io/address/0xafd4915897a6e72825e27096e43755b22b514fa7 -> AccessControl

Doing the contract system helps to keep everything onchain except the resource which resource provider can easily check with SDK if the accessing user have paid for it or not. This same approach can easily be exteneded to AI agentic usage, Magazine subscriptions, etc.

Inspired by: https://www.x402.org/x402-whitepaper.pdf

background image mobile

Join the mailing list

Get the latest news and updates