Metaverse Identity Contract
What it does:
Allows users to create, manage, and verify their metaverse identity, linking avatars, credentials, and reputation across multiple platforms.
Why it matters:
Ensures verifiable digital identity, prevents impersonation, enables cross-platform reputation, and supports personalized experiences in virtual worlds.
How it works:
-
Users mint a unique on-chain identity NFT representing their metaverse persona
-
Identity can include metadata: avatar, bio, credentials, achievements
-
Reputation points, badges, or tokens can be associated with the identity
-
Integrates with Virtual Land Ownership, Gaming Asset Ownership, and Play-to-Earn Reward Engine
-
Supports verification by oracles or validators for achievements and cross-platform actions
-
Dashboards show identity details, linked assets, reputation, and activity history
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title MetaverseIdentity
* @author Nam
* @notice Creates and manages on-chain metaverse identities with avatars and reputation
*/
contract MetaverseIdentity is ERC721, Ownable {
struct Identity {
string avatarURI;
string bio;
uint256 reputation;
}
mapping(uint256 => Identity) public identities;
uint256 public identityCount;
mapping(address => uint256) public ownerToIdentity;
mapping(address => bool) public authorizedValidators;
// -------------------- EVENTS --------------------
event IdentityCreated(uint256 indexed identityId, address owner, string avatarURI);
event ReputationUpdated(uint256 indexed identityId, uint256 newReputation);
// -------------------- VALIDATOR MANAGEMENT --------------------
function approveValidator(address _validator) external onlyOwner {
authorizedValidators[_validator] = true;
}
function revokeValidator(address _validator) external onlyOwner {
authorizedValidators[_validator] = false;
}
modifier onlyValidator() {
require(authorizedValidators[msg.sender], "Not authorized validator");
_;
}
// -------------------- CONSTRUCTOR --------------------
constructor() ERC721("MetaverseIdentity", "MID") {}
// -------------------- IDENTITY MANAGEMENT --------------------
function createIdentity(string calldata _avatarURI, string calldata _bio) external {
require(ownerToIdentity[msg.sender] == 0, "Identity already exists");
identityCount += 1;
uint256 newId = identityCount;
identities[newId] = Identity({
avatarURI: _avatarURI,
bio: _bio,
reputation: 0
});
_mint(msg.sender, newId);
ownerToIdentity[msg.sender] = newId;
emit IdentityCreated(newId, msg.sender, _avatarURI);
}
function updateReputation(uint256 _identityId, uint256 _reputation) external onlyValidator {
Identity storage i = identities[_identityId];
i.reputation = _reputation;
emit ReputationUpdated(_identityId, _reputation);
}
function updateBio(uint256 _identityId, string calldata _bio) external {
require(ownerOf(_identityId) == msg.sender, "Not owner");
identities[_identityId].bio = _bio;
}
function updateAvatar(uint256 _identityId, string calldata _avatarURI) external {
require(ownerOf(_identityId) == msg.sender, "Not owner");
identities[_identityId].avatarURI = _avatarURI;
}
// -------------------- VIEW FUNCTIONS --------------------
function getIdentity(uint256 _identityId) external view returns (Identity memory) {
return identities[_identityId];
}
function tokenURI(uint256 tokenId) public view override returns (string memory) {
return identities[tokenId].avatarURI;
}
}