0

I don't quite understand the concept of payable in a function in the smart contract and the difference between payable ,view and pure.

1

Payable function means that you will send some ETH with the function. If you don't send any ETH with it, transaction will fail.

View is used to return data from function. Such function will read contract state/storage.

Pure is the same as View, except you can't read state/storage in it, but only do calculations with passed parameters or variables created inside function.

View and Pure are gas free when called from outside the contract or from other View/Pure function. If you call such function from inside normal function (which changes contract state), you will be charged however.

0

Payable means that the function can receive Ether via that function call. Comments in this contract explain this modifier.

View means that the function only reads from member variables contained within the contract. Explained here.

Pure states that no member variables within the contract are read from — all required data is in scope within the function itself. Explained here.

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.