The full code: https://plnkr.co/edit/WYDB9fOvmRoUvCVw
Testing on the mainnet because: ENS on Rinkeby - Network does not support ENS?
1️⃣ setSubnodeOwner
works
https://etherscan.io/tx/0xfc88211f5ac3ca51dbcc9f39b6d00f4ce39c25febb248256bdc3925818c2e677
web3.eth.ens.('dearmoon.eth', 'hack', accounts[0], {from: accounts[0]}).then(function (receipt) {
console.log(receipt);
});
2️⃣ setResolver
works
https://etherscan.io/tx/0x562c26d3770804586ba9a432dc8ad9e22b02956dc81c3aec72ddb89e28f908e8
web3.eth.ens.setResolver('hack.dearmoon.eth', '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', {from: accounts[0]}).then(function (receipt) {
console.log(receipt);
});
3️⃣ setAddress
fails
https://etherscan.io/tx/0x2f077a521c5824ebecd8e9306a3f96dc955ec7bcb4f18c8e9fc781f7498c6af9
(Metamask told me it will fail but I send it anyway hoping for some helpful revert message)
web3.eth.ens.setAddress('hack.dearmoon.eth', '0x614962025820c57d6af5acff56b5879237daf559', { from: accounts[0] }).then(function (result) {
console.log(result.events);
});
I'm using: https://web3js.readthedocs.io/en/v1.2.7/web3-eth-ens.html#setaddress
Do you know why setAddress
fails? 🤷♀️
Existing research, good links:
https://github.com/ensdomains/subdomain-registrar - not good, the transfer is irrevocable, I need flexibility.
https://www.toptal.com/dapp/ethereum-name-service-dapp-tutorial - this is actually quite clever, including smart contract that does everything in a single transaction: https://github.com/radek1st/ens-subdomain-factory/blob/master/contracts/EnsSubdomainFactory.sol#L73-L79
registry.setSubnodeOwner(domainNamehash, subdomainLabelhash, address(this));
registry.setResolver(subdomainNamehash, resolver);
resolver.setAddr(subdomainNamehash, _target);
registry.setOwner(subdomainNamehash, _owner);
I'm thinking about using it but before doing complicated stuff I prefer to learn basics first.
Longer-term I would like to anyone register a subdomain but without me losing ownership.