0

I'm trying to make a function that returns true if msg.sender is the owner.

This is my function;

function isAdmin() public view  returns (bool){
   require(admin == msg.sender);
   
    return true;
    
}

admin was given the value of msg.sender in the constructor.

Whenever I call this function it revert. From truffle or my app

truffle;

x = await contract.deployed()
x.isAdmin()

It revert!

My app;

await exchange.methods.isAdmin.call()

Also revert.

So what am I doing wrong?

2

Generally call will default to using 0x0000000000000000000000000000000000000000 as msg.sender, which is why this is reverting. That address is indeed not owner, so a revert is what you would expect. You can do call though and specific the msg.sender by doing await exchange.methods.isAdmin().call({from:addressYouWantToUse}) and replace the placeholder with the owner address

| improve this answer | |
  • And how do I read the result from the response? i was expecting just true but i receive a lot back. An object. – MadeInDreams Oct 24 at 23:03
  • exchange.methods.isAdmin().call({from:addressYouWantToUse}) will return the value returned from the function – MadeInDreams Oct 25 at 1:25

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.