iotexproject / iotex-core

Official implementation of IoTeX blockchain protocol in Go. An ultra-efficient EVM blockchain offering 1000 TPS with instant 1-block finality. Perfect for DeFi, DePIN tokenomics, Identities, and any trusted logic requiring Web3 composability
https://iotex.io
Apache License 2.0
1.55k stars 323 forks source link

Call fallback function in transfer actions #2737

Open CoderZhi opened 3 years ago

CoderZhi commented 3 years ago

https://github.com/iotexproject/iotex-core/blob/7c758ab75007a17606563303816229b3d252778f/action/protocol/account/transfer.go#L73

What would you like to be added: Enable transfer to a smart contract and trigger fallback function if any

Why is this needed: Be compatible with more dapps

maswalker commented 3 years ago

I think that transfer to contract has already been supported by execution. please refer to the commit, https://github.com/iotexproject/pebble-contracts/commit/122498880907af062b7652ed8801b4f00315227d

raullenchai commented 3 years ago

My testing example

pragma solidity 0.7.3;

contract Receiver {
    event Received(address, uint);
    uint256 cnt = 0;

    function getcount() public view returns (uint256) { 
        return cnt;
    }

    receive() external payable {
        cnt += 1;
        emit Received(msg.sender, msg.value);
    }
}

Verified that every transfer of IOTX to this contract increases count by 1, indicating it works.

raullenchai commented 3 years ago

Pending on #1600