-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnft.sol
39 lines (32 loc) · 1.06 KB
/
nft.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
pragma solidity ^0.8.0;
contract nft {
struct nft_data {
uint256 id;
address owner;
}
nft_data[] public nft_datas;
mapping(uint256 => address) public id_to_addr;
mapping(address => uint256) public number_of_ids_per_address;
function mint() external {
uint256 id = nft_datas.length;
nft_data memory item = nft_data({
id : id,
owner : msg.sender
});
nft_datas.push(item);
number_of_ids_per_address[msg.sender]+=1;
id_to_addr[id] = msg.sender;
}
function balance_of(address _addr) external view returns(uint256) {
return number_of_ids_per_address[_addr];
}
function transfer(uint256 _id, address _to) external {
require(id_to_addr[_id] == msg.sender, "Only owner of the nft can transfer");
id_to_addr[_id] = _to;
number_of_ids_per_address[msg.sender]-=1;
number_of_ids_per_address[_to]+=1;
}
function totalSupply() external view returns(uint256) {
return nft_datas.length;
}
}