> For the complete documentation index, see [llms.txt](https://docs.ethgas.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ethgas.com/overview/x402-agentic-preconfirmations.md).

# x402 Agentic Preconfirmations

ETHGas's x402 for Blockspace endpoint lets an agent purchase a preconfirmation for a single Ethereum mainnet transaction. In plain language, you submit a signed transaction, pay the quoted WETH fee with signature via standard HTTP, and ETHGas passes it to the blockspace platform and partnered builders for inclusion.

This service works on Ethereum mainnet only. It is intended for users who already have an Ethereum wallet.

### At A Glance

* **Endpoint:** `https://x402.ethgas.com/v1/preconfirmations`
* **Method:** POST
* **Content-Type:** `application/json`
* **Authentication:** none — x402 is payment-native. Agents pay per request; no API keys, no accounts
* **Network:** Ethereum mainnet only

### Prerequisites

Before your first request:&#x20;

* An Ethereum mainnet wallet&#x20;
* Enough WETH to pay the preconfirmation fee (see [Pricing](#pricing))
* Enough ETH to pay the base and priority fee for your transaction
* A one-off transaction to grant the standard Permit2 contract the payment permission used by the facilitator to move the WETH fee when you approve the purchase

### Setup

Grant the standard Permit2 contract permission to move WETH on your behalf. This is a one-off transaction — after this, no further gas payments to ETHGas are required.

* **Contract:** `0x000000000022d473030f116ddee9f6b43ac78ba3`
* **Recommended approval amount:** 0.002 ETH should be enough for \~100 swaps
* **Via Etherscan:** [approve WETH for Permit2](https://etherscan.io/address/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2#writeContract)&#x20;

### End-to-End Flow

#### Step 1: Sign the transaction you want executed

Prepare and sign your Ethereum mainnet transaction as you would for any RPC submission. Requirements:

* Valid Ethereum mainnet transaction
* Gas limit ≤ 300,000 units (limit in place during initial rollout to prevent any single transaction occupying the majority of blockspace)
* Blob transactions (EIP-4844 type 3) are **not** supported

#### Step 2: Request a preconfirmation

POST the signed transaction to the endpoint:

```bash
curl -X POST https://x402.ethgas.com/v1/preconfirmations \
  -H "Content-Type: application/json" \
  -d '{"rawSignedTransaction": "0x02f8..."}'
```

**If a suitable upcoming block slot is available**, ETHGas responds with `HTTP/1.1 402 Payment Required`:

```http
HTTP/1.1 402 Payment Required
PAYMENT-REQUIRED: <base64-encoded challenge>
```

Decoded challenge structure:

```json
{
  "scheme": "exact",
  "network": "eip155:1", // Ethereum mainnet
  "amount": "2100000000000", // in wei
  "asset": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH address
  "payTo": "0x...",
  "maxTimeoutSeconds": 180,
  "extra": {
    "assetTransferMethod": "permit2"
  }
}
```

**If no upcoming block is available**, no payment request is issued. Wait briefly and request a new quote — do not retry immediately in a tight loop.

#### Step 3: Verify the payment challenge

Your agent should independently verify:

* `network` matches the expected chain (`ethereum`)
* `asset` is `WETH` (not ETH — payment is in wrapped ETH via Permit2)
* `amount` is within your budget
* [`assetTransferMethod`](#user-content-fn-1)[^1] is `permit2`

Reject any challenge that doesn't match your policy.

#### Step 4: Sign the payment challenge

Sign the typed payload using EIP-712 structured data signing. This authorizes the facilitator to pull the WETH fee via Permit2. This signature is gasless — no ETH is spent on the payment leg.

#### Step 5: Submit the signed payment

Retry the request with the signature in the `PAYMENT-SIGNATURE` header:

```bash
curl -X POST https://x402.ethgas.com/v1/preconfirmations \
  -H "Content-Type: application/json" \
  -H "PAYMENT-SIGNATURE: 0x1b8f..." \
  -d '{"rawSignedTransaction": "0x02f8..."}'
```

Payment requests expire in 180 seconds — sign and submit promptly. If a challenge expires, request a new quote rather than reusing the old one.

#### Step 6: Settlement and inclusion

ETHGas verifies the signature, settles the WETH payment via Permit2, and forwards the original signed transaction to the blockspace platform and partnered builders. Response:

```http
HTTP/1.1 200 OK
Content-Type: application/json

{
  "success": true,
  "status": "payment_settling",
  "pendingTransactionHash": "0x...",
  "pendingPaymentHash": "0x..."
}
```

* `pendingTransactionHash` identifies the pending preconf transaction, subject to the successful payment
* `pendingPaymentHash` identifies the pending x402 payment transaction

#### Step 7 — Confirm on-chain inclusion

* Use Etherscan to query the above pending transaction hash or
* Poll `pendingTransactionHash` via standard Ethereum RPC to confirm inclusion:

```bash
curl -X POST https://<your-rpc-endpoint> \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["<pendingTransactionHash or pendingPaymentHash>"],"id":1}'
```

#### Reference

You could follow the instructions in our [Github Repo](https://github.com/ethgas-developer/ethgas-x402-client)

### Pricing

The preconfirmation fee is based on your transaction's **gas limit**, not the gas it eventually consumes:

```
preconfirmation fee = price per gas unit × transaction gas limit
```

**Example:** at a price of `0.1 gwei` per gas unit with a gas limit of `21,000`, the fee is `2,100 gwei` = `0.0000021 WETH`.

The preconfirmation fee is separate from and additional to:

* **The Ethereum network fee both base and priority fee** for your transaction, paid in ETH as normal

### Common failures

<table><thead><tr><th width="306.33984375">Condition</th><th>Behavior</th></tr></thead><tbody><tr><td>No upcoming block available</td><td>No payment request issued. Retry after a short wait</td></tr><tr><td>Payment signature invalid or expired</td><td>No preconfirmation issued. Request a new quote</td></tr><tr><td>Insufficient WETH balance or missing Permit2 approval</td><td>No preconfirmation issued</td></tr><tr><td>Duplicate submission of the same signed transaction</td><td>May be rejected while the first attempt is being processed. Do not submit the same signed tx through multiple routes concurrently</td></tr><tr><td>Gas limit above 300,000 units</td><td>Rejected at intake</td></tr><tr><td>Blob transaction (EIP-4844 type 3)</td><td>Rejected at intake</td></tr></tbody></table>

### Refund

* The fee is settled before the downstream transaction service accepts the transaction. In the uncommon case that the downstream service is unavailable or rejects the transaction after settlement. ETHGas will issue a refund to the original payer.

[^1]:


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ethgas.com/overview/x402-agentic-preconfirmations.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
