Complicated register() payable method with loops throw error: contract call run out of gas

If you could start by rephrasing this obfuscated description into something that makes sense...


If you are looking for a way to "make" the caller of the register method transfer payUnit ETH to your contract, then you only need to verify that the caller has done so (inside your contract's method):

require(msg.value == payUnit, "did not pay the required amount");

Or alternatively:

if (msg.value > payUnit)
    payable(msg.sender).transfer(msg.value - payUnit);
else
    require(msg.value == payUnit, "did not pay the required amount");
1 Like