iotex-core icon indicating copy to clipboard operation
iotex-core copied to clipboard

Call fallback function in transfer actions

Open CoderZhi opened this issue 3 years ago • 3 comments

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

CoderZhi avatar Jul 19 '21 23:07 CoderZhi

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

maswalker avatar Aug 15 '21 09:08 maswalker

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 avatar Aug 15 '21 15:08 raullenchai

Pending on #1600

raullenchai avatar Aug 23 '21 00:08 raullenchai