I don't understand some points on Medium clone

Hello,
First of all, thank you for Medium clone tutorial.
But i didn’t understand some points into this smart contract: https://github.com/IAmJaysWay/Medium-Final/blob/main/smartcontract/Medium.sol

 if (contractBalance > 0) {
            payable(msg.sender).transfer(address(this).balance);
        }

Why do i need to transfer whole contract balance to the msg.sender if the msg.sender is not me?

  _safeMint(to, tokenId);
  _setTokenURI(tokenId, uri);

Where are these functions come from?

Thanks!

If you look at the top of your function there are some Open zeppelin imports. Your contract inherits from those. That is where _safeMint and _setTokenUri functions are.

The user pays to use your contract and the fee is transferred away from the contracts address and into the contract owners address on line 28. On line 42 you are transferring anything that they overpaid back to them.

FYI If you are using remix as your editor there is a plugin called “flatten” which will open all of the contracts you inherit from and put them into one file. You can see what is happening and this helpful for verifying contracts sometime also (usually I flatten them before deploying the contract to the main net)

1 Like