0

Sorry if this question is silly, I'm still learning.

My smart contract has a function which mints a token and is owned by the caller. I set it as public so it can be called externally through web3js. My game calls this mint function every time you beat a level. However, because it is a public function, is it true that someone can simply call this function without beating the game?

2

I recommend you read OpenZeppelin's article on Access Control in Solidity.

In your case, you would inherit from Ownable.sol and add the onlyOwnable modifier to the mint function. Here's an example for one of my contracts which does that:

function setMinGasReserve(uint256 newMinGasReserve) external override onlyOwner {
    minGasReserve = newMinGasReserve;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.