https://github.com/coinbase/x402
To understand the process, I created a new repository (https://github.com/gin-lsl/x402-solana-demo) containing all the Server, Client, and Facilitator components. Here, Koa was chosen as the base framework to enable the client to obtain access to a specific interface provided by the server by paying with Devnet’s USDC (a custom token). Some explanations First, I created the corresponding token using the spl-token tool, which can be seen here: https://solscan.io/token/9gKBTRXgVTszU31A12oJKKSy6aje8LyoVvNfSimembHo?cluster=devnet Solana was chosen here because this chain is very developer-friendly, providing an almost unlimited amount of test tokens for everyone to develop and test. It does not set any barriers, does not require login, does not require linking any social media accounts, and does not require a wallet with a balance on the mainnet. If you need to run the project, you need to create a .env file, fill in the required environment variables, and then start the server and run the client code in the terminal: Code Explanation Since this is only for demonstration purposes, they are simply placed in one location. Below are some key document descriptions: solana.ts It provides an interface called “/solana/get-balance”, which we assume is a valuable interface that requires a small fee to call. As the Server, it corresponds to parts (5) to (8) in the sequence diagram, and more specifically, part (7). Typically, servers only handle business logic and don’t need to deal with on-chain transactions. Therefore, even if a system’s developers are unfamiliar with Web3, they can still integrate Web3 payment methods with minimal changes to their business logic. facilitator.ts It implements the capabilities of Facilitator, mainly providing the /supported, /verify, and /settle interfaces, which are used to query currently supported chains, verify transaction data, and provide on-chain settlement capabilities, respectively. This is where it interacts with the chain, requiring a private key to pay on-chain transaction fees. Architecturally, it is independent of the Server (i.e., solana.ts), corresponding to (9) and (10) in the sequence diagram; Even if you decide to provide your own Facilitator service, this part of the code is actually standardized, and you can basically use the official pattern directly without having to implement it yourself. However, currently the official support is only full for base. If you want to use other chains, some adaptation work is required. This mainly involves sending simulated transactions to the chain to verify the transactions (if it’s a chain that “x402” already supports, you can directly call the verify function), and officially submitting the transactions to the chain and waiting for final confirmation (if it’s a chain that “x402” already supports, you can directly call the settle function). For the Solana chain, after the request reaches POST /settle, the settle function in “x402/facilitator” is called. After some verification, sendTransaction on RPC is called to send the transaction, and then waitForRecentTransactionConfirmation is used to wait for and confirm the transaction result. The relevant code is provided by @solana/kit. The EVM part follows similar logic. x402-middleware.ts Used to connect the Server and Facilitator, it acts as a Koa middleware, guarding APIs that require payment to access. The code references the official “x402-express”. Its function is to automatically return a 402 status and forward /verify and /settle requests. My code in this section essentially just assembles various parameters and forwards them to the facilitator or returns them to the client. For ease of testing and to avoid delving into too much detail, I’ve written most parameters as fixed values. These include: Setting maxAmountRequired to a very large value will actually be validated on the client side. If the amount the user needs to pay is higher than this value, an exception will be thrown directly. The asset was set to our own created token: 9gKBTRXgVTszU31A12oJKKSy6aje8LyoVvNfSimembHo, instead of the token address built into x402. On the mainnet, this should be the official USDC address. Interestingly, x402-express implements a Koa-like onion model by rewriting functions on the Response. Therefore, in their middleware for Express, the actual flow is verify -> business logic -> settle. Submitting to the blockchain occurs after executing the business logic, which indeed matches the sequence diagram above. Implementing this logic is very simple in Koa, but requires some additional code in Express, which may be why they prioritized providing Express middleware. payment-client-fetch.ts Acting as a client, it initiates requests to the server, corresponding to steps 1 through 4 in the flowchart. This utilizes helper functions provided by “x402-fetch” to automatically handle 402 statuses, generate signatures using the client wallet’s private key, and resend the data. It will attempt to directly request the interface. Upon encountering a 402 error, it will read the returned content (which should contain the x402 version supported by the server, currently fixed at 1, and the required parameters for the server), sign the transaction using your private key, and then serialize the transaction information and resend it to the original URL via the X-PAYMENT Header. After understanding the basic structure of the project, we can run the Server and Client using the following commands: Client execution results and logs: سوچو In my opinion, if the previous efforts of Web3 developers were aimed at lowering the barrier to entry for ordinary users to use Web3, making it easier for end users to utilize the Web3 ecosystem (payments, investments, etc.), then the current x402 was created to lower the barrier to entry for Web2 developers to access Web3 payment channels. While the helper functions provided in the x402/client section are useful, they only do what they’re supposed to do. Users can already easily pay with USDC and other currencies via their wallets. Therefore, relatively speaking, x402 is probably more significant for developers and service providers. However, the widespread adoption of x402 will still encounter many problems. Large companies have their own internal settlement systems, and they will have their own attitudes and pace regarding how to integrate new standards. Integrating a new payment method into their existing systems will inevitably be a long and arduous process. Furthermore, large companies will have to consider regulatory implications when integrating payment methods, which may force them to abandon more convenient payment methods and continue using traditional, complex solutions. Perhaps Node RPC providers would prefer it. In addition to providing basic interfaces, RPC providers also offer many Advance APIs, transaction acceleration interfaces, etc. If these can be provided through x402, perhaps more people can experience their services. Finally, please note that x420 itself is just a basic payment protocol. Its significance lies in proposing a set of standardized technical specifications. With a recognized standard, it becomes easier for developers and companies of all sizes to collaborate on improving the entire ecosystem. We should view the proposal of new standards rationally and avoid falling into the narrative traps set by hype-mongers. This article was written by ZAN Team (X account @zan_team ). یہ مضمون انٹرنیٹ سے لیا گیا ہے: Web3 Beginner Series: Exploring New On-Chain Payment Protocols – x402Recommended Articles Related: With the tariff threat temporarily lifted, is the bull market coming back? Author|Azuma ( @azuma_eth ) As tariff negotiations between China and the United States have made new progress, crypto market sentiment has rapidly heated up. From last night to this morning, the market saw another significant surge. OKX market data (data as of 9:30 AM) shows that BTC broke through 115,000 USDT, reaching a high of 115,590 USDT, a 24-hour increase of 3.02%. ETH approached 4,200 USDT, reaching a high of 4,194.84 USDT, a 24-hour increase of 5.88%. Sol (SOL) reclaimed the 200 USDT mark, reaching a high of 205.09 USDT, a 24-hour increase of 5.58%. Besides BTC, ETH, and SOL, the altcoin market has finally seen some decent recovery, with some tokens seeing impressive gains. For example, the consistently strong ZEC reached 368 USDT, a 30.03% 24-hour increase. Favored by… # تجزیہ# ٹوکن# ٹول# web3© 版权声明صف 上一篇 The temporary suspension of Yei Finance reflects the risks of DeFi. 下一篇 One-week token unlock: LINEA unlocked to 16.4% of circulating supply. 相关文章 The most exciting cryptocurrency product war in 2025, who will have the last laugh? 6086cf14eb90bc67ca4fc62b 22,165 24-Hour Hot Cryptocurrencies and News | Trump says some economic policies have not yet taken effect, midterm election results remain uncertain; negotiations on the US crypto market structure bill continue, possibly delayed until January (December 15). 6086cf14eb90bc67ca4fc62b 17,579 کیا یہ $400 ملین ویلیویشن کے ساتھ روبوٹ سیکٹر لیڈر اوپن مائنڈ کے TGE میں حصہ لینے کے قابل ہے؟ 6086cf14eb90bc67ca4fc62b 9,193 Can Retail Investors Also Invest in Star Robot Companies? Virtuals Titan’s First Project XMAQUINA New Token Offering Guide 6086cf14eb90bc67ca4fc62b 12,020 2 Escalating geopolitical tensions in East Asia: A structural growth cycle for stablecoins, RWA, and on-chain yields. 6086cf14eb90bc67ca4fc62b 28,231 Huobi Growth Academy | AI Agent in-depth research report: The center of the intelligent revolution, may usher in a big e 6086cf14eb90bc67ca4fc62b 39,339 3 1 تبصرے Comment closed... #BeelieverU88ARA9 مہمان اچھا پراجیکٹ 4 ماہ پہلے Bee.com دنیا کا سب سے بڑا Web3 پورٹل شراکت دار سکے کارپ بائننس CoinMarketCap سکے گیکو سکے لائیو آرمر Bee Network APP ڈاؤن لوڈ کریں اور web3 کا سفر شروع کریں۔ سفید کاغذ کردار عمومی سوالات © 2021–2026۔ جملہ حقوق محفوظ ہیں۔. رازداری کی پالیسی | سروس کی شرائط Bee Network APP ڈاؤن لوڈ کریں۔ اور ویب 3 کا سفر شروع کریں۔ دنیا کا سب سے بڑا Web3 پورٹل شراکت دار CoinCarp Binance CoinMarketCap CoinGecko Coinlive Armors سفید کاغذ کردار عمومی سوالات © 2021–2026۔ جملہ حقوق محفوظ ہیں۔. رازداری کی پالیسی | سروس کی شرائط تلاش کریں۔ تلاش کریں۔InSiteآنچینسماجیخبریں 热门推荐: ایئر ڈراپ ہنٹرز ڈیٹا تجزیہ کرپٹو مشہور شخصیات ٹریپ ڈیٹیکٹر اردو English 繁體中文 简体中文 日本語 Tiếng Việt العربية 한국어 Bahasa Indonesia हिन्दी Русский اردو智能索引记录
-
2026-02-28 21:28:08
综合导航
成功
标题:最新包饺子作文
简介:编者按:如果大家觉得内容不错,记得分享给你的小伙伴们哦!内容简介:今天,我帮了妈妈包饺子,说起包饺子,还有我的一份功劳呢
-
2026-02-27 22:23:50
综合导航
成功
标题:胃溃疡严重吗 - 云大夫
简介:胃溃疡如果合并有幽门螺杆菌的感染,建议患者根治幽门螺杆菌,就是良性的胃溃疡。一般药物治疗,就可以痊愈。如果胃镜检查之后,
-
2026-02-28 21:12:18
综合导航
成功
标题:本製品内やウェブサイトを検索する XPERIA 5 SOV41 オンラインマニュアル(取扱説明書) au
简介:auのスマートフォン「XPERIA 5(エクスぺリア ファイブ)SOV41」Android9版のオンラインマニュアル(取
-
2026-02-28 21:53:27
图片素材
成功
标题:星星的作文150字 描写星星的作文 关于星星的作文-作文网
简介:作文网精选关于星星的150字作文,包含星星的作文素材,关于星星的作文题目,以星星为话题的150字作文大全,作文网原创名师
-
2026-02-28 06:02:46
综合导航
成功
标题:Louis-Michel Le Peletier de Saint-Fargeau (1760-1793). The Reader's Biographical Encyclopaedia. 1922
简介:Louis-Michel Le Peletier de Saint-Fargeau (1760-1793). The R
-
2026-02-28 09:05:45
职场办公
成功
标题:极简渐变工作总结汇报PPT模板-果果圈模板
简介:极简渐变工作总结汇报PPT模板
-
2026-02-28 08:32:24
综合导航
成功
标题:Solutions for the pulp and paper market
简介:Discover how we help improve your pulp and paper product qua
-
2026-02-27 21:56:46
综合导航
成功
标题:Wort sb.2. World English Historical Dictionary
简介:Wort sb.2. World English Historical Dictionary
-
2026-02-28 05:56:11
综合导航
成功
标题:Bakery Stack: Cooking Games - Best Unblocked Game
简介:Bakery Stack: Cooking Games is a fun casual platform game on
-
2026-02-28 08:20:01
综合导航
成功
标题:Tailored migration strategies for your logistics projects
简介:We develop efficient migration strategies for all upstream a
-
2026-02-28 21:20:30
教育培训
成功
标题:[推荐]四年级作文5篇
简介:在日常学习、工作或生活中,大家都跟作文打过交道吧,借助作文可以提高我们的语言组织能力。那么问题来了,到底应如何写一篇优秀
-
2026-02-27 21:14:33
综合导航
成功
标题:Toronto Maple Leafs Hockey Standings
简介:The official standings for the Toronto Maple Leafs.
-
2026-03-01 14:30:45
教育培训
成功
标题:夕阳下的公园作文
简介:在生活、工作和学习中,大家都经常接触到作文吧,作文是经过人的思想考虑和语言组织,通过文字来表达一个主题意义的记叙方法。那
-
2026-03-01 06:14:47
图片素材
成功
标题:念念不忘的作文500字 描写念念不忘的作文 关于念念不忘的作文-作文网
简介:作文网精选关于念念不忘的500字作文,包含念念不忘的作文素材,关于念念不忘的作文题目,以念念不忘为话题的500字作文大全
-
2026-02-28 01:16:03
综合导航
成功
标题:MX Data Enhancement and Account Aggregation for Lending Processes
简介:MX provides lenders with real-time insights and additional i
-
2026-03-01 06:18:40
综合导航
成功
标题:山写景作文15篇
简介:在平平淡淡的日常中,大家都写过作文吧,作文是人们把记忆中所存储的有关知识、经验和思想用书面形式表达出来的记叙方式。那么问
-
2026-02-28 06:08:38
职场办公
成功
标题:固定资产移转单-果果圈模板
简介:固定资产移转单,适合公司下载作为行政模板使用,方便记录固定资产的安置情况。果果圈网站提供海量精美Excel模板下载,一键
-
2026-02-28 22:06:12
图片素材
成功
标题:所求的作文1200字 描写所求的作文 关于所求的作文-作文网
简介:作文网精选关于所求的1200字作文,包含所求的作文素材,关于所求的作文题目,以所求为话题的1200字作文大全,作文网原创
-
2026-02-28 05:54:52
综合导航
成功
标题:Specialized Health Services Business Directory - PR.com
简介:Find Specialized Health Services businesses with full compan
-
2026-02-27 21:16:21
综合导航
成功
标题:Cook'n Recipe Organizer App for iPhone, iPad, Android, Windows, Mac, Alexa, and Apple Watch
简介:Collect, organize and share all your favorite recipes and ac
-
2026-03-01 06:17:08
综合导航
成功
标题:Deathwish Hayes Maniac Skateboard Deck - 8.475" – CCS
简介:Deck Construction:Traditional Maple,Board Shape:Popsicle,Dec
-
2026-02-28 01:54:14
综合导航
成功
标题:Men's Lounge Tops American Eagle
简介:Shop Lounge Tops for Men at American Eagle to find the right
-
2026-02-28 21:39:22
教育培训
成功
标题:【精选】找秋天作文300字4篇
简介:在平平淡淡的学习、工作、生活中,大家或多或少都会接触过作文吧,作文可分为小学作文、中学作文、大学作文(论文)。那么你有了
-
2026-02-28 07:54:35
综合导航
成功
标题:Détails du programme de fidélisation Real Rewards American Eagle et Aerie
简介:S’inscrire au programme Real Rewards d’American Eagle et d’A
-
2026-02-28 21:24:03
综合导航
成功
标题:Learn English and more in Australia & Canada ILSC
简介:Learn English at ILSC Language Schools or study French or Hi
-
2026-03-01 14:09:07
教育培训
成功
标题:学校生活英语作文4篇【通用】
简介:无论在学习、工作或是生活中,大家都接触过作文吧,借助作文人们可以反映客观事物、表达思想感情、传递知识信息。作文的注意事项
-
2026-02-28 21:33:52
教育培训
成功
标题:新王牌培优_上海春季补习班_初中高中课外辅导补课培训机构
简介:新王牌创立于2005年,拥有一支强大的名师天团,定位培优,学生都来自重点中学,采用分层授课,小班教学,支持按月收费,成就
-
2026-03-01 06:53:26
综合导航
成功
标题:Комплекс оборудования для выполнения операций холодной штамповки (пробивание, вырубка, гибка). (165983521) - RIA
简介:Продаю на RIA - Комплекс оборудования для выполнения операци
-
2026-03-01 06:24:47
教育培训
成功
标题:关于二年级家乡作文汇总10篇
简介:在平凡的学习、工作、生活中,大家对作文都不陌生吧,借助作文人们可以实现文化交流的目的。那要怎么写好作文呢?以下是小编帮大
-
2026-02-28 06:12:41
新闻资讯
成功
标题:美国AI巨头的烦心事:巨头要合同 员工要“不作恶”, 站长资讯平台
简介:来源: 网易智能 我们对于AI威胁的担忧从未停歇,但这并不妨碍威胁不断加剧。 事实上,不论专家们如何歇斯底里地呼吁,很多