Morais Archives - Rvpg media

Learn Solidity lesson 36. Cryptography and digital signature. | by João Paulo Morais | Coinmonks | Nov, 2022

The Ethereum virtual machine has a variety of cryptography-related opcodes, from hashing a generic set of bytes to verifying the authenticity of a signature. Solidity implements such opcodes quite simply. Let’s start with hash functions. Solidity implements three cryptographic hash functions: keccak256, sha-256 and ripemd160. The Ethereum network largely uses keccak256, as to calculate the … Read more

Learn Solidity lesson 31. Inheritance. | by João Paulo Morais | Coinmonks | Aug, 2022

One of the pillars of object-oriented programming is the concept of inheritance. A class can inherit properties and methods from another class, forming an heir tree. We will study this in detail in this and the next lesson. In the code below, a contract named Foo is defined, with a state variable. The contract Bar … Read more

Learn Solidity lesson 30. Contracts as classes. | by João Paulo Morais | Coinmonks | Aug, 2022

The official Solidity documentation specifies that contracts are similar to classes in object-oriented languages. We’ll look at this in greater detail in this and the next lessons. Classes are like models that allow us to create objects. They are the ideas of the Platonic world that model real objects. Thinking this way, the contract code … Read more

Learn Solidity lesson 29. OpenZeppelin’s implementation of the ERC20 token. | by João Paulo Morais | Coinmonks | Aug, 2022

OpenZeppelin is a company specialized in crypto and security. It provides an open-source library of smart contracts and its fungible and non-fungible token implementation is the most widely used today. It is quite simple to implement an ERC20 token using OpenZeppelin libraries. On their website there is a user interface, named Wizard, which writes the … Read more

Learn Solidity lesson 26. Error handling. | by João Paulo Morais | Coinmonks | Aug, 2022

We have already seen how to check a condition in Solidity using the require function. For example, if we want to check whether the balance of an account is greater than a certain amount, we can write the following statement. require(balanceOf[account] > 100); Thus, if the expression inside the parentheses is false, the transaction will … Read more

Learn Solidity lesson 25. Function modifiers. | by João Paulo Morais | Coinmonks | Aug, 2022

Modifiers are used to change the behavior of functions in a declarative way. They allow us to reuse code blocks in different functions, in addition to making them more readable. Let’s look at a classic example. It is common in contracts to want a certain function to be invoked only by a specific address, usually … Read more

Learn Solidity lesson 23. Loops and conditionals. | by João Paulo Morais | Coinmonks | Aug, 2022

Solidity has loops and conditionals similar to other programming languages. Its syntax is pretty much the same as C, Java, and JavaScript, so this chapter should be straightforward for anyone who is used to programming in languages like the ones above. When the program finds some kind of fork in its flow, where it must … Read more

Learn Solidity lesson 22. Type casting. | by João Paulo Morais | Aug, 2022

Solidity is a statically typed language, so all variables have a fixed type; it is not possible to change the type of the variable after its declaration. This is necessary because state variables have a dedicated space for them in storage. It is possible, however, to convert one type to another. This is called type … Read more

Learn Solidity lesson 20. Address type methods. | by João Paulo Morais | Coinmonks | Aug, 2022

The address type is one of the most used in Solidity, as it indicates accounts on the blockchain. Every account has a balance in the base coin. In the case of the Ethereum network, an account has a balance in Ether. On other EVM-compatible blockchains, such as Polygon, the balance is in some native token … Read more

Learn Solidity lesson 17. The structure of a smart contract. | by João Paulo Morais | Coinmonks | Aug, 2022

In this chapter we will see the structure of a smart contract, with all its possibilities. Smart contract files have a .sol extension and can have one or more contracts declared within them. We have already seen that the declaration of a contract is done by the sentence contract, but there are still two unexplored … Read more