pragma solidity ^0.4.19; | |
contract ERC721 { | |
string constant private tokenName = "My ERC721 Token"; | |
string constant private tokenSymbol = "MET"; | |
uint256 constant private totalTokens = 1000000; | |
mapping(address => uint) private balances; | |
mapping(uint256 => address) private tokenOwners; | |
mapping(uint256 => bool) private tokenExists; | |
mapping(address => mapping (address => uint256)) private allowed; | |
mapping(address => mapping(uint256 => uint256)) private ownerTokens; | |
mapping(uint256 => string) tokenLinks; | |
function removeFromTokenList(address owner, uint256 _tokenId) private { | |
for(uint256 i = 0;ownerTokens[owner][i] != _tokenId;i++){ | |
ownerTokens[owner][i] = 0; | |
} | |
} | |
function name() public constant returns (string){ | |
return tokenName; | |
} | |
function symbol() public constant returns (string) { | |
return tokenSymbol; | |
} | |
function totalSupply() public constant returns (uint256){ | |
return totalTokens; | |
} | |
function balanceOf(address _owner) constant returns (uint){ | |
return balances[_owner]; | |
} | |
function ownerOf(uint256 _tokenId) constant returns (address){ | |
require(tokenExists[_tokenId]); | |
return tokenOwners[_tokenId]; | |
} | |
function approve(address _to, uint256 _tokenId){ | |
require(msg.sender == ownerOf(_tokenId)); | |
require(msg.sender != _to); | |
allowed[msg.sender][_to] = _tokenId; | |
Approval(msg.sender, _to, _tokenId); | |
} | |
function takeOwnership(uint256 _tokenId){ | |
require(tokenExists[_tokenId]); | |
address oldOwner = ownerOf(_tokenId); | |
address newOwner = msg.sender; | |
require(newOwner != oldOwner); | |
require(allowed[oldOwner][newOwner] == _tokenId); | |
balances[oldOwner] -= 1; | |
tokenOwners[_tokenId] = newOwner; | |
balances[oldOwner] += 1; | |
Transfer(oldOwner, newOwner, _tokenId); | |
} | |
function transfer(address _to, uint256 _tokenId){ | |
address currentOwner = msg.sender; | |
address newOwner = _to; | |
require(tokenExists[_tokenId]); | |
require(currentOwner == ownerOf(_tokenId)); | |
require(currentOwner != newOwner); | |
require(newOwner != address(0)); | |
removeFromTokenList(_tokenId); | |
balances[currentOwner] -= 1; | |
tokenOwners[_tokenId] = newOwner; | |
balances[newOwner] += 1; | |
Transfer(currentOwner, newOwner, _tokenId); | |
} | |
function tokenOfOwnerByIndex(address _owner, uint256 _index) constant returns (uint tokenId){ | |
return ownerTokens[_owner][_index]; | |
} | |
function tokenMetadata(uint256 _tokenId) constant returns (string infoUrl){ | |
return tokenLinks[_tokenId]; | |
} | |
event Transfer(address indexed _from, address indexed _to, uint256 _tokenId); | |
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId); | |
} |
This comment has been minimized.
This comment has been minimized.
i see a logic bug here |
This comment has been minimized.
This comment has been minimized.
The function removeFromTokenList has two parameters, but it is only given one argument on line 58. The contract does not compile for this reason. |
This comment has been minimized.
This comment has been minimized.
What argument did you add as the second one? |
This comment has been minimized.
This comment has been minimized.
@vlugansky There's a reason there's a note at the top saying DO NOT DEPLOY TO THE NETWORK. It's way off-spec in the handling of approval events, as well. |
This comment has been minimized.
This comment has been minimized.
Hey @aunyks, I think this also needs a way to add meta-data to a token, e.g.:
The check |
This comment has been minimized.
This comment has been minimized.
Shouldn't line 48 be:
( |
This comment has been minimized.
This comment has been minimized.
Thanks a lot! |
This comment has been minimized.
This comment has been minimized.
i have a suspicion this is what you want
also add addToTokenList under line 48 after turning
|
This comment has been minimized.
This comment has been minimized.
ownerTokens[owner][_tokenId] = 0 |
This comment has been minimized.
This comment has been minimized.
So many bugs !!! improvements above all should add into it ! |
This comment has been minimized.
This comment has been minimized.
it supppose to be like this.... function removeFromTokenList(address owner, uint256 _tokenId) private { |
This comment has been minimized.
Has anybody implemented an ERC-721 compliant contract in production use-cases yet? I'm looking at doing something with it, in a prod-like setting.
Edit: Crypto Kitties...duh