I'm confused about how the Smart Contracts work internally.
I've read this:
https://blog.zeppelin.solutions/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05
TLTR: there is an example of a smart contract "ProofOfExistence" saving the hash for some string into an array
contract ProofOfExistence3 {
mapping (bytes32 => bool) private proofs;
// store a proof of existence in the contract state
function storeProof(bytes32 proof) {
proofs[proof] = true;
}
// calculate and store the proof for a document
function notarize(string document) {
var proof = proofFor(document);
storeProof(proof);
}
// helper function to get a document's sha256
function proofFor(string document) constant returns (bytes32) {
return sha256(document);
}
// check if a document has been notarized
function checkDocument(string document) constant returns (bool) {
var proof = proofFor(document);
return hasProof(proof);
}
// returns true if proof is stored
function hasProof(bytes32 proof) constant returns(bool) {
return proofs[proof];
}
}
My questions:
1) What happens when I deploy that contract? in terms of the Ethereum blockchain. The code is saved in a new block on the Ethereum network? I mean in Bitcoin we send some BTC from one address to another, and that info is saved in a new block. Is there any analogy to this for Ethereum and Smart Contracts?
2) Is there any cost to deploy the smart contract?
3) How can I use that contract? Let's say I want to check if some string exists there, how can I do that? the same if I want to save a new string. What is the workflow to execute some function from the smart contract (and to get the result)?
4) Do we need ETH to execute some function on the Smart Contract? why? what is happening on the blockchain when executing it (not deploying)?
I know these could be a bit long to reply, but I'm pretty sure will be a good reference for many newbies like me :)