EIPs Explained

ERC-2304 · Stagnant · ERC · 2019-09-09

ERC-2304: Multichain address resolution for ENS

Adds an `addr(node, coinType)` function to ENS resolvers so one name can point to addresses on Bitcoin, Litecoin and other chains, not just Ethereum.

What problem does it solve?

The original ENS spec (EIP-137) lets a name such as alice.eth resolve to a single Ethereum address via addr(bytes32 node). Multi-coin wallets wanted more: a user should be able to type alice.eth and send BTC, LTC or DOGE too. Without a shared standard, each wallet would invent its own record format and names would not work across clients.

ERC-2304 standardises how non-Ethereum addresses are stored in and read from an ENS resolver.

How it works

  • A new resolver function addr(bytes32 node, uint coinType) returns (bytes) returns the address for a given chain. Its ERC-165 interface ID is 0xf1cb7e06.
  • coinType is the coin type index from SLIP-44 (for example Bitcoin 0, Litecoin 2, Dogecoin 3, Ethereum 60, Ethereum Classic 61).
  • The return value is the address in its native binary form, not the human-readable text. For Bitcoin-style chains that means the scriptPubkey bytes (e.g. a P2PKH address is stored as 76a914<20-byte hash>88ac); for Ethereum it is the raw 20 bytes with the 0x prefix removed. A name with no address for that coin returns empty bytes.
  • Resolvers must emit AddressChanged(bytes32 indexed node, uint coinType, bytes newAddress) on every change. The recommended setter is setAddr(bytes32 node, uint coinType, bytes addr).
  • Backwards compatibility: if a resolver also supports the old addr(bytes32), it must return the same value as addr(node, 60), and the old AddrChanged and new AddressChanged events must be emitted together.

Clients are responsible for converting between text and binary. When turning stored bytes back into an Ethereum-style address, they must apply the EIP-55 checksum.

Sample code

Resolver storage and accessors (simplified; access control omitted):

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract MultiCoinResolver {
    uint256 constant COIN_TYPE_ETH = 60;
    event AddressChanged(bytes32 indexed node, uint256 coinType, bytes newAddress);

    mapping(bytes32 => mapping(uint256 => bytes)) private _addresses;

    function setAddr(bytes32 node, uint256 coinType, bytes calldata a) external {
        // real resolvers check that msg.sender controls `node`
        _addresses[node][coinType] = a;
        emit AddressChanged(node, coinType, a);
    }

    function addr(bytes32 node, uint256 coinType) external view returns (bytes memory) {
        return _addresses[node][coinType]; // empty bytes if unset
    }

    function supportsInterface(bytes4 id) external pure returns (bool) {
        return id == 0xf1cb7e06 || id == 0x01ffc9a7;
    }
}

Reading a Bitcoin address with ethers v6, which decodes the binary format for you:

import { JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const resolver = await provider.getResolver("alice.eth");
const btc = await resolver?.getAddress(0); // coinType 0 = Bitcoin
console.log(btc);

Things to know

  • Status is Stagnant in the EIP repository. The ENS project maintains this scheme in its own ENSIP process, and it is what ENS resolvers and libraries implement in practice.
  • Always store the binary form, never the display string, and validate checksums when parsing user input; a mis-encoded Bitcoin scriptPubkey can make funds unspendable.
  • The spec includes test vectors for each listed chain. Use them when writing an encoder/decoder.
  • For resolving names that have no resolver of their own (e.g. user.wallet.eth), see ERC-2544 wildcard resolution.

#ens #naming #multichain #resolver #addresses

Details

Authors
Nick Johnson <[email protected]>
Status
Stagnant
Type
Standards Track / ERC
Created
2019-09-09
Requires
Required by

Machine-readable: Markdown · JSON