The PolyDomains is a decentralized domain name registration and rental system built on the Ethereum blockchain. It allows users to register, manage, transfer, and rent subdomains under a specific Top-Level Domain (TLD). This project leverages NFTs to represent ownership of the domains, ensuring secure and transparent operations.
- Domain Registration: Users can register unique subdomains under a predefined TLD.
- NFT Representation: Each registered domain is represented as an ERC-721 token.
- Domain Records: Store and retrieve custom records for registered domains.
- Domain Transfer: Transfer ownership of domains between users.
- Domain Rental: Rent out domains for specific durations.
- Dynamic Pricing: Domain prices are determined by the length of the domain name.
- On-Chain Metadata: SVG-based domain logos and metadata are stored on-chain.
- Secure Ownership: Includes authorization checks for secure domain management.
- Withdraw Funds: Contract owner can withdraw accumulated funds.
Ensure you have the following installed:
git clone https://github.com/Enigmage/polydomains.git
cd polydomains/contractpnpm installnpx hardhat compilenpx hardhat testDeploy the Domains contract to a local or live Ethereum network.
npx hardhat run scripts/deploy.js --network <network-name>Replace <network-name> with localhost, goerli, or your target network.
To deploy to local network, start hardhat local network using
npx hardhat nodeThe Domains contract accepts a single parameter:
- _tld: The top-level domain string for the service (e.g.,
sns).
Example:
constructor(string memory _tld) payable ERC721("Scholar Name Service", "SNS") { ... }Registers a unique domain name under the specified TLD.
Input Parameters:
name(string): The desired domain name.
Requirements:
- The domain name must be unique and not already registered.
- Payment is required based on the domain name length:
- Shorter names cost more due to higher desirability.
function price(string calldata name) public pure returns (uint) {
uint len = StringUtils.strlen(name);
require(len > 0);
if (len == 3) {
return 5 * 10 ** 17; // 0.5 ETH
} else if (len == 4) {
return 3 * 10 ** 17;
} else {
return 1 * 10 ** 17;
}
}Payment Calculation:
uint price = (10 - length(name)) * 0.01 ether;Example:
registerDomain("example");Effect:
- Mints an NFT representing ownership of the domain.
- Emits a
DomainRegisteredevent.
Retrieves the Ethereum address of the current domain owner.
Input Parameters:
name(string): The domain name.
Output:
- Returns the owner’s address.
Example:
getDomainOwner("example");Transfers ownership of a domain to another Ethereum address.
Input Parameters:
name(string): The domain name.to(address): The recipient’s Ethereum address.
Requirements:
- The caller must be the domain owner.
Effect:
- Updates the domain ownership.
- Emits a
DomainTransferredevent.
Example:
transferDomain("example", 0xRecipientAddress);Sets a custom record for a domain.
Input Parameters:
name(string): The domain name.record(string): The record to associate with the domain.
Requirements:
- The caller must be the domain owner.
Effect:
- Updates the domain’s record mapping.
Example:
setRecord("example", "ipfs://hash");Retrieves the record associated with a domain.
Input Parameters:
name(string): The domain name.
Output:
- Returns the record (string).
Example:
getRecord("example");Rents a domain for a specified duration.
Input Parameters:
name(string): The domain name.rentalDays(uint256): The duration of the rental (in days).
Requirements:
- Domain must not already be rented.
- Payment is required based on the rental duration.
Effect:
- Temporarily transfers usage rights to the renter.
- Emits a
DomainRentedevent.
Example:
rentDomain("example", 30);Cancels the rental of a domain.
Input Parameters:
name(string): The domain name.
Requirements:
- The caller must be the current renter.
Effect:
- Ends the rental period.
- Emits a
RentalCanceledevent.
Example:
cancelRental("example");Checks if a domain is available for registration.
Input Parameters:
name(string): The domain name.
Output:
- Returns a boolean indicating availability.
Example:
checkDomainAvailability("example");Calculates the registration price for a domain.
Input Parameters:
name(string): The domain name.
Output:
- Returns the price in Wei (uint256).
Example:
price("example");Validates the format of a domain name.
Input Parameters:
name(string): The domain name.
Output:
- Returns
trueif the name is valid, otherwisefalse.
Example:
valid("example");- DomainRegistered: Emitted when a domain is registered.
- DomainTransferred: Emitted when a domain is transferred.
- DomainRented: Emitted when a domain is rented.
- RentalCanceled: Emitted when a rental is canceled.
- Unauthorized: Thrown for unauthorized actions.
- AlreadyRegistered: Domain already exists.
- InvalidName: Invalid domain name format.
- InsufficientPayment: Payment does not meet the required amount.
- InvalidRentalDuration: Rental duration is invalid.
Run tests using Hardhat:
npx hardhat testThis project is licensed under the MIT License. See the LICENSE file for details.