Blockchain
ERC223


自己紹介

こんにちは、私はグウェン(https://twitter.com/gwenskiesHere)です。今日、ERC223についてを話し合いましょう。


ERC223とは

DexaranはERC223スタンダードを言い出した。ERC223トークンスタンダードではトークンを譲すことをetherトランザクションのように可能にするそして、手がけないトランザクションを手がけます。これはERC20のトランザクションの誤りを繕いますから、fundsを無くなってない。ERC223はERC777と使うことができます。ERC223のロジックはERC777と比較して簡単です。ERC223はless error-prone codeを保証います。ERC223トークンはきみの実装を頼る。


ERC223を使用する理由


  • To stop the continuous loss of tokens. There are reports of users losing a lot of ERC20 tokens just because they sent the tokens to the wrong contract.

  • To make the transfer mechanism of tokens similar to that of transferring Ether.

  • To correct the inability of handling incoming token transactions for non-supported tokens.

  • To eradicate one step out of the two-step process of transactions that happens in a token transfer.


ERC223 Use Case


Trust Wallet

trustWallet.PNG


ERC223Interfaceのコード


ERC223Interface.sol

pragma solidity ^0.4.11;

contract ERC223Interface {
uint public totalSupply;
function balanceOf(address who) constant returns (uint);
function transfer(address to, uint value);
function transfer(address to, uint value, bytes data);
event Transfer(address indexed from, address indexed to, uint value, bytes data);
}



ERC223のコード

ERC223はERC223Interfaceの関数をinheritする。


ERC223.sol

pragma solidity ^0.4.11;

import './ERC223_interface.sol';
import './ERC223_receiving_contract.sol';
import '././SafeMath.sol';

/**
* @title Reference implementation of the ERC223 standard token.
*/

contract ERC223Token is ERC223Interface {
using SafeMath for uint;

mapping(address => uint) balances; // List of user balances.

/**
* @dev Transfer the specified amount of tokens to the specified address.
* Invokes the `tokenFallback` function if the recipient is a contract.
* The token transfer fails if the recipient is a contract
* but does not implement the `tokenFallback` function
* or the fallback function to receive funds.
*
* @param _to Receiver address.
* @param _value Amount of tokens that will be transferred.
* @param _data Transaction metadata.
*/

function transfer(address _to, uint _value, bytes _data) {
// Standard function transfer similar to ERC20 transfer with no _data .
// Added due to backwards compatibility reasons .
uint codeLength;

assembly {
// Retrieve the size of the code on target address, this needs assembly .
codeLength := extcodesize(_to)
}

balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
if(codeLength>0) {
ERC223ReceivingContract receiver = ERC223ReceivingContract(_to);
receiver.tokenFallback(msg.sender, _value, _data);
}
emit Transfer(msg.sender, _to, _value, _data);
}

/**
* @dev Transfer the specified amount of tokens to the specified address.
* This function works the same with the previous one
* but doesn't contain `_data` param.
* Added due to backwards compatibility reasons.
*
* @param _to Receiver address.
* @param _value Amount of tokens that will be transferred.
*/

function transfer(address _to, uint _value) {
uint codeLength;
bytes memory empty;

assembly {
// Retrieve the size of the code on target address, this needs assembly .
codeLength := extcodesize(_to)
}

balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
if(codeLength>0) {
ERC223ReceivingContract receiver = ERC223ReceivingContract(_to);
receiver.tokenFallback(msg.sender, _value, empty);
}
emit Transfer(msg.sender, _to, _value, empty);
}

/**
* @dev Returns balance of the `_owner`.
*
* @param _owner The address whose balance will be returned.
* @return balance Balance of the `_owner`.
*/

function balanceOf(address _owner) constant returns (uint balance) {
return balances[_owner];
}
}


ERC223 Github: https://github.com/Dexaran/ERC223-token-standard

sources:

https://www.cointelligence.com/content/comparison-erc20-erc223-new-ethereum-erc777-token-standard/

https://medium.com/koinbros/what-are-erc20-and-erc223-tokens-307badcca5a