Anni Maan Profile picture
Jan 23, 2022 β€’ 24 tweets β€’ 7 min read β€’ Read on X
{1/24}

How to write a solidity code like a Professional?

This simplified style guide is intended to help Solidity programmers adhere to basic coding conventions. πŸ”₯

Mega Thread 🧡

#100DaysOfCode #Solidity #web3 #blockchain #100Devs #techtwitter
{2/24}
Properly styled computer code is more easily read and understood by humans.

You may revisit the code you write later, or you may work on code with other people in the future. It’s important that your code is easily understood by yourself and others.
{3/24}
Consistency:

Code is read much more often than it is written. The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Solidity code.
{4/24}
Indentation:

Use 4 spaces per indentation level.

Tabs or Spaces:

Spaces are the preferred indentation method.
Mixing tabs and spaces should be avoided. Image
{5/24}

Within a contract surround function declarations with a single blank line.

Blank lines may be omitted between groups of related one-liners (such as stub functions for an abstract contract) Image
{6/24}

Maximum Line Length:

Keeping lines under the PEP 8 recommendation to a maximum of 79 (or 99) characters helps readers easily parse the code.

Wrapped lines should conform to the following guidelines.
{7/24}

1. The first argument should not be attached to the opening parenthesis.

2. One, and only one, indent should be used.

3. Each argument should fall on its own line.

4. The terminating element, ); , should be placed on the final line by itself. Image
{8/24}

Assignment Statements: Image
{9/24}

Event Definitions and Event Emitters: Image
{10/24}

Imports:

Import statements should always be placed at the top of the file. Image
11/24
Order of Functions
Ordering helps readers identify which functions they can call and find the constructor and fallback definitions easier.

Functions should be grouped according to their visibility and ordered:
constructor
fallback function
external
public
internal
private Image
{12/24}

Control Structures:

The braces denoting the body of a contract, library, functions, and structs should: πŸ‘‡
{13/24}
- open on the same line as the declaration

- close on their own line at the same indentation level as the beginning of the declaration.

- The opening brace should be proceeded by a single space. Image
{14/24}

The same recommendations apply to the control structures if, else, while, and for.
{15/24}

Additionally, there should be a single space between the control structures if, while, and for and the parenthetic block representing the conditional, as well as a single space between the conditional parenthetic block and the opening brace.
{16/24}

Function Declaration:

For short function declarations, it is recommended for the opening brace of the function body to be kept on the same line as the function declaration.

The closing brace should be at the same indentation level as the function declaration. Image
{17/24}

You should explicitly label the visibility of all functions, including constructors. Image
{18/24}
The visibility modifier for a function should come before any custom modifiers. Image
{19/24}

In variable declarations, do not separate the keyword mapping from its type by a space.

Do not separate any nested mapping keyword from its type by whitespace. Image
{20/24}

Order of Layout:

Layout contract elements in the following order:

1. Pragma statements
2. Import statements
3. Interfaces
4. Libraries
5. Contracts
{21/24}
Inside each contract, library or interface, use the following order:

1. Type declarations
2. State variables
3. Events
4. Functions
{22/24}
Contract and Library Names:

Contracts and libraries should be named using the CapWords style.

Examples: SimpleToken, SmartBank, CertificateHashRepository, Player, Congress, Owned.

Contract and library names should also match their filenames.
{23/24}

If a contract file includes multiple contracts and/or libraries, then the filename should match the core contract.

This is not recommended, however, if it can be avoided. Image
{24/24}

Phew, that was a lot to consume. Let me know in the comment section below what were you doing wrong?

βœ…Follow for more content on Web3
βœ…Retweet the first tweet for better reach

CheersπŸ₯‚

β€’ β€’ β€’

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

Keep Current with Anni Maan

Anni Maan 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 @Anni_Maan

Jul 11, 2022
Learn WEB3 for FREE πŸš€

πŸ“– 30 Solidity Videos and 3 Projects

πŸ’Έ Project1: ERC20 Token
🏦 Project2: DEFI Bank
🎨 Project3: NFT

Thread πŸ§΅πŸ‘‡
Solidity Playlist
Project1: ERC20
Read 6 tweets
Jul 1, 2022
12 Tips to learn any new technology in less timeπŸš€

Thread πŸ§΅πŸ‘‡
Learning a new technology can be a scary task, but it doesn't have to be if you plan ahead of time.
I learned the following technologies and frameworks from scratch as a complete newbie in OOP in just one year using this technique. I don't pretend that I know each and every bit but I know enough.

Python
JavaScript
Solidity
React
Flask
NestJS
Tailwind
Blockchain
Read 23 tweets
Jun 30, 2022
7 Tips to help you enhance your problem-solving abilities πŸš€

Thread πŸ§΅πŸ‘‡
1. Understand the problem

The first step to solving any problem is to understand what the problem is. This may seem obvious, but it is often overlooked. Make sure you know what the problem is before trying to solve it.
2. Break the problem down

Once you understand the problem, the next step is to break it down into smaller, more manageable pieces. This will make it easier to find a solution.
Read 9 tweets
Jun 29, 2022
How did a clever transaction trick the Bitcoin system and generated 184 Billion new Bitcoins? πŸš€

Thread πŸ§΅πŸ‘‡
Back in 2010, there was a transaction that created 184 Billion new Bitcoins.

This was due to the fact that in C++, the amount field is a signed integer and not an unsigned integer.
A clever transaction passed all the checks, including the one for not creating new bitcoins, but only because the output amounts overflowed past the maximum number.

2^64 is 1.84 * 10^19 satoshis, which is 184 billion bitcoins.
Read 7 tweets
Jun 28, 2022
I can help you become a WEB3 developer in 30 days πŸš€

If you're willing to put in 30 minutes every day.

Thread πŸ§΅πŸ‘‡
A proper roadmap or structured approach can help you learn any new technology quickly.

Many people don't know where to start and how to learn WEB3 and that's the reason I'm starting this 30 days WEB challenge.
I will share daily one topic on WEB3 about which you can learn and practice. 30 minutes daily are enough to start with WEB3.

In the end, we will build 3 Projects to polish your WEB3 skills.
Read 5 tweets
Jun 28, 2022
Learning WEB3 is the Best Investment you can do in 2022πŸš€

FREE WEB3 learning resources

Thread πŸ§΅πŸ‘‡
Why are Blockchain and Web3 developers paid so well all over the world?

The answer is simple: there is a lot of demand and not enough supply.
If you want to work in WEB3 then learn javascript.

FREE javascript tutorial
scrimba.com
Read 16 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

Don't want to be a Premium member but still want to support us?

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

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(