pragma solidity ^0.6.0; // Any versions of 0.6.X will do.
contract SimpleStorage{
uint256 public favouriteNumber; // This value will be initialised to 0
//----Other types of variables----// // bool favouriteBool = true; // string favouriteString = "String"; // int256 favouriteInt = -5; // address favouriteAddress = 0xBEB40F5Fd51b8E499Ec25Eae84227b65ea84563E; // bytes32 favouriteBytes = "cat"; // Strings can be converted to bytes
// --- Visibility --- // // external - Can only be called by something outside of the contract // public - Anyone can call this value / function // internal - Can only be called by something inside of the contact, or any contracts deriving from it // private - Can only be called by within the contract, and NOT by any contacts deriving from it
// --- view, pure --- // // `view`, `pure` do not cost any transactions. // They only access the variables, and they do not make any state changes // `view` lets you read a variable number // `pure` function lets you do maths operation
// --- Struct --- // // Make your new data structure using struct!
struct People { uint256 favouriteNumber; string name; }
People public person = People({favouriteNumber: 777, name: "Hyunggi"});
// --- Arrays --- // // People[] public people_dynamic_array; // People[2] public people_static_array; People[] public people;
// --- mapping --- // // mapping - very similar to Python Dictionary. Hash table. mapping(string => uint256) public nameToFavouriteNumber;
// --- memory vs storage --- // // memory - Data will only be wstored during the execution of the function // storage - Data will persist even after the execution