# Smart Contracts & Solidity Fundamentals

By [jackofcrypto](https://paragraph.com/@jackofcrypto) · 2022-01-06

---

By the end of this post, readers will be able to:

*   Explain what a smart contract is.
    
*   Explain how Solidity works and how it differs from Python as a programming language.
    
*   Explain how the Ethereum Virtual Machine (EVM) is an isolated environment and how Solidity code can access only on-chain data.
    
*   Explain how Remix supports blockchain development.
    
*   Create functions along with getters and setters in Solidity.
    

In essence, **smart contracts** are computer programs that allow credible transactions of digital assets under certain conditions without third parties. [Solidity](https://solidity.readthedocs.io/en/latest/index.html) is an object-oriented language for implementing smart contracts in Ethereum.

Smart Contracts and Solidity
----------------------------

Smart contracts allow application development and credible transactions that involve assets without a third-party overseer. Smart contracts rely on the following building blocks:

*   A robust, reliable and industry-supported blockchain technology
    
*   A robust and reliable programming language
    
*   An isolated execution environment
    
*   Robust encryption mechanisms
    
*   A suitable set of development tools for creating and deploying the smart contracts
    

Solidity, which is a human-readable programming language is like Python in the sense that its syntax comes close to human language (as opposed to the bits and bytes of a more computer-friendly language). This eases our ability to read, write, and understand Solidity code.

Solidity is a programming language that’s **statically typed**. This means that we need to specify a data type for each Solidity variable. By contrast, we don’t need to do this for Python variables.

Solidity includes several data types. The following image lists the main ones, which you can use for smart contracts, and includes Python and Solidity examples of using them:

![Python vs. Solidity data types](https://storage.googleapis.com/papyrus_images/c544cf586699a0733a85994f8234bc09a4c5e81587ead7c8ea91f5d13c427548.png)

Python vs. Solidity data types

The main data types in Solidity are string, positive number, negative number, wallet address, and boolean value.

*   A variable of type `string` stores a text value.
    
*   A variable of type `uint` stores a positive number. The keyword `uint` stands for “unsigned integer.”
    
*   A variable of type `int` stores a number. This type of variable can store a positive or a negative integer.
    
*   A variable of type `address` stores an Ethereum address. This is a special Solidity data type for storing an Ethereum address in a way that’s computationally more efficient than storing a string.
    
*   A variable of type `bool` stores a Boolean value—that is, `true` or `false`.
    

In Solidity, we have the `function` keyword followed by the function name. Then, the following syntax can specify many function arguments or none. You can define two special types of functions:

*   **Setter functions**, which can set or update the value of any variable.
    
*   **Getter functions**, which can get the current value of a variable.
    

By default, Solidity functions are public. This means that the function can be called from outside the contract—by either users or other contracts. This is known as **access control** in the object-oriented programming paradigm.

The EVM can store items in three areas: in the [Storage, Memory and the Stack](https://docs.soliditylang.org/en/v0.5.11/introduction-to-smart-contracts.html?highlight=storage#storage-memory-and-the-stack).

Here’s a summary of what happens when a Solidity smart contract runs:

*   The program first gets compiled. This means that it’s converted from human-readable syntax into a computer-friendly version of the code, called **bytecode**. Once compiled, the code runs in the EVM.
    
    *   The **EVM** is a software platform that’s embedded in each node of the Ethereum blockchain network. The EVM runs the bytecode that results from running a Solidity smart contract.
        

Solidity and Remix
------------------

We use an IDE for Solidity, just like we use an IDE for Python. But instead of using Visual Studio Code or JupyterLab, we’ll use the [Remix IDE](https://remix.ethereum.org/).

The Remix IDE is an open-source application for developing, deploying, and administering smart contracts that run on Ethereum-based blockchains. We can use this IDE for the entire development cycle of smart contracts and as a playground for teaching and learning Ethereum.

To create a new Solidity script in the Remix IDE, first click the **File Explorers** button (which appears in the upper-left area of the window). This causes the Solidity Compiler pane to change to the File Explorers pane, as the following image shows:

![Remix File Explorers](https://storage.googleapis.com/papyrus_images/f3e20b4f80d2a9686b825c717800381dde12cac5fb5ce1a292ae24485764b6d3.png)

Remix File Explorers

Just like `.py` is the file extension for our Python scripts, `.sol` is the file extension for our Solidity smart contracts.

![Solidity script editor](https://storage.googleapis.com/papyrus_images/a3b3b67cae4e5a01c7b9e460663f210feb6184f4f246a1c3d51da36fb7920861.png)

Solidity script editor

**Pragma** refers to the version of Solidity that we’ll use. As an example, use version 0.5.0, which we’ll define in the first line of our code.

We specify a smart contract by using the `contract` keyword and a set of braces ({ }) that defines the start and the end of the contract’s code.

Let’s wrap all of this together to show a contract script example:

    pragma solidity ^0.5.0;
    
    contract CustomerAccount {
        address owner;
        bool isNewAccount;
        uint accountBalance;
        string customerName;
        string customerLastName;
    
        function getInfo() view public returns(address, bool, uint, string memory, string memory) {
            return (owner, isNewAccount, accountBalance, customerName, customerLastName);
        }
    
        function setInfo(address newOwner, bool newAccountStatus, uint
          newAccountBalance, string memory newCustomerName, string memory newCustomerLastName) public {
            owner = newOwner;
            isNewAccount = newAccountStatus;
            accountBalance = newAccountBalance;
            customerName = newCustomerName;
            customerLastName = newCustomerLastName;
        }
    }
    

Finally, we click the Compile message\_contract.sol button to pass our Solidity script through the compiler. If the program successfully compiles, a green check mark indicating “compilation successful” will appear next to the **Solidity compiler** button.

Until next time, here’s a twitter thread summary of this post:

[https://twitter.com/jackofcrypto/status/1479160822513373190?s=20](https://twitter.com/jackofcrypto/status/1479160822513373190?s=20)

---

*Originally published on [jackofcrypto](https://paragraph.com/@jackofcrypto/smart-contracts-solidity-fundamentals)*
