Manage Domains Using Smart Contracts
This guide covers how to manage UD domain records using proxy contracts. This process requires using the Etherscan and Polygonscan user interface to write and execute contracts.
Step 1: Select a UNS Registry Smart Contract
The UNS Registry smart contract is where domain owners store their data and is a map of domain namehashes to key-value dictionaries of records. Choose one of the Unstoppable Registry smart contracts to interact with (either mainnet or testnet).
Step 2: Open the "Write as Proxy" Tab for the Registry Contract
Navigate to the Contract
tab in either the Etherscan or Polygonscan page of the Registry contract and click on the Write as Proxy
tab:
Step 3: Connect Your Web3 Wallet
Click on the Connect to Web3
button in the Write as Proxy
tab and connect the wallet associated with the domain:
Step 4: Manage the Domain Records
Choose the set
or setMany
method from the Write as Proxy
tab section. The set
method allows you to update a single record, while the setMany
method allows you to update multiple records simultaneously.
Next, add the record(s) you want to manage to the key
and value
fields as a single value for the set
method or array of values for the setMany
method.
info
Please see the Record Reference guide and reference JSON file for all the resolver keys used by the Unstoppable Domains UNS Registry.
Step 5: Generate the Namehash of the Domain
You can generate the namehash of a domain using any of the Resolution Libraries, Resolution CLI, or Resolution Service. You can also use online tools to calculate the namehash of the domain.
const {default: Resolution} = require('@unstoppabledomains/resolution');
// obtain a key by following this document https://docs.unstoppabledomains.com/domain-distribution-and-management/quickstart/retrieve-an-api-key/#api-key
const resolution = new Resolution({ apiKey: "<api_key>" });
let namehash = resolution.namehash("brad.crypto", "UNS");
import com.unstoppabledomains.resolution.Resolution;
// obtain a key by following this document https://docs.unstoppabledomains.com/domain-distribution-and-management/quickstart/retrieve-an-api-key/#api-key. See https://github.com/unstoppabledomains/resolution-java for more initialization options
DomainResolution resolution = new Resolution("<api_key>");
String namehash = resolution.getNamehash("brad.crypto", "UNS");
import UnstoppableDomainsResolution
// obtain a key by following this document https://docs.unstoppabledomains.com/domain-distribution-and-management/quickstart/retrieve-an-api-key/#api-key. See https://github.com/unstoppabledomains/resolution-swift for more initialization options
guard let resolution = try? Resolution(apiKey: "<api_key>") else {
print ("Init of Resolution instance failed...")
return
}
let namehash = try resolution.namehash(domain: "brad.crypto")
package main
import (
"fmt"
"github.com/unstoppabledomains/resolution-go/v3"
)
func main() {
// obtain a key by following this document https://docs.unstoppabledomains.com/domain-distribution-and-management/quickstart/retrieve-an-api-key/#api-key. See https://github.com/unstoppabledomains/resolution-go for more initialization options
uns, _ := resolution.NewUnsBuilder().SetUdClient("<api_key>").Build()
namehash, _ := uns.Namehash("brad.crypto")
fmt.Println("The namehash for brad.crypto is", namehash)
}
$ resolution namehash -d brad.crypto
"0x756e4e998dbffd803c21d23b06cd855cdc7a4b57706c95964a37e24b47c10fc9"
info
The JavaScript and Java Resolution Libraries require a Naming Service
parameter to generate namehashes. This specifies the name service that manages the domain name, and the value must either be "UNS"
or "ZNS"
.
After generating the domain namehash, insert it into the tokenId
field of the set
or setMany
method.
Step 6: Execute the Contract
Click the Write
button to sign the transaction and execute the contract. After signing the transaction, you can view its details on the blockchain explorer, like so:
Congratulations!
You have successfully managed your Unstoppable Domain records using smart contracts. Happy hacking!