Typefully

Solidity Basics - A thread!

Avatar

Share

 • 

3 years ago

 • 

View on X

✨Solidity Basics - A thread!✨🧵 So, what is Solidity? Solidity is an object-oriented, high-level programming language we use to write smart contracts on the Ethereum blockchain.
Well, that's quite a mouthful, isn't it? Let's backtrack for a minute and try to understand what those programming buzzwords I threw at you actually mean.
What does Object-Oriented programming (OOP) mean? 🤔 OOP is a method of programming that involves the use of 'objects'. An object is a piece of code that allows you to create similar pieces of code again, and again so that you don’t have to write them over and over again.
These objects follow a blueprint called a Class. Here's a visual example: The car is a blueprint and different types of cars are created following that blueprint.
✨What is a high-level programming language?✨ An HLL programming language is one that lets you do more stuff with less code and has a higher level of abstraction.
✨Now on to Solidity.✨ Solidity is the primary language that runs on the EVM and is used for writing smart contracts on the Ethereum blockchain.
✨What's a smart contract?🤔✨ A smart contract is a piece of code stored inside the blockchain that enables two or more parties to exchange value with each other in a conflict-free manner while avoiding the need for a third party like a bank.
Smart contracts are just like contracts in the real world with their own set of rules, terms, and conditions written in code. They can be used for voting, crowdfunding, ownership registrations (like property ownership), etc.
Now, we can write smart contracts using multiple programming languages like Vyper, Yul, and Rust but for the Ethereum blockchain, the most popular choice seems to be Solidity.
✨Types of Variables in Solidity✨ To store data in a smart contract, there are 3 types of variables in Solidity. 1️⃣ State Variables: those variables that store data on the blockchain. State variables are declared inside the contract and outside of any function.
2️⃣ Local Variables: whose values are available only within a function they are defined in & can't be accessed from outside that function. 3️⃣ Global Variables: a special type of variable that stores info about blockchain, txns, and the account that has called the function.
✨Basic Value Types in Solidity✨ 1️⃣ Integer (int/uint): uint are unsigned integers (non-negative integers) while int are combinations of negative and non-negative integers. Their size ranges from 8 to 256 (in steps of 8): uint8, uint16, ... uint256.
2️⃣ bool: A variable with `bool` value type can hold any of the two values: true or false. The default value of a boolean is false. 3️⃣ address: The address value type represents an Ethereum address and holds a 20-byte value.
4️⃣ arrays: a collection of items of the same data type. Can have a compile-time fixed size or a dynamic size.
Now, in the code sample above, when we created different types of variables, we used a special keyword called `public`. Now, what is this public thingy? 🤔
Turns out this thing is called a "Visibility Modifier" in Solidity. ✨Visibility modifiers define the visibility of state variables and functions.✨
State Variables have access to three types of visibility modifiers: public, internal, or private, while Functions have access to an additional modifier: external.
1️⃣ Public means that both the state variable and the function can be accessed by the contract and by other smart contracts.
2️⃣ Private means that the variable and function are only accessible with the contract they are defined in. It is the most restrictive visibility. 3️⃣ Internal means that the variable & function can be accessed from within the same contract as well as its derived contracts.
4️⃣ External visibility means a function can be called from other contracts and transactions, but it cannot be called from within the same contract or any of its derived contracts. External visibility is not available for state variables.
ℹ️ ✨By default, all functions are `public`, whereas all state variables are `internal`.✨
If you'd prefer reading long-form content, here’s a blog post that goes into a little more detail: cryptoshuriken.com/100daysofweb3-week-0-solidity-basics-first-smart-contract-deployed/
Also, please consider subscribing to my newsletter & get content like this delivered right into your inbox. ⬇️ cryptoshuriken.com/#/portal/
Avatar

Akshay

@cryptoshuriken

Social Media Manager @Impact3Growth / Helping crypto brands & KOLs go viral / Memecoin degen