solidity tutorial 101

Harold C
4 min readApr 25, 2022

--

a simple learning log of solidity code language

update time: 2022 April 25 (some info maybe be outdated after a period of time, the world is changing)

this is a 10 mins long walking through, if you are a pro, plz skip the explanation part

A: what is solidity

Solidity is an object-oriented, high-level language for implementing smart contracts. Smart contracts are programs which govern the behaviour of accounts within the Ethereum state.

source:https://docs.soliditylang.org/en/v0.8.13/

B: how to start with solidity

Any text editor can start but in order to be able to run your smart contract,

option 1: the recommended way is to use a Web-IDE:https://remix.ethereum.org/

option 2: IntelliJ with eth-Java VM, the auto env setting up has been expired, pending to be fixed

option 3: VS studio, I have not verified yet

C: a demo using remix web-ide

step 1: choose solidity

On the left, you can see the files tab and contracts path

click in the contracts, then you will see three default sol files, if you wanna try your own code, plz add them in this path under “contracts”, or u can just reuse the file they provide you by default

this is a simple explanation of how solidity works

red-letter-1: declare the compatible syntax version of solidity

red-letter-2: contract section (like a class in python/java in my understanding)

red-letter-3: define a variable with the declaration

red-letter-4: function of storing the data (like setter in python)

red-letter-5: function of retrieving the data (like getter in python)

Step2: Compile your script

find the compile tab

what does compile mean:

contracts are like a class in the whole big program. In order to run it, we need to compile the program first like Java and C, maybe not python, for python, the code is runnable.

In other words, solidity is not JIT(just in time), so I think JIT will be the next roadmap of solidity

Step 3: Now let’s deploy

click the red-box-on-the-very-left: deploy tab

explain:

lets me explain some boxes here:

red-box-environment: define which environment it will run on

red-box-account: some fake account here, no worries it is not real money

red-box-contract: the contract you compiled before

now :

click the red-box-button: deploy

and it is online

explain:

1 red-box-contacts: the contract you just deployed with the address

2 red-box-store: it will call the setter function earlier we saw in the code here:

3 red-box-retrieve: get function

now you can play with it by setting whatever number which is within the data type:

uint data type does not allow negative numbers, only positive number

uint allow 0

now have fun and look forward to my next class

--

--

Harold C
Harold C

Written by Harold C

Blockchain <br /> Infra \n Security Data science Data engineering Full stack Flutter Devops Mlops Sec-ops All the tech you can image

No responses yet