Code on the Blockchain - Electronic Contract Scripts
Turn classic unique punks into "standardized" non-fungible tokens
How? Non-fungible Tokens (ERC721 on Ethereum) each backed 1:1 by a CryptoPunk
Etherscan
- WrappedPunk (WPUNKS), see contract address
0xb7f7f6c52f2e2fdb1963eab30438024864c313f6
The WrappedPunk contract script is about 1 800 lines total.
Interfaces (Ethereum Standards and Optional Extensions) used / supported:
interface IERC721 // ERC-721 compliant contract
interface IERC721Enumerable // ERC-721 Non-Fungible Token Standard, optional enumeration extension
interface IERC721Receiver // ERC-721 token receiver interface
interface IERC721Metadata // ERC-721 Non-Fungible Token Standard, optional metadata extension
interface IERC165 // declare support of contract interfaces, which can then be queried by others
Libraries (re)used:
library SafeMath
library Counters
library Address
library Strings
The contract outline & inheritance for the WrappedPunk contract:
contract Context
contract ERC165 is IERC165
contract ERC721 is Context, ERC165, IERC721 // ERC721 Non-Fungible Token Standard basic
using SafeMath
using Address
using Counters
contract ERC721Enumerable is ERC721, IERC721Enumerable // ERC-721 Non-Fungible Token with optional enumeration extension logic
contract ERC721Metadata is ERC721, IERC721Metadata
using Strings
contract ERC721Full is ERC721Enumerable, ERC721Metadata // Full ERC721 Token
contract Ownable is Context
contract Pausable is Context
contract UserProxy
contract WrappedPunk is Ownable, ERC721Full, Pausable
And CryptoPunksMarket contract functions called (via the "imported" external functions in ICryptoPunk):
interface ICryptoPunk {
function punkIndexToAddress(uint256 punkIndex) returns (address);
function punksOfferedForSale(uint256 punkIndex) returns (bool, uint256, address, uint256, address);
function buyPunk(uint punkIndex) payable;
function transferPunk(address to, uint punkIndex);
}
The metadata details about the "Wrapped Cryptopunks" WPUNKS ERC721 non-fungible token.
string private _name = "Wrapped Cryptopunks"; // Token name
string private _symbol = "WPUNKS"; // Token symbol
ProxyRegistered
event ProxyRegistered(address user, address proxy);
proxies
Mapping from user address to proxy address
mapping(address => address) private _proxies;
registerProxy
Registers proxy for user
function registerProxy()
mint
Mints a wrapped punk
function mint(
uint256 punkIndex
)
burn
Burns a specific wrapped punk
function burn(
uint256 punkIndex
)
(Source: WrappedPunk.sol)