2. Calculate the transaction fee as STARTGAS * GASPRICE , and determine the sending
address from the signature. Subtract the fee from the sender's account balance and
increment the sender's nonce. If there is not enough balance to spend, return an error.
3. Initialize GAS = STARTGAS , and take off a certain quantity of gas per byte to pay for
the bytes in the transaction.
4. Transfer the transaction value from the sender's account to the receiving account. If
the receiving account does not yet exist, create it. If the receiving account is a
contract, run the contract's code either to completion or until the execution runs out of
gas.
5. If the value transfer failed because the sender did not have enough money, or the code
execution ran out of gas, revert all state changes except the payment of the fees, and
add the fees to the miner's account.
6. Otherwise, refund the fees for all remaining gas to the sender, and send the fees paid
for gas consumed to the miner.
For example, suppose that the contract's code is:
if !self.storage[calldataload(0)]:
self.storage[calldataload(0)] = calldataload(32)
Note that in reality the contract code is written in the low-level EVM code; this example is
written in Serpent, one of our high-level languages, for clarity, and can be compiled down
to EVM code. Suppose that the contract's storage starts off empty, and a transaction is
sent with 10 ether value, 2000 gas, 0.001 ether gasprice, and 64 bytes of data, with bytes
0-31 representing the number 2 and bytes 32-63 representing the string CHARLIE .
The process for the state transition function in this case is as follows:
1. Check that the transaction is valid and well formed.
2. Check that the transaction sender has at least 2000 * 0.001 = 2 ether. If it is, then
subtract 2 ether from the sender's account.
3. Initialize gas = 2000; assuming the transaction is 170 bytes long and the byte-fee is 5,
subtract 850 so that there is 1150 gas left.
fn. 6