Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding L2 notes to Naming Contracts page. #354

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/web/naming-contracts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ contract ReverseClaimer {
}
```

You can also call the ReverseRegistrar's `setName` function directly. However note that if you do this, you will not be able to change the primary name for that contract ever again. Also remember to set the ETH address on your ENS name to the address at which your contract was deployed.

```solidity
import {ENS} from "../registry/ENS.sol";
import {IReverseRegistrar} from "../reverseRegistrar/IReverseRegistrar.sol";

contract ReverseClaimer {
bytes32 constant ADDR_REVERSE_NODE =
0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2;

constructor(ENS ens, string primaryName) {
IReverseRegistrar reverseRegistrar = IReverseRegistrar(ens.owner(ADDR_REVERSE_NODE));
reverseRegistrar.setName(primaryName);
}
}
```

You can read more about setting a primary name for a contract in on the [support page](https://support.ens.domains/en/articles/7902626-set-primary-name-for-contract).

## Existing Contracts
Expand All @@ -82,3 +99,23 @@ You can do so by hitting the `setNameForAddr` function on the [Reverse Registrar
From your contract you can execute `setName` function on the [Reverse Registrar](/registry/reverse)

<LiveDemo id="reversesetnamefordemo" />

## L2 Contracts

### L2 - Ownable

If you want to set a primary name for a contract you are deploying on an L2 chain, you need to make sure your contract implements the [Ownable](https://docs.openzeppelin.com/contracts/5.x/api/access#Ownable) interface from OpenZeppelin, and has an account you own set as the owner.

You will also need to locate the canonical Reverse Registry for that L2 chain. We currently do not have a way to discover those contracts, but for now, selected deployments are listed here: [Primary Names](/web/reverse#set)

Then, after you've deployed your contract, call `setNameForAddr(address addr, string name)` on the L2 Reverse Resolver from your authorized owner account. The `addr` is the address of your contract, and `name` is the ENS name to set it to.

### L2 - Manually

Another option is to call the L2ReverseRegistry's `setName(string name)` function directly, in the constructor of your contract. However note that if you do this, you will not be able to change the primary name for that contract ever again.

<Note>
Make sure that the ENS name also resolves to your contract address for the appropriate cointype.

For example, if you are deploying a contract on Base, make sure you set the Base address on your ENS name to your contract address.
</Note>
2 changes: 2 additions & 0 deletions docs/wrapper/creating-subname-registrar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ If you want your subname registrar to set records on a subname in the same regis
* Call whatever <a href="/resolvers/interacting">resolver methods</a> you need to. Perhaps these are records that you want to be pre-set on your subnames (such as an ETH address that the subname points to). Or perhaps these are records that you allow the registrant to pass in, so that they can register their subname and set whatever records they want all in one transaction.
* Call `setSubnodeRecord`, but this time set the owner to the actual intended owner of the subname. This is the point at which you should set the appropriate fuses and expiry you want to, as well.

In addition, you will need to make sure your contract follows the <a href="https://eips.ethereum.org/EIPS/eip-1155#erc-1155-token-receiver">ERC-1155 Token Receiver rules</a>. This means implementing the `onERC1155Received` and `onERC1155BatchReceived` methods, and signaling support for them in your ERC-165 `supportsInterface` method. OpenZeppelin has an easy abstract contract you can include for all this: <a href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/utils/ERC1155Holder.sol">ERC1155Holder.sol</a>

### Taking fees

If you are setting up a "rental" registrar, then your registration function should require a certain amount of ETH to be sent in as well.
Expand Down
Loading