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/infoAuthentication Required: Yes (API Key via X-API-Key header)
Request Parameters
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userAddress | string | Yes | User’s wallet address (EIP-55 checksummed) |
Headers
| Header | Required | Description | Example |
|---|---|---|---|
X-API-Key | Yes | Your UNIKRON API key | uk_live_abc123... |
Code Examples
JavaScript
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
| Field | Type | Description |
|---|---|---|
address | string | WETH contract address (Ethereum mainnet) |
name | string | Token name (“Wrapped Ether”) |
symbol | string | Token symbol (“WETH”) |
decimals | number | Token decimals (18) |
chainId | number | Chain ID (1 = Ethereum mainnet) |
Balances Object
| Field | Type | Description |
|---|---|---|
eth.wei | string | ETH balance in wei (smallest unit) |
eth.ether | string | ETH balance in ether (formatted) |
weth.wei | string | WETH balance in wei |
weth.ether | string | WETH balance in ether (formatted) |
Operations Object
| Field | Type | Description |
|---|---|---|
wrap.description | string | Wrap operation description |
wrap.maxAmount | string | Max ETH that can be wrapped (user’s ETH balance) |
unwrap.description | string | Unwrap operation description |
unwrap.maxAmount | string | Max 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
| HTTP | Error Code | Reason | Solution |
|---|---|---|---|
| 400 | INVALID_ADDRESS | Invalid wallet address | Use checksummed address |
| 400 | MISSING_PARAMETER | Missing userAddress | Include userAddress param |
| 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 | RPC provider issue | Retry 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:
- Pre-Operation Check: Always call this endpoint before requesting wrap/unwrap quotes
- Balance Display: Use formatted
ethervalues for user-facing displays - Wei for Calculations: Use
weivalues for precise calculations - Gas Reserves: When wrapping, reserve ~0.1 ETH for future gas fees
- 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 Endpoints
Related Operations:
- POST /api/v1/mev/wrap/quote - Get wrap/unwrap quote
- POST /api/v1/mev/wrap/order - Submit wrap/unwrap order
- GET /api/v1/quote - Get swap quote (requires WETH)
Need Help?
Last updated on