3

I'm here for asking of a SECURE way to implement on solidity 0.8.0 two functions: 1-Withdrawal() which sends all the ether of the smart contract to the owner address. My current implementation is:

//send the ethereum on this contract to the owner 
function withdraw() external onlyOwner {
        address payable _owner = payable(owner());
        _owner.transfer(address(this).balance);
 }

2-Refund() which sends ether to the buyer of my token if the msg.value exceeds the cost of a single token. My current implementation is:

function createToken(xxx parameters) payable public {
        require(msg.value >= TokenCost, "not enough ether sent!");
        
        _createToken(xxx parameters);
        
        //refund user if he/she pays more than the singleCarCost value 
        payable(msg.sender).transfer(msg.value - TokenCost);
    }

Thanks in advance! Simone :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.