js icon indicating copy to clipboard operation
js copied to clipboard

Override "from" on useReadContract

Open larron opened this issue 1 year ago • 2 comments

Ran into an edge case today where I have a public viewable method that uses msg.sender to determine the return value and it seems not possible to send an override of the "from" address on useReadContract.

Please let me know.

Thanks

larron avatar Jul 14 '24 20:07 larron

thanks for the report @larron - this would be very easy to add. mind telling us what contract you're using that has this behavior? helps me test it

joaquim-verges avatar Jul 15 '24 07:07 joaquim-verges

@joaquim-verges thanks for the swift response.

Something like this (extending openzeppelin ownable) is a good example:

contract TestOwner is Ownable {
    function test() public {
        if (owner() == msg.sender) {
            return true;
        }
        
        return false;
    }
}

Using the owner account get the test method to return true from the useReadContract

larron avatar Jul 15 '24 08:07 larron

Fixed in #3735 - will be released in the next version shortly

joaquim-verges avatar Jul 18 '24 00:07 joaquim-verges

merged!

joaquim-verges avatar Jul 21 '24 21:07 joaquim-verges

Excellent, thank you @joaquim-verges

I'll give it a try shortly.

larron avatar Jul 22 '24 02:07 larron

This does look to be working. Thanks again @joaquim-verges

larron avatar Aug 06 '24 15:08 larron