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/quoteAuthentication Required: Yes (API Key via X-API-Key header)
Request Parameters
Request Body (JSON)
| Parameter | Type | Required | Description |
|---|---|---|---|
operation | string | Yes | "wrap" or "unwrap" |
amount | string | Yes | Amount in ETH (e.g., “1.0”) |
userAddress | string | Yes | User’s wallet address (EIP-55 checksummed) |
chainId | number | No | Chain ID (default: 1, only mainnet supported) |
Headers
| Header | Required | Description | Example |
|---|---|---|---|
X-API-Key | Yes | Your UNIKRON API key | uk_live_abc123... |
Content-Type | Yes | Must be application/json | application/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
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
| Field | Type | Description |
|---|---|---|
quoteId | string | Quote identifier for order submission |
operation | string | ”wrap” or “unwrap” |
amount | string | Amount in ETH |
amountWei | string | Amount in wei (smallest unit) |
inputToken | string | Input token (ETH or WETH address) |
outputToken | string | Output token (WETH address or ETH) |
mevProtection.provider | string | MEV protection provider name |
mevProtection.transactionParams | object | Transaction params to sign (client sets nonce) |
mevProtection.providerMetadata | object | Provider metadata (required for order submission) |
deadline | number | Quote expiry (Unix timestamp) |
estimatedGas | string | Estimated gas units |
createdAt | string | Quote creation time (ISO 8601) |
validUntil | string | Quote expiry time (ISO 8601) |
Transaction Parameters Object
| Field | Type | Description |
|---|---|---|
to | string | WETH contract address |
data | string | Encoded function call data |
value | string | ETH value to send (for wrap) |
chainId | number | Chain ID (1 = Ethereum mainnet) |
gasLimit | string | Maximum gas units |
maxFeePerGas | string | Maximum fee per gas in wei (EIP-1559) |
maxPriorityFeePerGas | string | Priority fee per gas in wei (always “0” for MEV protection) |
nonce | number | Transaction nonce (null = client sets) |
type | number | Transaction type (2 = EIP-1559) |
Provider Metadata Object
| Field | Type | Description |
|---|---|---|
provider | string | Provider type (always “mev_blocker”) |
tier | number | MEV Blocker tier (2 or 4) |
mevBlockerMetadata | object | MEV Blocker-specific configuration |
MEV Blocker Metadata Object
| Field | Type | Description |
|---|---|---|
endpoint | string | MEV Blocker RPC endpoint URL with query parameters |
endpointType | string | Endpoint type (fast, noreverts, fullprivacy) |
shareMode | string | Profit sharing mode (shareAll, shareSafe, none) |
revertProtection | boolean | Whether revert protection is enabled |
useBoost | boolean | Whether 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
| HTTP | Error Code | Reason | Solution |
|---|---|---|---|
| 400 | INVALID_OPERATION | Invalid operation type | Use “wrap” or “unwrap” |
| 400 | INVALID_AMOUNT | Invalid amount format | Use positive decimal number |
| 400 | INVALID_ADDRESS | Invalid wallet address | Use checksummed address |
| 400 | MISSING_PARAMETER | Required field missing | Include all required fields |
| 401 | UNAUTHORIZED | Invalid/missing API key | Check X-API-Key header |
| 429 | RATE_LIMIT_EXCEEDED | Too many requests | Wait and retry with backoff |
| 503 | SERVICE_UNAVAILABLE | Temporary service issue | Retry 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 (
validUntiltimestamp) - Always check
validUntilbefore 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:
- Set Nonce: Add current nonce to
transactionParams - Sign Transaction: Sign with user’s private key
- Submit Order: Use POST /api/v1/mev/wrap/order with
providerMetadata - Monitor Status: Track transaction confirmation
Related Endpoints
Related Operations:
- POST /api/v1/mev/wrap/order - Submit wrap/unwrap order
- GET /api/v1/quote - Get swap quote
- Important Notes - Why WETH is required