0

I want to call a read function which does a calculation and returns a result. It is important that the input will not be saved on the blockchain. If I were to use a write function then even if there isn't a state change (i.e., I don't save a variable) the transaction will forever be present on the blockchain with the secret input. How does it work with read a call? I'm confident that it isn't a transaction and does not propagate and thus does not remains on the blockchain. Is it running by the node I communicate with and leaves no trace then? and if so is it stored in some node caching mechanism for a while (e.g., in commonly used software like Geth) and can it be accessed by someone?

1 Answer 1

1

You can do calculations, read global variables (not edit), make local variables in a function to be called without showing any trace in blockchain.

When you call read function below, it will not be saved in the blockchain:

//SPDX-License-Identifier: MIT
pragma solidity >0.7.0 <0.9.0;
contract calculate{
    int something=10;
    function read(int a) view public returns(int){
        int square=a*a;
        int cube=square*a;
        return cube*something/10; // round off to integer
    }
}
// web3JS
var MyContract = new web3.eth.Contract(abi, address);
MyContract.methods.read(1234).call()
.then(console.log);

Also, Float is not allowed in solidity, so if u will use PI(3.14), or want decimal output, then you will get round off integer.

Provide codes in question for detailed answer.

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.