1+ // SPDX-License-Identifier: MIT
2+ pragma solidity ^ 0.8.23 ;
3+
4+ // Contract for an unburnable token
5+ contract UnburnableToken {
6+ string private salt = "value " ; // A private string variable
7+
8+ // Mapping to track token balances of addresses
9+ mapping (address => uint256 ) public balances;
10+
11+ uint256 public totalSupply; // Total supply of tokens
12+ uint256 public totalClaimed; // Total number of tokens claimed
13+ mapping (address => bool ) private claimed; // Mapping to track whether an address has claimed tokens
14+
15+ // Custom errors
16+ error TokensClaimed (); // Error for attempting to claim tokens again
17+ error AllTokensClaimed (); // Error for attempting to claim tokens when all are already claimed
18+ error UnsafeTransfer (address _to ); // Error for unsafe token transfer
19+
20+ // Constructor to set the total supply of tokens
21+ constructor () {
22+ totalSupply = 100000000 ; // Set the total supply of tokens
23+ }
24+
25+ // Public function to claim tokens
26+ function claim () public {
27+ // Check if all tokens have been claimed
28+ if (totalClaimed >= totalSupply) revert AllTokensClaimed ();
29+
30+ // Check if the caller has already claimed tokens
31+ if (claimed[msg .sender ]) revert TokensClaimed ();
32+
33+ // Update balances and claimed status
34+ balances[msg .sender ] += 1000 ;
35+ totalClaimed += 1000 ;
36+ claimed[msg .sender ] = true ;
37+ }
38+
39+ // Public function for safe token transfer
40+ function safeTransfer (address _to , uint256 _amount ) public {
41+ // Check for unsafe transfer conditions, including if the target address has a non-zero ether balance
42+ if (_to == address (0 ) || _to.balance == 0 ) revert UnsafeTransfer (_to);
43+
44+ // Ensure the sender has enough balance to transfer
45+ require (balances[msg .sender ] >= _amount, "Insufficient balance " );
46+
47+ // Perform the transfer
48+ balances[msg .sender ] -= _amount;
49+ balances[_to] += _amount;
50+ }
51+ }
0 commit comments