solidity quick start



Keywords for solidity


mapping (mapping(_KeyType => _ValueType) - use to express we're going to map 'KeyType' to get the intended 'ValueType'.  We will use address as a key and we get Voter type in return.

// This declares a state variable that
// stores a `Voter` struct for each possible address.
mapping(address => Voter) public voters;

payable - if a function supports payment (transfer  / receive payment) 

storage -

memory -

stack  -


msg.sender is the current account interacting with a transaction. Data type is address.

A very simple, get / set contract property example :-




Coin balance example.

In this example, solidity code allows user to mint / create coins and then keep track it it. A call to 'coinbalance' you will be able to query amount in an address.







Some common global variables / terms

  • block.blockhash(uint numberOfBlock) returns (bytes32): hash which belongs to the given block – will only work for 256 of the most recent blocks, not including current
  • block.difficulty (uint): difficulty of the current block
  • block.coinbase (address): miner’s address of the current block
  • block.number (uint): number of the current block
  • block.gaslimit (uint): gaslimit of the current block
  • block.timestamp (uint): timestamp of the current block as seconds passed since the unix epoch
  • msg.gas (uint): gas that remains
  • msg.data (bytes): complete calldata
  • msg.value (uint): amount of wei which was sent along with the message
  • msg.sender (address): message sender (current call)
  • msg.sig (bytes4): calldata’s first four bytes (i.e. function identifier)
  • now (uint): timestamp of the current block (alias for block.timestamp)
  • tx.origin (address): sender of the transaction (whole call chain)

More complex example






Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm