0

can some help: I am getting withdrawEth - Undeclared indentifier error compiling the below contract:

contract MyToken is ERC20, Pausable, Ownable {
    event MTKBuyEvent (
        address from,
        address to,
        uint256 amount
    );
    
    event MTKSellEvent (
        address from,
        address to,
        uint256 amount
    );

    mapping (address => uint256) pendingWithdrawals;


    constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) public { 
        _mint(msg.sender, 1000);
    }

    // A wallet sends Eth and receives MTK in return
    function buyToken(uint256 _amount) external payable {
        // Ensures that correct amount of Eth sent for MTK
        // 1 ETH is set equal to 1 MTK
        require(_amount == ((msg.value / 1 ether)), "Incorrect amount of Eth.");
        transferFrom(owner, msg.sender, _amount);
        emit MTKBuyEvent(owner, msg.sender, _amount);
    }
    
    // A wallet sends MTK and receives Eth in return
    function sellToken(uint256 _amount) public {
        pendingWithdrawals[msg.sender] = _amount;
        transfer(owner, _amount);
        **withdrawETH();**
        emit MTKSellEvent(msg.sender, owner, _amount);
    }
}

1 Answer 1

1

Assuming that the contracts you inherit from (ERC20, Pausable, Ownable) are standard contracts and only have their standard functionality, you simply don't have function withdrawETH defined anywhere.

You are either using a wrong name or you forgot to implement the function.

Furthermore your buying and selling logic is incorrect. Buying should send tokens from the contract and should use transfer. Selling should take tokens from the seller with transferFrom and the transfer needs to be pre-approved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.