I am developing an app which allows users to create subdomains for certain domains which I own. I would like to attach certain avatars to my domains, and would like those avatars to be set for all subdomains and I do not want to allow those who buy the subdomains to be able to change those avatars.
How can I do this? Note: I am going to be using my own subdomainregistrar.
We think one way would be to create a function like:
function setAvatar(bytes32 _node, bytes calldata _image) external {
// Check if the caller is the parent of the subdomain
require(msg.sender == ens.owner(ens.parent(_node)), āOnly the parent can change the avatarā);
// Call the original setAvatar function from the parent contract
super.setAvatar(_node, _image);
// Check if the owner has set the avatar
if (AvatarMetadata(avatarRegistry).avatarURI(owner) != "") {
return true;
}
// Check if the parent has set the avatar
if (AvatarMetadata(avatarRegistry).avatarURI(parentOwner) == "") {
return true;
}
return false;
}
with updated fuseChecks
function fuseChecks(bytes32 node, string memory name) internal view {
require(!disallowOwnerAvatar(name), āAvatar can only be set by parentā);
require(!FuseRegistry(fuseRegistry).isFuseBlown(node), āNode fuse blownā);
require(!FuseRegistry(fuseRegistry).isFuseBlown(0), āGlobal fuse blownā);
}
You can accomplish this with a custom resolver contract. Then, when you create your subnames, also burn CANNOT_SET_RESOLVER.
Your custom resolver could be setup so that only the parent owner (you) can set the avatar, yet still allow the owner of the subname to set other records like their ETH address and so on.
Itās your custom resolver, so itās up to you what you want to pre-set or restrict.
Instead of allowing users to pass in their own resolver, your registrar would always set the resolver to your custom contract whenever any sub is registered.
The default ENS resolver is 0x231b0Ee14048e9dCcD1d247744d114a4EB5E8E63 - you would clone this contract and then edit in/out any restrictions you would like to impose on the Subname, and then force all Subnames to resolve at the new resolver contract address that contains your cloned / edited resolver contract.
In your namewrapper contract you would specifiy that Subname owner does not have the right to edit resolver / set a custom resolver.
This is a resolver I just whipped up based on @serenaeās spec. Iāve only added a couple tests and havenāt built the subdomain registrar that would need to be coupled with, but should serve as example of how it can be done.
Everything works okay, just a few issues. I removed the authorised modifier on setAvatar since I wasnāt able to call register on my registrar. I anyways wanted to remove it though, since Iād like anyone who calls register to be able to set the avatar. If I do things this way, are there any issues? I basically want to allow anyone to call register, but I donāt want them to be able to change the avatar once set (I know I have to burn the respective fuse, but is there anything else I should keep in mind?)
Next, when I try to edit my profile on the ENS website (v3), I get a notification saying that the resolver is out of date and I need to upgrade it. Why is this? (I am testing on goerli).
Finally, I have set my avatar, however itās not showing as the profile picture on the ENS website. Does it take time to set, have specific file requirements, or could something else be the issue?
If you remove the authorised modifier it means absolutely anyone can call setAvatar, which iām guessing isnāt what you want. You need resolver.setApprovalForAll(subdomainRegistrar.address, true) on the resolver for the parent name so it can set it for you.
I do setApprovalForAll from the namewrapper so I donāt need to from the resolver. Also, I want only the people who buy the subdomain to be able to set the avatar, and Iāve set a modifier which only allows the registrar to call setAvatar.
Is that an okay solution? Iām most concerned with safety.
Also, any idea why Iām being asked to update the resolver in the ENS v3 website (I assume itās a bug).