1

I am trying to create a function that charges a user for calling the function. I came across an old example here and I am wondering what the currenct best practice is?

Add a transaction fee for each time a function is called

I have a modifier and a simplified function as shown below but it doesn't seem to charge a fee when I test it through metamask and check on etherscan, the transaction goes through normally but without the 0.02 eth fee. Is there something I am missing here?


    modifier requiresFee(uint fee) {
        require(msg.value == fee);
        _ ;
    }

    function simple() requiresFee(0.02 ether) payable external {

      owner.call.value(0.02 ether).gas(20317)("");

     // other parts of the function 

    }

Thank you

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.