The NULS AI smart contract system implements domain name registration, management, and staking functions on the NULS blockchain. It consists of three main contracts:
-
NulsDomain - Core AI identity management contract
-
NulsDomainNRC721 - NFT implementation of AI identity ownership
-
NulsDomainStaking - Staking and reward mechanism
##Core contract
####Key functions
mint(string domain)
- Register a new AI identitymintWithTokenURI(string domain, string tokenURI)
- Register an AI identity with metadatasetTokenURI(BigInteger tokenId, string uri)
- Update AI identity metadatasetUserURI(string uri)
- Set user profile metadata
#####Domain name query
domain(BigInteger tokenId)
- Get AI identity by token IDdomainId(string domain)
- Get the token ID of the AI identitytokenURI(string domain)
- Get AI Identity Metadata URIuserAddress(string domain)
- Get the owner address AI IdentityuserURI(Address user)
- Get the user profile metadata
getDefaultPrice()
- Get the default AI Identity pricegetDomainPrice(int length)
- Get the price of a specific AI Identity lengthgetPriceByDomain(string domain)
- Get the price of a specific AI Identity
activeAward(string domain)
- Activate AI Identity Staking RewardsreceiveAwards()
- Receive available rewardspendingAward(Address user)
- View pending rewardsgetUserRewardReceived(Address user)
- View total rewards received
mint(Address to, BigInteger tokenId)
- mint new AI identity tokensmintWithTokenURI(Address to, BigInteger tokenId, string tokenURI)
- mint with metadataburn(Address Owner, BigInteger tokenId)
- destroy AI identity tokenstransferFrom(Address from, Address to, BigInteger tokenId)
- transfer AI identity ownership
ownerOf(BigInteger tokenId)
- get AI identity ownerbalanceOf(Address Owner)
- get the number of AI identities ownedtokenURI(BigInteger tokenId)
- get AI identity metadata URI
depositForOwn()
- stake NULS tokenswithdraw(BigInteger amount)
- Withdraw staked tokensquit()
- Completely exit stakingreceiveAwards()
- Receive staking rewards
pendingToken(Address User)
- View pending rewardsgetDepositInfo(Address address)
- View staking detailstotalDeposit()
- Get total staking amountminimumStaking()
- Get minimum staking amountlpSupply()
- Get total staking supply
DomainTransfer(Address from, Address to, string domain)
UserActiveAward(string user, BigInteger userPay, string domain, bool newId)
UserPendingAward(string user, BigInteger waiting)
DepositDetailInfoEvent(BigInteger value, long number, BigInteger amount)
PocmWithdrawEvent(string user, string amount)
CurrentMiningInfoEvent(List<CurrentMingInfo> info)
// Register a new domain name
contract.mint("mydomain.nuls");
// Register using metadata
contract.mintWithTokenURI("mydomain.nuls", "ipfs://metadata");
// Stake NULS
contract.depositForOwn({value: stakeAmount});
// Receive rewards
contract.receiveAwards();
// Withdraw stake
contract.withdraw(withdrawAmount);
// Get the owner of the AI identity
const Owner = contract.userAddress("mydomain.nuls");
// Get the price of the AI identity
const Price = contract.getPriceByDomain("mydomain.nuls");
// Check pending rewards
const Rewards = contract.pendingAward(userAddress);
- Reentrancy protection
- The contract implements reentrancy protection for key functions
- State changes occur before external calls
- Access control
- Owner-only management operation functions
- Official-only protocol management functions
- Properly verify caller permissions
- Input validation
- Domain name format and length check
- Amount verification for deposits/withdrawals
- Address verification for transfers
- Economic security
- Minimum and maximum staking limits
- Locking staking period
- Treasury fee collection
- Consensus reward distribution control
Common error messages:
- "AI identity already exists"
- "Insufficient payment"
- "Not the domain owner"
- "Amount is too small"
- "Stake is locked"
- "No rewards available"