Skip to content

Commit

Permalink
Create erc721.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 6, 2024
1 parent dcdabe7 commit ec09e40
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions interoperability/ethereum/erc20/erc721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC721/SafeERC721.sol";

contract ERC721Token {
string public name;
string public symbol;
uint public totalSupply;
mapping (address => uint) public balances;
mapping (uint => address) public tokenOwners;
mapping (uint => string) public tokenURIs;

constructor(string memory _name, string memory _symbol) public {
name = _name;
symbol = _symbol;
}

function mint(address _to, uint _tokenId, string memory _tokenURI) public {
require(tokenOwners[_tokenId] == address(0), "Token already exists");
tokenOwners[_tokenId] = _to;
tokenURIs[_tokenId] = _tokenURI;
balances[_to]++;
totalSupply++;
emit Transfer(address(0), _to, _tokenId);
}

function transfer(address _to, uint _tokenId) public {
require(tokenOwners[_tokenId] == msg.sender, "Only the owner can transfer");
tokenOwners[_tokenId] = _to;
balances[msg.sender]--;
balances[_to]++;
emit Transfer(msg.sender, _to, _tokenId);
}

function ownerOf(uint _tokenId) public view returns (address) {
return tokenOwners[_tokenId];
}

function tokenURI(uint _tokenId) public view returns (string memory) {
return tokenURIs[_tokenId];
}

event Transfer(address indexed _from, address indexed _to, uint _tokenId);
}

0 comments on commit ec09e40

Please sign in to comment.