Why link uses erc-677 standard to issue token


Wait a minute. Isn’t link erc207? How did it become erc677 again?

Don’t worry. Let’s start with erc20.

Erc20 is a set of protocol standards, code point of view is a set of interface API. Under this protocol standard, as long as the method specified in the protocol standard is implemented, it can be used as erc20 token. The methods that must be realized in the agreement are as follows:

//1. Total amount of token issue
function totalSupply() public view returns (uint256)

// 2. _ Token balance of owner account
function balanceOf(address _owner) public view returns (uint256 balance)

//3. Transfer_ Value number of tokens to_ To address
function transfer(address _to, uint256 _value) public returns (bool success)

//4. From_ Address transfer_ Value number of tokens to_ To address
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)

//5. Permission_ Spender can withdraw the total amount of_ Value number of tokens, unlimited number of times to extract
function approve(address _spender, uint256 _value) public returns (bool success)

//6. Return_ Spender can also access the_ Number of tokens extracted by owner
function allowance(address _owner, address _spender) public view returns (uint256 remaining)

In addition to these methods, erc20 also specifies two events:

//When the token is successfully transferred, the transfer event is triggered to record the sender, receiver and transfer amount of the transfer
event Transfer(address indexed _from, address indexed _to, uint256 _value)

//When the approval function is successfully called, the approval event is triggered to record the owner, the receiver and the approved amount
event Approval(address indexed _owner, address indexed _spender, uint256 _value)

The above is basically the whole content of erc20 token. Because link token is not only token, but also undertakes the function of data transmission on and off the chain, so if the erc20 token standard can not meet this requirement, link chooses erc677 protocol standard to implement.

Erc677 is an extension of erc20, which inherits all methods and events of erc20. It was first proposed by Steve Ellis, CTO of chainlink. In addition to including all methods and events of erc20, erc677 adds atransferAndCallmethod:

function transferAndCall(address receiver, uint amount, bytes data) returns (bool success)

As you can see, this method is better than that in erc20transferOne more methoddataThis field is used to carry user-defined data while transferring money. When the method is called, it is also triggeredTransfer(address,address,uint256,bytes)Event, record the sender, receiver, transfer amount and attached data. After completing the transfer and logging, the token contract will call theonTokenTransferMethod to trigger the logic of the receive contract. This means that the contract to receive erc677 token must be realizedonTokenTransferMethod to call the token contract.onTokenTransferMethods are defined as follows:

function onTokenTransfer(address from, uint256 amount, bytes data) returns (bool success)

The receiving contract can define its own business logic in this method, which can be triggered automatically when a transfer occurs. In other words, the business logic in the smart contract can trigger automatic operation through token transfer. This gives the application scenario of smart contract a lot of imagination. For example, the token contract of link is an erc677 contract, while the Oracle contract of chainlink is a contract that can receive erc677, which containsonTokenTransferMethod to execute the Oracle related business logic when receiving the transfer from link.

LINK token contract:


  *@ dev transfers the token to the contract address and carries additional data
  * @param _ To the address to go to
  * @param _ Value transfer amount
  * @param _ Additional data passed to the accepting contract
  function transferAndCall(address _to, uint _value, bytes _data)
    returns (bool success)
    super.transfer(_to, _value);
    Transfer(msg.sender, _to, _value, _data);
    if (isContract(_to)) {
      contractFallback(_to, _value, _data);
    return true;


Oracle contract:


    *@ notice is called when link is sent to the contract through the 'transferandcall' method
    *The first two bytes of @ dev payload data are`_ Sender 'and`_ The value of "amount" is overridden to ensure correctness. The oraclerequest method is called
    * @param _ Sender address
    * @param _ Number of links sent by amount (unit: Wei)
    * @param _ Load data of data transaction
  function onTokenTransfer(
    address _sender,
    uint256 _amount,
    bytes _data
    assembly {
      // solium-disable-next-line security/no-low-level-calls
      mstore(add(_data, 36), _sender) // ensure correct sender is passed
      // solium-disable-next-line security/no-low-level-calls
      mstore(add(_data, 68), _amount)    // ensure correct amount is passed
    // solium-disable-next-line security/no-low-level-calls
    require(address(this).delegatecall(_data), "Unable to create request"); // calls oracleRequest



Link token contract is erc677 contract, which is an extension of erc20 contract and compatible with erc20 protocol standard. It can carry data during transfer and trigger the business logic of receiving contract, which can help smart contract expand application scenarios.

reference resources:






Author: [email protected] (team leader)

Welcome to the chainlink developer community

Why link uses erc-677 standard to issue token