Q: When deploying contracts, to what end can/is the ether value associated to the deployment transaction be used?
The value amount in ethers is transferred from the deploying account to the newly deployed contract. The contract is then able to transfer these amounts to other accounts or contracts.
Q: but who receives this value? or is it the value of the product between gasPrice and gas deducted from the creating account upon deployment (and received by miners)?
The deployed contract receives the value amount. The winning miner is paid (gasPrice x gasUsed) ethers, and this fee amount is deducted from the deploying account IN ADDITION to the value amount deducted.
- I want to deploy a poker contract (I won't as I do not want to encourage gambling)
- I have 100 ETH in the account I'm deploying the poker contract from
- The fee to deploy the contract is (gasUsed x gasPrice) = 0.01 ETH
- I want to load the poker contract with an initial amount of 50 ETH
- I deploy the poker contract with amount = 50 ETH
- 50.01 ETH will get deducted from my account
- The poker contract will have a 50 ETH balance on creation
- The winning miner receives a 0.01 ETH fee
- A gambler could win a round of poker and my poker contract will make a payment to the gambler from the 50 ETH balance
- A gamble could lose a round of poker and their payment will increase the ETH balance of the poker contract
Response to additional question in the comment:
So according to the answer to the first question the contract is an account which can, in turn, make transactions (including new contracts). But the contract is stored in the block chain meaning that it's publicly available to any node who synchronized with the block containing it, meaning that it's private key is visible to all peers? Doesn't this mean that it is possible to make transactions on behalf of a contract?
The contract does not have an associated private key. The contract will have a public key that is the account address the contract is deployed to. The contract code will have to be written to ensure that only the correct transactions are made to the right recipients.
Take the poker example:
- When deploying the poker contract, the contract stores the "owner" of the poker contract by saving the deploying account address.
- When players win a round of poker, the contract sends the winning account the ethers won
- When the owner wants to withdraw the accumulated winnings from the poker contract, the owner may call a
withdrawProfits() function, and this checks that the withdrawal is only made to the original deploying account address (which was stored in the poker contract's data when the contract was originally deployed).