简体   繁体   中英

Solidity two mint functions or one?

I have an ERC721 contract that has a whitelistEnabled property which, if enabled, requires the user to pass a merkleproof to the minting function. Currently, I have two functions: mint() {...} and mintWhitelist(merkleproof) {...} . Both functions have the same logic and custom implementation. The only difference is that the latter checks the merkleproof and the former doesn't.

Since the bulk of the two functions is the same, I was wondering if 'duplicating' the functions like this is the right, most gas efficient approach.

Would it be better to merge them into one? I think this might be the case, but I don't think there is a way to pass the merkleproof optionally (since there are no optional function parameters in Solidity).

Any help is appreciated!

You can add a boolean argument in the mint function for checks that need to merkelProof or not, if that was true you should check merhleProof and that logic is like WhiteList else you should ignore the merkelProof argument and that can be null or else. but actually, this code is so dirty and increases the gas fee for anyone use mint (not WhitListMint) and I think your code is good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM