Recently, I had the chance to study DApps. DApp stands for Decentralized Application, which refers to applications that run on a blockchain or P2P network. I summarized the notes I took while learning about DApps. Additionally, I added explanations to clarify my understanding.
Solidity is a statically typed programming language designed for developing smart contracts that run on Ethereum. The pragma solidity
statement indicates the Solidity version being used. This version statement helps check the compatibility of the code file. For your information, the file extension for Solidity is .sol
.
The code indicates that the Solidity version must be at least 0.8.0 and less than 0.9.0.
이 코드는 Solidity 버전이 0.7.0
이상인 것을 뜻해요. Ethereum IDE 컴파일러 버전을 따로 설정하지 않았다면 기본 설정으로 인한 에러가 발생하는데요.
Solidity 0.7.0
버전을 사용하고 싶다면, 컴파일러 버전을 0.7.x
으로 설정하거나 pragma solidity >= 0.7.0 < 0.9.0;
구문으로 수정해서 작성하면 된답니다.
컴파일러 버전 기본 설정을 유지하 면서 해당 구문을 사용하고 싶은 경우에는 Ethereum IDE 컴파일러 버전을 확인하고 컴파일러 버전으로 설정하면 돼요. 저는 현재 Solidity 기본 버전이 0.8.18
이어서, ^0.8.0
이상으로 변경해줬어요.
This code means that the Solidity version must be at least 0.7.0
. If you have not set a specific version for the Ethereum IDE compiler, you might encounter errors due to the default settings.
If you want to use Solidity version 0.7.0
, you can set the compiler version to 0.7.x
or modify the code to pragma solidity >= 0.7.0 < 0.9.0;
.
If you want to keep the default compiler version settings while using this code, check the Ethereum IDE compiler version and set it accordingly.
Currently, my default Solidity version is 0.8.18, so I changed it to ^0.8.0 or higher.
We can write a contract that can store and return data using contract
.
pragma solidity >= 0.8.0 < 0.9.0;contract storage {// function and state}
In Solidity, you must specify the data type when declaring variables.
So far, the data types I have learned include uint for representing integers, string for string types, bool for representing boolean values, and address for account addresses. Additionally, there are other data types such as int for signed integers and bytes for byte arrays. For those who want to learn more about data types, I recommend doing further research.
mapping
in Solidity is similar to the map
in JavaScript. It represents a key-value storage where each key is associated with a value.
When you use public, it allows external calls to the function or variable. Since there is public, there is also private. When you use private, the function or variable can only be accessed internally within the contract.
Personally, I found the for
loop in Solidity to be quite interesting. It’s the first programming language I’ve encountered that requires you to specify the data type when declaring the loop variable.
I felt a bit confused when I selected the EVM version, account, and value, and then clicked Deploy. After a few more actions, I saw that Ether was distributed according to the code I wrote for each account address. It was amazing to actually interact with the blockchain, which I had only heard about from friends who invest in it.