Knowing and understanding the four visibility modifiers of Solidity is a base requirement for any Solidity developer.

These modifiers are:

1. external
2. public
3. internal
4. private

And each has its own use case.

A thread.
1. external

Only functions can be marked external.

External functions are part of the contract interface and can be called from other contracts and transactions.

They can't be called internally.

This leads to external functions being cheaper to execute.

1/14
Arguments of external functions can be directly read from the calldata.

They don't need to be copied over to memory like for public functions.

2/14
The reason is that internal calls are executed through jumps in the code (under the hood). Array arguments are internally passed as memory pointers.

Because of this, internal calls always need all variables in memory.

3/14
Best practice: Always use external when you don't want to call the function from within the same contract.

This saves gas.

4/14
2. public

Both state variables (the 'properties' of your contract) and functions can be marked as public.

Public state variables and functions can both be accessed from the outside and the inside.

5/14
The Solidity compiler automatically creates a getter function for public state variables.

For a public state variable myVar, the compiler generates an automatic getter function myVar() that returns the value of myVar.

6/14
When myVar() is called from within the same contract, myVar is actually accessed.

If accessed externally, the function is evaluated.

7/14
Best practice: Use public for publicly accessible state variables and when you want functions accessible from the outside and inside.

8/14
3. internal

internal is the default visibility for state variables.

Internal functions and state variables can both be accessed from within the same contract and in deriving contracts.

They aren't accessible from the outside.

9/14
Best practice: Use internal whenever you think state variables and functions should also be accessible in deriving contracts.

10/14
4. private

Private is the most restrictive visibility.

State variables and functions marked as private are only visible and accessible in the same contract.

11/14
Important: Private is only a code-level visibility modifier.

State marked as private is still visible to observers of the blockchain. It is just not accessible for other contracts.

12/14
Best practice:

Use private when you really want to protect your state variables and functions because you hide them behind logic executed through internal or public functions.

13/14
5. Thread end

You've made it to the end of this thread. Thank you for taking the time to read it!

If you liked this thread, leave a like, retweet the first tweet, it would mean the world to me! 💛

If you want more content like this, follow me for more.

14/14

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Oliver Jumpertz

Oliver Jumpertz Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @oliverjumpertz

5 Jul
I found some awesome resources that teach you about blockchain technology.

They are short videos explaining blockchain technology to you in simple words.

A thread.
1. Asymmetric encryption

Encryption is one of the foundational building blocks of a blockchain. Knowing what it is and understanding how it works is definitely beneficial.



1/6
2. Zero Knowledge Proof

Blockchains are public databases.

Everyone decides what the truth is, and this video explains to you how it works.



2/6
Read 7 tweets
2 Jul
Some of the most important tools beginners in web development should take a look at:

- ESLint
- Prettier
- Babel
- Webpack/Parcel/Snowflake/esbuild
- Mocha/Jest

Let's go over them individually.

A thread.
1. ESLint

ESLint can take care of both code quality and code style.

Code quality covers issues like unused variables.

Code style covers issues like mixing spaces and tabs to indent code.

A good rule of thumb is to use ESLint to check your code quality.

1/9
2. Prettier

Prettier is a code formatter.

It takes care of code style and rewrites your code such that it conforms to your style guide.

Use prettier to take care of your code style while ESLint covers code quality.

2/9
Read 10 tweets
28 Jun
Okay, what actually is a dApp?

You might hear this term from time to time, and you have perhaps not spent much more thought on it.

But you are definitely missing out on something great, so let me give you an introduction!

A thread.
1. The internet today

Nearly all websites you visit every day are a perfect model of how the internet works today.

Someone creates a service (a website, e.g.), hosts it somewhere, and has it under full control.

1/24
If you own an app, you decide what happens. You store the data. You can often decide what you do with it.

And most importantly: You can prevent certain users from participating if you don't feel like they deserve to be around.

2/24
Read 25 tweets
23 Jun
I've developed software for over 21 years now, which is way over half of my lifetime, both professionally and as a hobby.

Here are some of the most valuable lessons I learned along the way.

A thread.
1. You will never know everything

Especially at the beginning, I thought I could learn everything, and I thought this for a good portion of my developer career.

But each time I learned something new, a whole new world of other concepts and techniques opened up.

1/47
It may seem tempting to try and learn it all, but it's a never-ending endeavor.

There will always be another library or framework and another cool thing you could also learn.

2/47
Read 49 tweets
22 Jun
Web 3.0 is the next evolutionary step of the internet and an awesome one, to be honest.

Every web developer, beginner, junior, or senior can and should contribute to it, and it doesn't even take too much effort.

Let's see how. A thread.

1/
If you are still unsure what the term "Web 3" or "Web 3.0" really means, you might want to read this thread first. 👇🏻



2/
1. Why you should care

The Web is inevitably going to evolve. The question is not if but when this is going to happen.

This process won't happen fast or overnight, though. Instead, it will be a slow transition, nearly unnoticeable.

3/
Read 21 tweets
22 Jun
I've implemented nearly a hundred smart contracts with Solidity during my short blockchain career, but I'm ready to drop Solidity right now if I think about WebAssembly on the blockchain.

Interested to learn more? Let's take a look at what WASM can do for blockchains!

🧵👇🏻

1/
Before we jump in:

If you don't exactly know what WebAssembly is, this thread might help you understand the basics first. 👇🏻



2/
1. The status quo

The blockchain world is currently divided. There are many languages one can use to develop smart contracts on different blockchains.

3/
Read 22 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(