Solidity - Solidity 0.8.9 documentation

Solidity by Example

Remix - Ethereum IDE

Smart Contract Programmer

install the solidity compiler + SOLIDITY STATIC ANALYSIS + in the remix plugins

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.6; // tells the version of the solidity program 
	//^ sign is for supporting newer version of the program compiler 

contract nameOfTheContract {
		 // every contract start with a name like class or object  
	unit256 myNumber;   // unassign integer with it's size
	bool isActive;  // boolion ver
	bytes32 password; // uses less space , we need to choose the size
	string name; // in function we need to add memory 

	string [] names; // array of names 
	mapping (uint256 => bool) ids; (// hashmap , instant lookups
		{
				[0]: false // all units max 256 will be false by default 
				[1]: false 
				[2]: true 
			}

	address id; // 42 character eth wallet address // 0xdffj4Redf

	struct Person { // like an object, grouping all the primitives, array, mapping (celeing) 
		address id;
		string name;
		unit24 age;
		{

// we can use mapping to the actual struct
	mapping (address => Person) ids;
		{ 
			[0xdegf]: {
				id: 0x0000
				name:''
				age: 0
				}
		}
	enum Day { Monday, Tuesday }
	event // 
}

 constructor () public { // similar to angular (must be public)
	myName = 16; // initiating the values in the constructor of the verabeils 
	isActive = true;
	name = 'Tomas';
}

// function name(type name) {public | external | internal | private } {pure|constant|view|payable}
private // only accessable from with in this contract 
internal // acccessable from this contact and from any drive contracts  
external // this function will be only accessible externally 
public // everyone can access 

// {all this can be applied for variables like:
		unit256 public myNumber;  
		bool internal isActive;}

// pure - function is not reading from any environment and don't have side effects (calculations )
// view - if we need to read from the state need to use the view 
// constant - for returning constant like view
// payable - the user will be asked to spend some ether 

function setNumber(uint256 _newNumber) internal {
	require(_newNumber <= 10, "Number is above 10"); //the new number has to be lower or equal than 10 with an error 
	myNumber = _newNumber;
}

function getNumber() external pure returns (uint256)  {
	return 5* 5;
}

// we can use the modifier to require to reuse of the function 

modifier above10(unit256 _newNumber) {
	require(_newNumber <= 10, "Number is above 10");
	_;
}

function setNumber(uint256 _newNumber) internal above10(_newNumber) {
	myNumber = _newNumber; 
}

special variables 
now // gives the time now in mili seconds 
msg.sender // access to address of the sender 
msg.value // see the value the person is sending and check if ...

event PollCreated(uint256 _pollId);// creating new event 
emit PollCreated(pollId);