Monetize API Endpoints with x402 Crypto Payment Protocol - n8n Workflow

Secure and monetize your API services instantly using the x402 payment protocol within a custom n8n workflow. This n8n template utilizes the 1Shot API node for robust crypto payment verification and processing.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Developers and Agencies: Those offering premium API access or digital services.

  • Automation Engineers: Users looking to build pay-per-use n8n workflow segments.

  • Web3 Integrators: Individuals needing a non-custodial method to accept payments for digital goods.

  • n8n Power Users: Anyone seeking advanced examples of using the n8n webhook trigger for complex validation.

Overview

Monetizing automated services often requires complex subscription models or traditional payment processors. This advanced n8n workflow solves this by implementing the x402 protocol, which enables pay-per-request monetization using stablecoins (ERC-20 tokens) on any EVM chain via the 1Shot API.

Instead of building custom payment logic, this n8n template provides a plug-and-play solution. The entire process—from receiving the request via an n8n trigger, decoding the payment header, verifying the signature, simulating the transaction, and finally submitting the payment—is handled automatically. If any validation fails (e.g., missing header, invalid signature, or payment failure), the workflow responds instantly with a 402 Payment Required status, ensuring only paid requests proceed to the premium service component of the n8n workflow.

How it Works

This robust n8n workflow is initiated by an incoming HTTP request directed to the Webhook n8n trigger.


  1. Initial Validation: The Check for presence of X-HEADER n8n node verifies if the critical X-Payment header is present in the request. If missing, a 402 error response is immediately returned via the Response: Missing or Invalid Payment Headers n8n node.

  2. Decoding: If the header exists, the Decode & Validate X-Payment n8n node (a Code node) decodes the Base64-encoded payment payload and transforms it into a structured JSON object for validation.

  3. Payload Integrity Check: The Ensure Well Formatted Payment Payload n8n node uses an If condition to confirm the presence of required fields, specifically the payment signature. If the payload is malformed, it defaults to the 402 error response.

  4. Payment Simulation (Pre-Check): The n8n workflow uses the Simulate Payment 1Shot n8n node. This crucial step verifies the validity of the x402 authorization and signature using the blockchain data without immediately submitting the transaction.

  5. Simulation Check: The On Successful Payment Simulation n8n node confirms the simulation was successful. If the simulation fails (meaning the signature is invalid or the payment terms are incorrect), the request is rejected with a 402 response.

  6. Payment Submission: If simulation is successful, the 1Shot API Submit & Wait n8n node synchronously executes the transaction, confirming the payment on-chain.

  7. Service Delivery: Upon successful confirmation, the n8n workflow proceeds to the Response: 200 - Payment Successful node, which should be replaced by the premium service logic that the user is paying for.

Installation Guide

To deploy and utilize this powerful n8n workflow, follow these steps:


  1. Import: Copy the entire provided JSON and paste it into your n8n instance via the 'New' menu -> 'Import from JSON'. This creates the full n8n template.

  2. Credentials: You need to configure credentials for the specialized 1Shot n8n node. Click on the 'Simulate Payment' n8n node and set up or select your existing 1Shot API account credentials.

  3. Activation: Ensure the n8n workflow is active. Once active, the Webhook n8n trigger will provide a unique URL. This URL is your new monetized API endpoint.

  4. Customization: Replace the final Response: 200 - Payment Successful n8n node with your specific business logic (e.g., generating content, sending data, or accessing a database).

  5. Testing: Test the n8n trigger using a valid x402 payment header, following the example provided in the Sticky Note within the workflow.

Node Details

Webhook (n8n Trigger)
Function: Serves as the public-facing API endpoint, initiating the n8n workflow upon receiving an HTTP request.
Key Configuration: Response mode is set to responseNode to allow later nodes to control the HTTP response code (402 or 200).
Check for presence of X-HEADER (If n8n node)
Function: Checks if the required x-payment header exists in the incoming request data.
Key Configuration: Uses the expression ={{ $json.headers['x-payment'] }} with the operation exists.
Decode & Validate X-Payment (Code n8n node)
Function: Decodes the Base64 value of the x-payment header and parses the result into a new JSON property, decodedXPayment, which is crucial for subsequent n8n nodes.
Simulate Payment (1Shot n8n node)
Function: Interacts with the 1Shot API to cryptographically verify the payment signature and check if the funds are available and authorized, without executing the transaction.
Key Configuration: Configured with the simulate operation, passing extracted x402 parameters like from, to, value, and signature.
1Shot API Submit & Wait (1ShotSynch n8n node)
Function: Submits the validated x402 payment transaction to the blockchain via the 1Shot API and waits for on-chain confirmation before proceeding to the service delivery part of the n8n workflow.
Response: Missing or Invalid Payment Headers (Respond to Webhook n8n node)
* Function: Returns a 402 'Payment Required' response code, informing the caller that the request lacked the necessary payment credentials or was malformed.

Related n8n Workflows

Free

Nodes: 7 Nodes
Updated: December 26 2025
View all
Created by

1Shot API lets you bring onchain actions into your n8n workflows.

Featured*