Skip to content

Interacting with a Resolver

Set Addresses, Text Records, and more

Some apps may want to allow for users to edit, update, or modify their name and its behaviour at a more advanced level. This is possible by interacting with the resolver contract of a name directly.

Checking Interface Support

Before you start sending transactions to users resolvers, you should check if they support the interface you want to use. This is done by calling the supportsInterface (see EIP-165) function on the resolver contract.

function supportsInterface(bytes4 interfaceID) external pure returns (bool)

In order to ensure that resolvers we interact with are compatible with specific standards you can call the above function on contracts with an interfaceID and then check the boolean it returns.

Interface IDs are calculated according to solidity ABI and stored in a four-byte value.

Updating a User's Record

If you want to help a user set their avatar, specify a preferred color scheme, or set any other record on their ENS name you can do so in specific cases.

First we need to check if the user's resolver supports the interface we want to use (see setText). Afterwhich you can call the setText() function on the user's resolver contract.

Solidity
interface Resolver {
    function setText(bytes32 node, string calldata key, string calldata value) external;
}

Note that only the Manager of a name can set records on the resolver. For unwrapped names, the manager can be found by calling owner() on the ENS Registry. For wrapped names, the manager can be found by calling ownerOf() on the Name Wrapper. You can find the contract addresses here.

Update a User's Resolver

Overwriting a user's resolver involves overwriting the behaviour of their ENS name.

To change the resolver of a name, the Manager must call setResolver() on either the ENS Registry or the Name Wrapper, depending on whether the name is wrapped or not.

To figure out if a name is wrapped, call owner() on the ENS Registry. If this returns the address of the Name Wrapper, that indicates the name is wrapped and you should call ownerOf() on the Name Wrapper to get the effective owner of the name. You can find the contract addresses here.

Solidity
// Both the ENS Registry and the Name Wrapper implement this interface
interface ENS {
    function setResolver(bytes32 node, address resolver) external;
}

Please do not change the resolver for a user without their permission. Overwriting the resolver is a destructive action and will overwrite any existing resolution logic.

Layer 2 & Offchain Resolvers

At the time of writing this the ecosystem around multichain and "writing" to layer 2 & offchain resolvers has yet to be standardized and is still under active development. Please check back at a later date.