I am new to ethereum. We understand that whenever some new transaction made Contract state changes. What does it mean exactly by state change. Where they get stored.Are they called distributed ledger. Except transaction are there any events which cause state changes.
[Ethereum] What does it mean by smart contract state.Where they get stored
contract-developmentstate-transition
Related Solutions
Solidity's call
is a low-level interface for sending a message to a contract. It returns false
if the subcall encounters an exception, otherwise it returns true
. There is no notion of a legal call, if it compiles, it's valid Solidity.
nameReg.call("register", "MyName")
is a message that passes certain bytes to nameReg. For the bytes, see: Understanding nameReg.call("register", "MyName") style call between contractsnameReg.call(bytes4(sha3("fun(uint256)")), a)
is a message that would invoke a function namedfun
(if nameReg adheres to the ABI) and pass it the raw, unpadded dataa
(you need to correctly pada
to 32 bytes first if you want behavior to match the ABI. Foruint256
use left-padding.).
For 3, contract.call.value(...)(...)
is a way to add Ether when invoking a contract. if(!nameReg.call.value(10)()){throw;}
is an example of handling the failure case of the subcall. Note the extra parentheses value(10)()
which invokes the fallback function.
call
is a low-level interface, and it is simpler to invoke a function directly, nameReg.fun(a)
instead of the second example. The direct invocation is also type-safe, and allows the return value of fun
to be used.
When you call buyTicket
, your funds are saved to the contract. registrantsPaid
only records funds for every account that has called buyTicket
. All funds are saved to the contract, because a contract is an account.
If you call the destroy
function, the funds of the contract will be refunded to organizer
account. You can get the balance of the contract by this.balance
.
Your code has a bug , if numRegistrants >= quota
is true, the user calling buyTicket
will lose some funds, so you must refund him. Modified as follows:
pragma solidity ^0.4.13;
contract Conference {
address public organizer;
mapping (address => uint) public registrantsPaid;
uint public numRegistrants;
uint quota = 2000;
// ...
function buyTicket() payable public returns (bool success) {
require(numRegistrants >= quota);
registrantsPaid[msg.sender] = msg.value;
numRegistrants++;
return true;
}
// ...
function destroy() { // so funds not locked in contract forever
if (msg.sender == organizer) {
suicide(organizer); // send funds to organizer
}
}
function getContractBalance() constant returns (uint){
return this.balance;
}
}
Hope it helps~
Best Answer
What does it mean exactly by state change.
State change in a smart contract refers to a Transaction, which means two parties involved in the transaction will have some changes. For instance, if you send some money from one account to another - there will be changes on both sides. Similarly, it applies to data related transactions as well.
If you want to update the value of a variable defined in the smart contract then since you are going to use blockchain storage, so updating the variable is a state change here because you are making a transaction to make it happen. While this update/addition transaction, you will end up spending some gas.
Where they get stored.
The state changes get stored on the blockchain itself in terms of the transaction on distributed ledger.
Are they called distributed ledger.
Distributed ledger are not state or state changes, but on distributed ledger, you will have blocks of all transactions(state-changes) which happen on blockchain
Except transaction are there any events which cause state changes.
No, only transactions are the only way to state change on the blockchain.