for developers
Integrate Mega Names
Display .mega names in your app. Resolve names to addresses and addresses to names with a few lines of code.
How It Works
MegaNames is a single contract — no registry/resolver split, no subgraphs. Two read calls cover most use cases:
- getName(address) → resolve address to name
- addr(tokenId) → resolve name to address
Contract
Address:0x5B424C6CCba77b32b9625a6fd5A30D409d20d997
Chain:MegaETH Mainnet (4326)
RPC:https://mainnet.megaeth.com/rpc
Display a .mega Name
Show a user's .mega name instead of their raw address. This is the most common integration.
import { createPublicClient, http } from 'viem'
const client = createPublicClient({
transport: http('https://mainnet.megaeth.com/rpc'),
})
const name = await client.readContract({
address: '0x5B424C6CCba77b32b9625a6fd5A30D409d20d997',
abi: [{
type: 'function', name: 'getName',
inputs: [{ name: 'addr_', type: 'address' }],
outputs: [{ type: 'string' }],
stateMutability: 'view',
}],
functionName: 'getName',
args: ['0x9D152D78b05f31EA6979061d432110c8664cA1a7'],
})
const display = name ? `${name}.mega` : '0x9D15...1a7'Resolve a Name to Address
Look up the address a .mega name points to — for example, letting users type "bread.mega" instead of pasting an address.
import { keccak256, toBytes, encodePacked } from 'viem'
const MEGA_NODE = keccak256(encodePacked(
['bytes32', 'bytes32'],
['0x' + '00'.repeat(32), keccak256(toBytes('mega'))]
))
function getTokenId(label: string): bigint {
return BigInt(keccak256(encodePacked(
['bytes32', 'bytes32'],
[MEGA_NODE, keccak256(toBytes(label.toLowerCase()))]
)))
}
const address = await client.readContract({
address: '0x5B424C6CCba77b32b9625a6fd5A30D409d20d997',
abi: [{
type: 'function', name: 'addr',
inputs: [{ name: 'tokenId', type: 'uint256' }],
outputs: [{ type: 'address' }],
stateMutability: 'view',
}],
functionName: 'addr',
args: [getTokenId('bread')],
})
// Returns 0x0 if name doesn't exist or is expired