在上篇完结的时候,咱们制造出了这个独一无二可爱至极的角色:微信
这里咱们继续总结一些关于solidity语言的知识点。而且开始了解一些比较高级的内容。app
ERC20 tokens以及ERC721标准,和crypto-collectible。这些知识可让咱们能够和其余玩家交易本身的创造的角色。区块链
对于token的理解,众说纷纭。为了让你清醒的记忆token在这里的定义,我就不举例其余对token的解释了。ui
在这里,token就是一个Dapp,一个智能合约的意思。this
重要的事情说三遍: token就是一个Dapp,一个智能合约的意思。 token就是一个Dapp,一个智能合约的意思。code
这个智能合约能够追溯谁拥有多少"金币",而后有一些功能可让"金币"拥有者进行交易。继承
So basically a token is just a contract that keeps track of who owns how much of that token, and some functions so those users can transfer their tokens to other addresses.token
由于ERC20 tokens是一个已经被实现了的Dapp,就意味着,你能够直接在你的Dapp里面使用ERC20 tokens,不须要本身去定义本身的"金币"。 在ERC20 tokens这个Dapp里面,一个"金币",彻底等于另一个"金币"。若是你没有零钱"金币",你能够付给对方一个大面值的"金币",对方能够找零。接口
但在咱们这个游戏里面,你创造和训练的无敌角色,和其余刚刚创造的角色的价值是彻底不对等的,并且,在交易的时候,也不可能说是找0.5个角色。游戏
与之对应的另一个token标准:ERC721 tokens但是适用于咱们这个游戏。
ERC721 tokens are not interchangeable since each one is assumed to be unique, and are not divisible.
在Solidity里面,咱们能够这样建立一个智能合约,而且结成另一个
pragma solidity ^0.4.19; import "./ZombieAttack.sol"; contract ZombieOwnership is ZombieAttack { }
ERC721 Standard 多重继承
这是ERC721 Standard的定义:咱们只须要实现这些接口。
contract ERC721 { event Transfer(address indexed _from, address indexed _to, uint256 _tokenId); event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId); function balanceOf(address _owner) public view returns (uint256 _balance); function ownerOf(uint256 _tokenId) public view returns (address _owner); function transfer(address _to, uint256 _tokenId) public; function approve(address _to, uint256 _tokenId) public; function takeOwnership(uint256 _tokenId) public; }
ERC721 standard还只是一个草稿,并不是正式版。在这个游戏里面咱们就直接使用OpenZeppelin库里面的实现版本。
Note: The ERC721 standard is currently a draft, and there is no officially agreed-upon implementation yet. For this tutorial we're using the current version from OpenZeppelin's library
和继承同样,import,而且把要实现的接口放到合约定义的 is 后面。
import "./zombieattack.sol"; import "./erc721.sol"; contract ZombieOwnership is ZombieAttack, erc721 { }
本系列文章做者:HiBlock区块链技术布道群-Amywu
原文发布于简书
加微信baobaotalk_com,加入技术布道群
Blockathon|48小时极客竞赛,区块链马拉松等你挑战(上海)
时间:2018年10月19-21日
地点:(上海黄浦)露香园路1号(近淮海东路)P2
北京blockathon回顾:
Blockathon(北京):48小时极客开发,区块松11个现场交付项目创意公开
成都blockathon回顾: