Files
proxmox/docs/archive/fixes/METAMASK_USD_PRICE_FIX.md
defiQUG cb47cce074 Complete markdown files cleanup and organization
- Organized 252 files across project
- Root directory: 187 → 2 files (98.9% reduction)
- Moved configuration guides to docs/04-configuration/
- Moved troubleshooting guides to docs/09-troubleshooting/
- Moved quick start guides to docs/01-getting-started/
- Moved reports to reports/ directory
- Archived temporary files
- Generated comprehensive reports and documentation
- Created maintenance scripts and guides

All files organized according to established standards.
2026-01-06 01:46:25 -08:00

6.0 KiB
Executable File

Fix MetaMask USD Value Display for Chain 138

Date: $(date)
ChainID: 138
Issue: MetaMask not showing USD values for ETH/tokens


🔍 Problem Analysis

Root Cause: MetaMask uses CoinGecko API to display USD prices for tokens. For custom chains (like Chain 138), MetaMask does NOT automatically query oracle contracts for USD prices.

Current Status:

  • Oracle contract deployed: 0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6
  • Oracle has no price data (returns all zeros)
  • Oracle Publisher service not running (VMID 3500)
  • ⚠️ MetaMask won't automatically use oracle for USD prices

⚠️ Important Limitation

MetaMask does NOT automatically query oracle contracts for USD prices on custom chains.

MetaMask relies on:

  1. CoinGecko API - Primary source for USD prices
  2. Token lists - Can include price metadata (but MetaMask may not use it)
  3. Oracle contracts - NOT automatically queried by MetaMask

This means: Even if your oracle contract has correct price data, MetaMask may not display USD values unless:

  • The token is listed on CoinGecko
  • OR you use a custom MetaMask extension/plugin (requires development)

Solutions

Option 1: Update Oracle Contract (For dApp Use)

While MetaMask won't use it automatically, dApps can query the oracle to display USD values.

Step 1: Check Oracle Publisher Service

# Check if VMID 3500 exists
ssh root@192.168.11.10 "pct list | grep 3500"

# Check service status
ssh root@192.168.11.10 "pct exec 3500 -- systemctl status oracle-publisher.service"

Step 2: Start/Configure Oracle Publisher

If the service doesn't exist, you'll need to:

  1. Create the oracle publisher service
  2. Configure it to fetch prices from CoinGecko/Binance APIs
  3. Update the oracle contract every 60 seconds

Step 3: Manually Update Oracle (Temporary Fix)

# Get current ETH price from CoinGecko
ETH_PRICE=$(curl -s 'https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd' | jq -r '.ethereum.usd')

# Convert to 8 decimals
PRICE_DECIMALS=$(echo "$ETH_PRICE * 100000000" | bc | cut -d. -f1)

# Update oracle contract (requires deployer private key)
cast send 0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6 \
  "updateAnswer(int256)" \
  "$PRICE_DECIMALS" \
  --rpc-url https://rpc-http-pub.d-bis.org \
  --private-key $DEPLOYER_PRIVATE_KEY

Option 2: Use dApp to Display USD Values

Since MetaMask won't show USD values, your dApp can query the oracle and display them:

// In your dApp
const { ethers } = require('ethers');

const provider = new ethers.providers.Web3Provider(window.ethereum);
const oracleAddress = '0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6';
const oracleABI = [
  "function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80)",
  "function decimals() external view returns (uint8)"
];

const oracle = new ethers.Contract(oracleAddress, oracleABI, provider);

async function getETHPrice() {
  const [roundId, answer, startedAt, updatedAt, answeredInRound] = await oracle.latestRoundData();
  const decimals = await oracle.decimals();
  const price = Number(answer) / (10 ** Number(decimals));
  return price;
}

// Display in your UI
const ethPrice = await getETHPrice();
console.log(`ETH Price: $${ethPrice.toFixed(2)}`);

// Calculate USD value of balance
const balance = await provider.getBalance(userAddress);
const balanceInETH = ethers.utils.formatEther(balance);
const balanceInUSD = balanceInETH * ethPrice;
console.log(`Balance: ${balanceInETH} ETH ($${balanceInUSD.toFixed(2)})`);

Option 3: List Token on CoinGecko (Long-term)

For MetaMask to automatically show USD values, the token needs to be listed on CoinGecko. This is a long process and requires:

  1. Token has active trading/market
  2. Meets CoinGecko listing requirements
  3. Submission and approval process

Not practical for custom chain native tokens.


🔧 Quick Fix: Update Oracle Contract

Script to update oracle with current ETH price:

#!/bin/bash
# update-oracle-price.sh

RPC_URL="https://rpc-http-pub.d-bis.org"
ORACLE_ADDRESS="0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6"
DEPLOYER_KEY="${DEPLOYER_PRIVATE_KEY}"  # Set your private key

# Get ETH price from CoinGecko
ETH_PRICE=$(curl -s 'https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd' | jq -r '.ethereum.usd')

if [ "$ETH_PRICE" = "null" ] || [ -z "$ETH_PRICE" ]; then
    echo "Error: Could not fetch ETH price from CoinGecko"
    exit 1
fi

# Convert to 8 decimals (oracle format)
PRICE_DECIMALS=$(python3 -c "print(int($ETH_PRICE * 100000000))")

echo "ETH/USD Price: \$$ETH_PRICE"
echo "Price in 8 decimals: $PRICE_DECIMALS"

# Update oracle contract
cast send "$ORACLE_ADDRESS" \
  "updateAnswer(int256)" \
  "$PRICE_DECIMALS" \
  --rpc-url "$RPC_URL" \
  --private-key "$DEPLOYER_KEY"

echo "Oracle updated successfully!"

Note: This requires the deployer's private key and the oracle contract must have an updateAnswer function.


📊 Verify Oracle Price

# Query oracle contract
cast call 0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6 \
  "latestRoundData()" \
  --rpc-url https://rpc-http-pub.d-bis.org

# Parse result
# Format: (roundId, answer, startedAt, updatedAt, answeredInRound)
# answer is in 8 decimals, so divide by 1e8 for USD price

📝 Summary

  1. Oracle contract needs price data - Currently returns all zeros
  2. Oracle Publisher service not running - Needs to be started/configured
  3. MetaMask limitation - Won't automatically use oracle for USD prices
  4. Workaround - dApps can query oracle and display USD values
  5. Long-term - Consider CoinGecko listing for automatic MetaMask USD display

Next Steps

  1. Update oracle contract with current ETH price
  2. Start/configure Oracle Publisher service (VMID 3500)
  3. Update dApps to query oracle for USD values
  4. Document limitation for users
  5. Consider CoinGecko listing (if applicable)

Last Updated: $(date)