Skip to Content
API ReferenceGet WETH Info

GET /api/v1/mev/wrap/info

Get WETH contract information and user balances for wrap/unwrap operations.

This endpoint provides WETH contract details and current ETH/WETH balances for a user, helping determine available amounts for wrap/unwrap operations.


Endpoint Details

GET https://api.unikron.ch/api/v1/mev/wrap/info

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


Request Parameters

Query Parameters

ParameterTypeRequiredDescription
userAddressstringYesUser’s wallet address (EIP-55 checksummed)

Headers

HeaderRequiredDescriptionExample
X-API-KeyYesYour UNIKRON API keyuk_live_abc123...

Code Examples

JavaScript / TypeScript

const API_KEY = process.env.UNIKRON_API_KEY; const API_URL = "https://api.unikron.ch"; async function getWrapInfo(userAddress: string) { const url = `${API_URL}/api/v1/mev/wrap/info?userAddress=${userAddress}`; const response = await fetch(url, { method: "GET", headers: { "X-API-Key": API_KEY, }, }); 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; } // Example usage const userAddress = "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb"; try { const info = await getWrapInfo(userAddress); console.log("=== WETH Information ==="); console.log(`Contract: ${info.weth.address}`); console.log(`Symbol: ${info.weth.symbol}`); console.log(`Decimals: ${info.weth.decimals}`); console.log("\n=== User Balances ==="); console.log(`ETH: ${info.balances.eth.ether} ETH`); console.log(` (${info.balances.eth.wei} wei)`); console.log(`WETH: ${info.balances.weth.ether} WETH`); console.log(` (${info.balances.weth.wei} wei)`); console.log("\n=== Available Operations ==="); console.log(`Max Wrap: ${info.operations.wrap.maxAmount} ETH`); console.log(`Max Unwrap: ${info.operations.unwrap.maxAmount} WETH`); } catch (error) { console.error("Failed to get wrap info:", error); }

Response Format

Success Response (200 OK)

{ "ok": true, "data": { "weth": { "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "name": "Wrapped Ether", "symbol": "WETH", "decimals": 18, "chainId": 1 }, "balances": { "eth": { "wei": "5000000000000000000", "ether": "5.0" }, "weth": { "wei": "2000000000000000000", "ether": "2.0" } }, "operations": { "wrap": { "description": "Convert ETH to WETH (required for most DEX swaps)", "maxAmount": "5.0" }, "unwrap": { "description": "Convert WETH back to ETH", "maxAmount": "2.0" } } } }

Response Fields Reference

WETH Object

FieldTypeDescription
addressstringWETH contract address (Ethereum mainnet)
namestringToken name (“Wrapped Ether”)
symbolstringToken symbol (“WETH”)
decimalsnumberToken decimals (18)
chainIdnumberChain ID (1 = Ethereum mainnet)

Balances Object

FieldTypeDescription
eth.weistringETH balance in wei (smallest unit)
eth.etherstringETH balance in ether (formatted)
weth.weistringWETH balance in wei
weth.etherstringWETH balance in ether (formatted)

Operations Object

FieldTypeDescription
wrap.descriptionstringWrap operation description
wrap.maxAmountstringMax ETH that can be wrapped (user’s ETH balance)
unwrap.descriptionstringUnwrap operation description
unwrap.maxAmountstringMax WETH that can be unwrapped (user’s WETH balance)

Use Cases

Check Before Wrap/Unwrap

Pre-Operation Validation: Call this endpoint before requesting a wrap/unwrap quote to:

  • Verify user has sufficient balance
  • Display available amounts in your UI
  • Prevent failed transactions due to insufficient funds
async function canWrap(userAddress: string, amount: string): Promise<boolean> { const info = await getWrapInfo(userAddress); const maxWrap = parseFloat(info.operations.wrap.maxAmount); const requestedAmount = parseFloat(amount); if (requestedAmount > maxWrap) { console.log(` Insufficient ETH balance`); console.log(` Requested: ${requestedAmount} ETH`); console.log(` Available: ${maxWrap} ETH`); return false; } return true; } // Usage if (await canWrap(userAddress, "5.0")) { // Proceed with wrap quote const quote = await getWrapQuote("wrap", "5.0", userAddress); }

Display Balance UI

async function renderBalanceWidget(userAddress: string) { const info = await getWrapInfo(userAddress); return { eth: { display: `${info.balances.eth.ether} ETH`, canWrap: parseFloat(info.operations.wrap.maxAmount) > 0, }, weth: { display: `${info.balances.weth.ether} WETH`, canUnwrap: parseFloat(info.operations.unwrap.maxAmount) > 0, }, }; }

Suggest Optimal Amount

async function suggestWrapAmount(userAddress: string): Promise<string> { const info = await getWrapInfo(userAddress); const maxWrap = parseFloat(info.operations.wrap.maxAmount); // Leave 0.1 ETH for gas fees const suggestedAmount = Math.max(0, maxWrap - 0.1); console.log(`💡 Suggested wrap amount: ${suggestedAmount.toFixed(4)} ETH`); console.log(` (Reserves 0.1 ETH for gas fees)`); return suggestedAmount.toFixed(4); }

Error Responses

400 Bad Request - Invalid Address

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

400 Bad Request - Missing Parameter

{ "ok": false, "error": "MISSING_PARAMETER", "message": "userAddress is required", "details": { "field": "userAddress", "required": true } }

Common Error Codes

HTTPError CodeReasonSolution
400INVALID_ADDRESSInvalid wallet addressUse checksummed address
400MISSING_PARAMETERMissing userAddressInclude userAddress param
401UNAUTHORIZEDInvalid/missing API keyCheck X-API-Key header
429RATE_LIMIT_EXCEEDEDToo many requestsWait and retry with backoff
503SERVICE_UNAVAILABLERPC provider issueRetry after a few seconds

Integration Example

Complete Wrap Flow with Validation

async function smartWrapFlow( userAddress: string, requestedAmount: string, signer: ethers.Signer ) { try { // 1. Get user info console.log("⏳ Fetching balance info..."); const info = await getWrapInfo(userAddress); console.log(` Current balances:`); console.log(` ETH: ${info.balances.eth.ether}`); console.log(` WETH: ${info.balances.weth.ether}`); // 2. Validate amount const maxWrap = parseFloat(info.operations.wrap.maxAmount); const amount = parseFloat(requestedAmount); if (amount > maxWrap) { throw new Error( `Insufficient balance. Max: ${maxWrap} ETH, Requested: ${amount} ETH` ); } if (amount <= 0) { throw new Error("Amount must be greater than 0"); } console.log(` Amount validated: ${amount} ETH`); // 3. Get quote console.log("⏳ Getting wrap quote..."); const quote = await getWrapQuote("wrap", requestedAmount, userAddress); console.log(` Quote received: ${quote.quoteId}`); // 4. Submit order console.log("⏳ Submitting wrap order..."); const order = await submitWrapOrder(quote, signer); console.log(` Order submitted: ${order.txHash}`); // 5. Monitor console.log("⏳ Waiting for confirmation..."); await waitForConfirmation(order.txHash, signer.provider); console.log(" Wrap completed successfully!"); // 6. Show updated balance const updatedInfo = await getWrapInfo(userAddress); console.log(`📊 Updated balances:`); console.log(` ETH: ${updatedInfo.balances.eth.ether}`); console.log(` WETH: ${updatedInfo.balances.weth.ether}`); return order; } catch (error) { console.error(" Wrap flow failed:", error); throw error; } }

Best Practices

Recommended Usage:

  1. Pre-Operation Check: Always call this endpoint before requesting wrap/unwrap quotes
  2. Balance Display: Use formatted ether values for user-facing displays
  3. Wei for Calculations: Use wei values for precise calculations
  4. Gas Reserves: When wrapping, reserve ~0.1 ETH for future gas fees
  5. Real-Time Updates: Refresh balances after each operation

Reserve Gas Fees

function calculateSafeWrapAmount(ethBalance: string): string { const balance = parseFloat(ethBalance); const gasReserve = 0.1; // Reserve 0.1 ETH for gas const safeAmount = Math.max(0, balance - gasReserve); return safeAmount.toFixed(6); }

Format for Display

function formatBalance(wei: string, decimals: number = 18): string { const ether = parseFloat(wei) / Math.pow(10, decimals); return ether.toFixed(4); // Show 4 decimal places }

WETH Contract Details

WETH (Wrapped Ether) Contract:

  • Address: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
  • Network: Ethereum Mainnet (Chain ID: 1)
  • Standard: ERC-20
  • Decimals: 18
  • 1:1 Conversion: 1 WETH = 1 ETH (always)

Related Operations:


Need Help?

Last updated on