Managing other addresses & Contract names
Sometimes you want to manage other addresses.
For example, you want to set a name for an address that is not yours. Or you want to set a name for an address that is not registered on Beranames. To do this, you need to be an approved operator for the address you want to manage.
In order to being successful in this operation, you need to follow these steps:
Let's take alice and bob as example.
Alice has minted a name on Beranames and set that name to resolve to Bob's address.Now, Alice wants that Bob's address resolves everywhere to that name.
How can she do that?
First of all, Alice needs to be an approved operator for Bob's address. So Bob needs to approve Alice to manage his address. Bob can do this by calling the
setApprovalForAll
function of theBeranNamesRegistry
contract.
here's the parameters:
address operator
: The address of the operator that will be approved.bool approved
: True if the operator is approved, false to revoke approval.
Then, Alice needs to set the name for Bob's address. She will need to call the
setNameForAddr
function of theReverseRegistrar
contract.
here's the parameters:
address addr
: The address that will resolve to the name.address owner
: The address that will be the owner of the reverse node.address resolver
: The address of the resolver that will be used to resolve the name. We recommend using theBeraDefaultResolver
contract.string name
: The name that will resolve to the address of Bob.
So in our case, Alice will need to call the following function:
NB. The owner
parameter could also be the Alice address, that depends on if Alice wants to be the owner of the reverse node of Bob's address or not.
And that's it! Now, Bob's address will resolve everywhere to "foobar.bera".
Bonus: Naming a contract
Naming a contract is pretty similar to naming an address.
You would pretty much follow the same steps, but with the additional advantage of being able to directly name a contract without the need of being set as an operator.
If the contract implements the Ownable
interface, and you are the owner of the contract, it's possible to name the contract by directly calling the setNameForAddr
function of the ReverseRegistrar
contract.
The ReverseRegistrar
supports the Ownable
interface and will let the owner of a contract set its primary name without having to add any BNS-Registry specific approval process.
And voila! You just named a contract!
Last updated