Is it possible to make a function only callable by owner but restricted to view? I tried something like that.
function getUserTokenBalance(address user) public view onlyAdmin returns (uint256) {
return balance[user];
}
Calling this method from web3
like:
contract.methods
.getUserTokenBalance('0x06bf3b021f10712655a8786f2bFfF11ddE0ea21B')
.call({ from: account.address })
.then((data) => {
console.log('balance: ', data);
})
.catch((err) => {
console.log('error', err);
});
returns some weird long number as string 3963877391197344453575983046348115674221700746820753546331534351508065746944
I guess it's not working because I have to send a transaction so the smart contract can verify me as the owner. However, what I want to achieve is to query some state in the smart contract without paying any fees.
require
statement which contains an error-message (and I'm guessing that theonlyAdmin
modifier contains suchrequire
statement) in aview
function.