Skip to Content
API ReferenceGet Wrap Quote

POST /api/v1/mev/wrap/quote

Get quote for wrapping ETH to WETH or unwrapping WETH to ETH with MEV protection.

WETH (Wrapped Ether) is an ERC-20 compatible version of ETH required for DEX trading. This endpoint provides quotes for wrapping/unwrapping with MEV-protected execution.


Endpoint Details

POST https://api.unikron.ch/api/v1/mev/wrap/quote

Authentication Required: Yes (API Key via X-API-Key header)


Request Parameters

Request Body (JSON)

ParameterTypeRequiredDescription
operationstringYes"wrap" or "unwrap"
amountstringYesAmount in ETH (e.g., “1.0”)
userAddressstringYesUser’s wallet address (EIP-55 checksummed)
chainIdnumberNoChain ID (default: 1, only mainnet supported)

Headers

HeaderRequiredDescriptionExample
X-API-KeyYesYour UNIKRON API keyuk_live_abc123...
Content-TypeYesMust be application/jsonapplication/json

Important Notes

Operation Types:

  • wrap: Convert native ETH → WETH (ERC-20 token)
  • unwrap: Convert WETH → native ETH

Amount Format: Use decimal ETH format (e.g., “1.0”, “0.5”, “10.25”) not wei. The API will convert to wei automatically.


Code Examples

JavaScript / TypeScript

import { ethers } from "ethers"; const API_KEY = process.env.UNIKRON_API_KEY; const API_URL = "https://api.unikron.ch"; async function getWrapQuote( operation: "wrap" | "unwrap", amountEth: string, userAddress: string ) { const response = await fetch(`${API_URL}/api/v1/mev/wrap/quote`, { method: "POST", headers: { "X-API-Key": API_KEY, "Content-Type": "application/json", }, body: JSON.stringify({ operation, amount: amountEth, userAddress, chainId: 1, }), }); if (!response.ok) { const error = await response.text(); throw new Error(`HTTP ${response.status}: ${error}`); } const { ok, data } = await response.json(); if (!ok) { throw new Error(`API Error: ${data.error}`); } return data.quote; } // Example usage - Wrap 1 ETH const wrapQuote = await getWrapQuote( "wrap", "1.0", "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb" ); console.log("=== Wrap Quote ==="); console.log(`Quote ID: ${wrapQuote.quoteId}`); console.log(`Operation: ${wrapQuote.operation}`); console.log(`Amount: ${wrapQuote.amount} ETH`); console.log(`Amount (wei): ${wrapQuote.amountWei}`); console.log(`Output Token: ${wrapQuote.outputToken}`); console.log(`Estimated Gas: ${wrapQuote.estimatedGas}`); console.log(`Valid Until: ${wrapQuote.validUntil}`); console.log(`Provider: ${wrapQuote.mevProtection.provider}`); // Example usage - Unwrap 0.5 WETH const unwrapQuote = await getWrapQuote( "unwrap", "0.5", "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb" ); console.log("\n=== Unwrap Quote ==="); console.log(`Quote ID: ${unwrapQuote.quoteId}`); console.log(`Operation: ${unwrapQuote.operation}`); console.log(`Amount: ${unwrapQuote.amount} WETH`);

Response Format

Success Response (200 OK)

{ "ok": true, "data": { "quote": { "quoteId": "weth_wrap_1705320000000_a1b2c3", "operation": "wrap", "amount": "1.0", "amountWei": "1000000000000000000", "inputToken": "ETH", "outputToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "mevProtection": { "provider": "MEV Blocker", "transactionParams": { "to": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "data": "0xd0e30db0", "value": "1000000000000000000", "chainId": 1, "gasLimit": "46000", "maxFeePerGas": "2000000000", "maxPriorityFeePerGas": "0", "nonce": null, "type": 2 }, "providerMetadata": { "provider": "mev_blocker", "tier": 2, "mevBlockerMetadata": { "endpoint": "https://rpc.mevblocker.io/fast?shareAll=1&referrer=UNIKRON&refundRecipient=0x...", "endpointType": "fast", "shareMode": "shareAll", "revertProtection": false, "useBoost": false } } }, "deadline": 1705320300, "estimatedGas": "46000", "createdAt": "2024-01-15T10:30:00.000Z", "validUntil": "2024-01-15T10:35:00.000Z" } } }

Response Fields Reference

Quote Object

FieldTypeDescription
quoteIdstringQuote identifier for order submission
operationstring”wrap” or “unwrap”
amountstringAmount in ETH
amountWeistringAmount in wei (smallest unit)
inputTokenstringInput token (ETH or WETH address)
outputTokenstringOutput token (WETH address or ETH)
mevProtection.providerstringMEV protection provider name
mevProtection.transactionParamsobjectTransaction params to sign (client sets nonce)
mevProtection.providerMetadataobjectProvider metadata (required for order submission)
deadlinenumberQuote expiry (Unix timestamp)
estimatedGasstringEstimated gas units
createdAtstringQuote creation time (ISO 8601)
validUntilstringQuote expiry time (ISO 8601)

Transaction Parameters Object

FieldTypeDescription
tostringWETH contract address
datastringEncoded function call data
valuestringETH value to send (for wrap)
chainIdnumberChain ID (1 = Ethereum mainnet)
gasLimitstringMaximum gas units
maxFeePerGasstringMaximum fee per gas in wei (EIP-1559)
maxPriorityFeePerGasstringPriority fee per gas in wei (always “0” for MEV protection)
noncenumberTransaction nonce (null = client sets)
typenumberTransaction type (2 = EIP-1559)

Provider Metadata Object

FieldTypeDescription
providerstringProvider type (always “mev_blocker”)
tiernumberMEV Blocker tier (2 or 4)
mevBlockerMetadataobjectMEV Blocker-specific configuration

MEV Blocker Metadata Object

FieldTypeDescription
endpointstringMEV Blocker RPC endpoint URL with query parameters
endpointTypestringEndpoint type (fast, noreverts, fullprivacy)
shareModestringProfit sharing mode (shareAll, shareSafe, none)
revertProtectionbooleanWhether revert protection is enabled
useBoostbooleanWhether transaction boost is enabled

Error Responses

400 Bad Request - Invalid Operation

{ "ok": false, "error": "INVALID_OPERATION", "message": "operation must be 'wrap' or 'unwrap'", "details": { "provided": "warp", "allowed": ["wrap", "unwrap"] } }

400 Bad Request - Invalid Amount

{ "ok": false, "error": "INVALID_AMOUNT", "message": "amount must be a positive number", "details": { "provided": "-1.0" } }

400 Bad Request - Invalid Address

{ "ok": false, "error": "INVALID_ADDRESS", "message": "userAddress must be a valid checksummed Ethereum address", "details": { "provided": "0xinvalidaddress" } }

Common Error Codes

HTTPError CodeReasonSolution
400INVALID_OPERATIONInvalid operation typeUse “wrap” or “unwrap”
400INVALID_AMOUNTInvalid amount formatUse positive decimal number
400INVALID_ADDRESSInvalid wallet addressUse checksummed address
400MISSING_PARAMETERRequired field missingInclude all required fields
401UNAUTHORIZEDInvalid/missing API keyCheck X-API-Key header
429RATE_LIMIT_EXCEEDEDToo many requestsWait and retry with backoff
503SERVICE_UNAVAILABLETemporary service issueRetry after a few seconds

WETH Contract Information

WETH Contract Details:

  • Address: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
  • Network: Ethereum Mainnet
  • Standard: ERC-20
  • Decimals: 18

Quote Expiration

Expiration Policy:

  • Quotes expire after 5 minutes (validUntil timestamp)
  • Always check validUntil before submitting order
  • If expired, request a new quote
  • Gas prices update frequently, fresh quotes recommended

Transaction Signing

Zero Priority Fees for MEV Protection

All WETH wrap/unwrap transactions use maxPriorityFeePerGas: "0". MEV Blocker’s private mempool handles transaction ordering, so priority fees are unnecessary and would just waste gas.

Save Provider Metadata

The providerMetadata object is required when submitting the order. Save it from the quote response and pass it to the order submission endpoint.

Next Steps

After Getting Quote:

  1. Set Nonce: Add current nonce to transactionParams
  2. Sign Transaction: Sign with user’s private key
  3. Submit Order: Use POST /api/v1/mev/wrap/order with providerMetadata
  4. Monitor Status: Track transaction confirmation

Related Operations:


Need Help?

Last updated on