[SOLVED] Question of Contract

I try to write a contract for the test. There some questions

Where can I find all the interface of the Contract, Chain, Call. Or all the namespaces?

Why the public function main2 can modify state without declare “stateful”? code:

contract Identity =

  record state = { amount : int }
 
  public function init(x:int) : state =
    { amount = x }
  public stateful function main(test:int) =
    put(state{amount=test})
    state.amount
  public function main2(test:int)=
    put(state{amount=test})
    state.amount

How can I generate a random number?

How can I write event just like solidity?

The best overview of what is implemented in Sophia is probably protocol/solidity.md at epoch-v1.1.0 · aeternity/protocol · GitHub

The concept of stateful is not implemented yet, any function can modify the state in the current compiler version.

You cannot generate a random number, since all nodes have to verify the contract execution a truly random number cannot be generated. Pseudo-random numbers can be achieved for example using a the blockhash of a previous generation, or a standard PRNG algorithm. (In current master there is also String.sha3 that can be used for pseudo randomness.)

Sophia isn’t Solidity, so “just like Solidity” is not a concept :slight_smile: But in the current master (what will go into 1.2.0) there is an implementation of events that is quite similar to Solidity. The implementation is described here: protocol/sophia.md at master · aeternity/protocol · GitHub

@hanssv.chain how can i use String.sha3 to generate a random number ???
@emin.chain pls help if u can