0

I would like to create a contract that uses the view function, however, I must make sure that nobody can see what data I am sending to a view since it is a sensitive content. The contracts simply acts as the logic and view simply verifies that whatever is inputted (without changing the state of the contract) gives some output according to this logic.

Is it possible to have some privacy with the views? Also, can the miners always see what data is passed and collect the sensitive data I just mentioned ?

2 Answers 2

4

If you are calling a view function locally, the information is not propagated to the blockchain at all. So you can call it with whatever parameters and nobody will know what parameters you used.

But if you call the view function as part of a transaction, all of the data is visible in the blockchain and there are no easy ways to hide the data.

Not only miners can see transaction data, but everyone can see transaction data. So in that sense miners have no special privileges - all the data in the blockchain is visible for everyone, unless you use a local call.

2
  • No it is not a part of a transaction, just a web3 call function to a view with some parameters. So what I understood is that the web3 call to a view function is safe since nobody can intercept the call and see what parameters I am using. Commented May 16, 2021 at 19:08
  • 1
    Yes it's safe, as long as your connection to the node is safe. And as added by another answer, you should use your own node. Commented May 17, 2021 at 5:01
2

Solidity functions with the view modifier are read-only, they do not modify the blockchain. So external calls to these functions will not form part of an Ethereum transaction, and will therefore not be put on the mempool or sent to a miner.

When you call a view function with arguments, the arguments are packed into an RPC message which is sent to the Ethereum node you are connected to. If you are running your own Ethereum node (e.g. Geth) on your computer, then your function arguments will never travel beyond the confines of your computer.

But if you are connecting to an Ethereum node that is running remotely and is provided to you over the Internet by a service like Infura, then your secret arguments will be sent over to that remote service. E.g. if you connect to the Ethereum mainnet using MetaMask, then you are indirectly using Infura.

So if your arguments are top secret, either you run your own Ethereum node locally, or you need to trust the remote provider.

1
  • Good points. Just a small note: the calls to view functions will form part of a transaction, if they are part of a transaction. Commented May 17, 2021 at 5:01

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.