1

I have the following function within my smart contract

function setRewardTokenForShareholder(address RWRD) external {
        require(customRewardsAllowed, "Contract: setRewardTokenForShareholder:: Custom Rewards arent allowed");
        
        // Check to ensure we have enough and also that we can 
        uint256 existingBalance = balanceOf(msg.sender);
        require(existingBalance < thresholdForCustomRewards, "You do not have enough tokens to changce your RWRD");

        require(isContract(RWRD), "Contract: setRewardTokenForShareholder:: Address is a wallet, not a contract.");
        require(RWRD != address(this), "Contract: setRewardTokenForShareholder:: Cannot set reward token as this token due to Router limitations.");
        require(!distributor.isBlacklistedRwrdToken(RWRD), "Contract: setRewardTokenForShareholder:: Reward Token is blacklisted from being used as rewards.");

        distributor.setNewRewardForShareholder(msg.sender, RWRD);
    }

What I'm trying to do here is do a bunch of checks on the shareholder to ensure they have enough tokens, the contract they want to set as their custom reward isn't blacklisted and is valid. However, when I fail one of the requirements, MetaMask says "We were not able to estimate gas..." and not the custom require error message.

Is there anything I'm doing wrong? I would much rather the error message I've defined would be used.

Pandapip1
  • 730
  • 5
  • 15
Andy
  • 679
  • 2
  • 10
  • 25
  • It's a problem of ethers (or whatever package you're using) and not of the smart contract – 0xSanson Sep 14 '22 at 13:57
  • ah, ok, well in this case i'm using BSCScan and not within a DAPP. So it's potentially that and not MM? – Andy Sep 14 '22 at 15:11
  • MM doesn't have a way to show the message I think. So the job should fall on bscscan. In any case you're not doing anything wrong (I just tested on other contracts and no-one show any message). – 0xSanson Sep 14 '22 at 16:38
  • ok cool, TY As it is, i'm working on the Dapp and i'm getting the error i expect. the only issue is what happens if someone wants to use the contract instead and not the dapp? will the txn fail and they wont be charged the 0.4 bnb? – Andy Sep 15 '22 at 14:03
  • If the tx fails they still pay a gas fee. It's possible that once failed, bscscan will show the error message on the tx page. – 0xSanson Sep 15 '22 at 14:19

0 Answers0