[Solved] automatic payment; Ether Balance in function

Jonathan Asks: automatic payment; Ether Balance in function
I’m trying to write a smart contract which can receive and send Ether and a Token I created (COMMToken). The goal is that as soon as the contract receives 1 ETH it does two things:

  1. the contract sends 50 COMM (the Token I created) to the address who sends the 1 ETH
  2. the contract forwards the 1 ETH to the creator of the contract

Right now my code looks looks like this:

// SPDX-License-Identifier: MIT pragma solidity ^0.8.5;

import “./COMMToken.sol”;

contract receiveAndSend is COMMToken {

Code:
// functions to be able to receive Ether
receive() external payable {}
fallback() external payable {}

function getBalance() public view returns (uint) {
    return address(this).balance;
}

// functions to be able to send Ether
function sendViaCall(address payable _to) public payable {
    (bool sent, bytes memory data) = _to.call{value: msg.value}("");
    require(sent, "Failed to send Ether");
}

// code to forward 50 COMM to retailer if getBalance == 1 (1 ETH were sent from the retailer)
uint EthValue = getBalance();

function COMMTransfer(uint EthValue) public pure returns (string) {
    if (EthValue == 1) {
        transferFrom(address(this), 0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C, 50);
    } else {
        return "still no payment received";
    }
}

// code to forward 1 ETH to distributor = msg.sender address
function ETHTransfer(uint CommValue) public {
    if (balanceOf == 0) {
        sendViaCall(msg.sender);
    }
}

}

this is the error I get right now..

I really appreciate any help I get!


Error at line 27 (function COMMTransfer())

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.