Below is a contract that i have commented on, hoping to understand the logic of the arguments.
Below in bold is the question in question. The .sol currently works fine.

pragma solidity ^0.5.11;

contract ReceiveEther {
    uint256 public clicksfromcreatorcount; 
    uint256 public count;
    address public creatorino = tx.origin;

I have a contract called "Receive Ether" with three variables. All of these variables are public, and two of them are integers, "clicksfromcreatorcount", and "count". The third variable is an address called "creatorino". It has been set to equal "tx.origin", which means "creatorino" is set to the address of the person (outside of the contract) that calls a function.

        function increaseifcreatorclicks() external {
            require (msg.sender == creatorino);

in this function, above, called "increaseifcreatorclicks" that is external, meaning it can be accessed from outside of the contract, "increaseifcreatorclicks" requires that that the address calling this function (msg.sender) be equal to "creatorino", the external address calling the function. When this condition is met, the aforementioned variable "clicksfromcreatorcount" goes up by a value of 1.

        function () external payable {
            require (clicksfromcreatorcount>=1);
            if (clicksfromcreatorcount ==1) {
                require (tx.origin == creatorino);

            require (count<2);

The function,above, that has no name can be called from outside of the contract (External) and can receive ether (payable). Only one of these nameless functions are allowed per contract. it requires that the value of "clicksfromcreatorcount" be greater than or equal to 1.
This means that the function can only receive ether if "clicksfromcreatorcount" is greater than or equal to 1.
HOWEVER, if "clicksfromcreatorcount" is exactly equal to 1, then the external address sending ether (tx.origin) must be equal to the address of creatorino???
Our payable function also has a counter called "count" that must remain less than 2 (though when i run it, it can be equal to 2 i'm not sure why) and that every time ether is sent to the contract, the count goes up by 1
Why do I have to set tx.origin ==creatorino for this to work, and how is it different from tx.origin==tx.origin if creatorino stands for tx.origin.

contract SendEther {
        function sendViaCall (address payable _to) public payable {
            (bool sent, bytes memory data) = _to.call.value(msg.value)("");
            require (sent, "failed to send ether");

Here we have a contract called "SendEther". It has a function called "sendViaCall". It can send ether to an address. It is public. If it does not send, 'failed to send ether' pops up. If it does send, we don't get a special message.

Admittedly i am still new

  • The storage variable creatorino is set when the contract is deployed. In following calls tx.origin is the person that signed the transaction. I'd guess those requires are there to allow the creator to initialize the contract. But without the whole contract is just a guess.
    – Ismael
    Commented May 19, 2020 at 22:50
  • that's along the lines of what i was thinking. Thank you. The broken up contract parts add up to make the whole contract.
    – rubecuber
    Commented May 19, 2020 at 23:10


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.