Gnosis Safe Functions – Executing View/Read Functions with ‘Raw’ Encoded Data

gnosisgnosis-safesolidity

I'm trying to execute an ERC721 "ownerOf" function through the Gnosis Safe interfacefunction ownerOf(uint256 tokenId) public view returns (address). When I use the Gnosis interface it works fine and I am returned the address of the owner.

But when I use the "Custom Data (hex encoded)" option, pass in custom data to do the exact same thing and execute the transaction (which costs gas) , I see the transaction in my history and on Etherscan but don't see the result anywhere. Is there anyway to execute a raw transaction and get the results for who the owner of the NFT is?

Best Answer

view functions on contract are meant to retrieve information. The Safe interface makes this possible and allows you to see the returned information. Solidity does not allow state changes in view functions (see Solidity docs)

Transactions are meant to perform state changes on the blockchain (e.g. transfer ownership). Additionally transactions do not have a return value (only a success flag).

Therefore invoking a view functions via a transaction does not really make sense and just burns gas.

Consensys has a blog post how to use view functions and events in smart contracts.

Related Topic