Continuing my quest to becoming a job-ready smart contract developer, I’ve been going over some of the stuff I had already tried to learn the first time I half-heartedly took up solidity. Some of it might be rudimentary or even redundant, but I’m just writing my thoughts here.
Here are some things that I’ve been covering:
Object-oriented programing (OOP): programming model based around data, or objects, rather than functions and logic.
Given that Solidity is an object oriented programing language, it’s important to use data modeling, an exercise to collect all objects in the contract and identify how they relate to each other in order to manipulate the objects accordingly.
Solidity contracts are similar to classes on other OOP languages, and each contract can contain decelerations of state variables, functions, structs, etc.
State Variables: variables whose values are permanently stored in contract storage.
Functions: declaration of an executable unit of code.
A data type that can group several variables together. In this example, we can tie variables like name, age and height to personalStats.
contract personalStats {
struct Person {
string name;
uint256 age;
uint256 height;
}
}
In terms of visibility, structs can be declared outside a contract so it can be shared by multiple contracts. Structs can also be declared inside contracts making them visible only in those contracts.
Arrays are data structures that store a fixed-size collection of objects of the same data type. It is often more useful to think of an array as a collection of variables of the same type.
//fixed array:
type arrayName [arraySize];
//dynamic array:
type[] arrayName;
Internal functions and variables can only be used internally while external functions are meant to be called by other contracts.
Public functions and variables can be used both internally and externally. Solidity automatically makes a getter function, ie a function used to retreive a variable value.
Private functions and variables can only be used internally and can not even used by derived contracts.
All reference type needs additional annotation, data location to direct where it will be stored
calldata and memory = variable will only exist temporarily/ exist within function
memory - used to store data for the execution of a contract. Memory is wiped once code is executed, less gas and holds functions argument.
calldata: non-modifiable, temporary data location; function arguments are stored here; available for external functions
storage - variable exists outside the function, data placed in storage is accessible to each execution of smart contract, consumes more gas and holds array, state and local variables of struct
//Example storage contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;
contract partyInvites {
int[] public invitees;
//Numbers function inserts values in invitees array
function Numbers() public {
invitees.push(1);
invitees.push(2);
//storage holds array
int[] storage myArray = invitees;
myArray[0] = 0;
}
}
*Data location can only be specified for an array struct or mapping types
A mapping is a data structure where a key is “mapped” to a single value. Mappings are used to store data in the form of key value pairs.
good way to think of it is as a dictionary and is created like other variables
//mapping syntax
mapping(key => value) <acess specifier> <name>;

So far this has just been a summation of a few key points from freeCodeCamp’s 32 -hour blockchain programming course. For next week, I plan to go through the course while also looking at CryptoZombies to supplement the coursework.
Crypto Chaos Radio 📡
RIP Trevor Strnad🤟

