-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.sol
39 lines (29 loc) · 1.26 KB
/
main.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract Registry {
// State variable to store a number
mapping(address => string) public names;
// Address of the required token contract
address public requiredToken;
// event everytime someone uses the function set
event NameSet(address indexed sender, string name);
constructor(address _requiredToken) {
requiredToken = _requiredToken;
}
// Allow users to set their name by sending 1 unit of the required token
function set(string calldata _text) public {
// Transfer the required token from the sender's account to the contract's account
ERC20(requiredToken).transferFrom(msg.sender, address(this), 1);
// Set the sender's name
names[msg.sender] = _text;
// Transfer the received token to the Ethereum burn address
ERC20(requiredToken).transfer(address(0x000000000000000000000000000000000000dEaD), 1);
// Emit the NameSet event
emit NameSet(msg.sender, _text);
}
// Implement the receive function to receive token transfers
receive() external payable {
// Do nothing. This function is needed to receive token transfers.
}
}