0

I want to charge the user a fee evertime he does something with my smart contract, can I do this?

Would be nice if someone can explain it to me with this example: Everytime someone calls a function(in this example a increment or decrement function) he needs to pay a fee to me.

contract Counter {
    uint256 public count;

    address public Owner;

    event Increment(uint256 value);
    event Decrement(uint256 value);

    constructor() public {
        count = 0;
    }

    function increment() public {
        count += 1;
        emit Increment(count);
    }

    function decrement() public {
        count -= 1;
        emit Decrement(count);
    }
}

1 Answer 1

1

You can add a require statement to each function, such as require(msg.value > 1000). You will need a way for you to withdraw the funds stored on the contract to your private wallet as well.

4
  • i get an error: 'Error: processing response error ... Transaction reverted without a reason.'
    – robinnlmn
    Oct 2, 2021 at 16:33
  • Correct answer, 2 additional things: The msg.value is in Wei and the function should be payable :)
    – Majd TL
    Oct 2, 2021 at 16:34
  • Have that but still error
    – robinnlmn
    Oct 2, 2021 at 16:36
  • Add that in another question or modify ur question with the new code @robinnlmn
    – Majd TL
    Oct 2, 2021 at 16:52

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.