0

I created a simple Erc20 token contract, i'd like to make the token approval on exchange(uniswap) only avaliable for just the owner of the contract. Everything seem to work fine but when a user goes to exchange and click on approve button in other to swap the token, nothing seem to work. I can only see the error in the console mode.

enter image description here

Everything works fine when i switch to the owner address (owner can successfully sign transaction). How can i get the user to sign the approve transaction first before getting the error message ?

Here is my code for approve

function approve(address delegate, uint256 numTokens) public override
    returns (bool success) {
  
  if (msg.sender != _owner) {
      
     revert ("Sender not authorized");
  } else {
      
     allowed[msg.sender][delegate] = numTokens;
     emit Approval(msg.sender, delegate, numTokens);
   
     return true;
  }  
}
3

1 Answer 1

0

The code explicitly reverts when the sender it not the owner. Unless that part is removed there's no way for a user to approve a third party to use transferFrom.

  if (msg.sender != _owner) {
      
     revert ("Sender not authorized");
  } else {

A user can discard the Metamask warning and send the transaction but it will fail.

Your Answer

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

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