What is Chainlink and why it is important for crypto-ecosystem?

Why

Blockchain’s inability to fetch reliable information from the real world

● Huge vulnerability in decentralized applications when Blockchain wants to take advantage of off-chain data

● Origins of data are also the points where data can be manipulated, compromised, or simply falsified

● Chainlink started on Ethereum but it’s also available on Polkadot, Hyperledger, etc…

Decentralized network of nodes that provide data and information from off-blockchain sources to on-blockchain smart contracts via oracles. LINK is built on Ethereum in accordance with the ERC-20 standard for tokens

❏ Sep 2017 – Chainlink raises $32 million in an ICO creating 1 billion LINK tokens

❏ Nov 2018 – Chainlink acquires TownCrier

❏ May 2019 – Chainlink is launched on Ethereum mainnet

❏ May 2021 – Chainlink 2.0 whitepaper

Oracle – Middleware that acts as an intermediary, translating data from the real world to smart contracts on the blockchain and back again

Chainlink – Decentralized network of nodes that provide data and information from off-blockchain sources to on-blockchain smart contracts via oracles

🥇 Market standard for decentralized oracles

✅ Enhance and extend the capabilities of smart contracts on a target blockchain through functions that are not available natively

✅ To minimize the potential failure of oracles: Distribution of data sources, Distribution of oracles and Use of trusted hardware

✅ The Chainlink Reputation Contract

Chainlink 2.0: Next Steps in the Evolution of Decentralized Oracle Networks

Oracle networks go far beyond delivering highly validated data, they provide the various decentralized
services that are combined with smart contracts to create real world outcomes. These hybrid smart
contracts are already redefining our industry as DeFi.

🔥 Hybrid Smart Contracts that are seamlessly connected to all necessary off-chain resources, while retaining increased levels of privacy and being secured

🔥 New “architecture” enables more advanced off-chain computation

🔥 Increase number of services since ecosystem is more flexible and enhance its capabilities. Chainlink is the future of DeFi

Glossary

ERC-20: technical standard used to issue and implement tokens on the Ethereum blockchain. It makes easier for developers to predict with more accuracy the interaction between different tokens and applications

Faucet: website that distributes small amounts of crypto

ICO: An Initial coin offering occurs when company looking to raise money to create a new coin, app, or service launches an ICO as a way to raise funds. Similar to an IPO

Middleware: software that acts as a bridge between an operating system or database and applications, especially on a network

Off-chain: Transactions which agree to happen outside the blockchain

On-chain: normally refer to as blockchain transactions which happens inside the blockchain

Additional Information

Top Oracles Tokens by Market Capitalization

77 Smart Contract Use Cases Enabled By Chainlink

Expanding Beyond Data Delivery With Chainlink 2.0


Inheritance in Solidity explained

Intro

Solidity supports multiple inheritance including polymorphism. Inheritance is the process of defining multiple contracts that are related to each other through parent-child relationships. The contract that is inherited is called the parent contract and the contract that inherits is called the child contract.

When a contract inherits from other contracts, only a single contract is created on the blockchain, and the code from all the base contracts is compiled into the created contract. This means that all internal calls to functions of base contracts also just use internal function calls.

The benefits of using inheritance are: Ability to change one contract and have those modifications reflected in others, Reducement of dependency nad Ability to reuse existing code more.

Example of Inheritance

pragma solidity ^0.8.0;

contract Grandparent {
    function myFunction() public pure virtual returns (string memory) {
        return "Contract Grandparent";
    }
}

// Contracts inherit other contracts by using the keyword 'is'.
contract Parent is Grandparent {
    // Override Grandparent.myFunction()
    function myFunction() public pure virtual override returns (string memory) {
        return "Contract Parent";
    }
}

contract Uncle is Grandparent {
    // Override Grandparent.myFunction()
    function myFunction() public pure virtual override returns (string memory) {
        return "Contract Uncle";
    }
}

Note: Solidity copies the base contracts into the derived contract and a single contract is created with inheritance. A single address is generated that is shared between contracts in a parent-child relationship.

💡 Gotchas

  • In the case of multiple inheritances, function calls using super gives preference to most derived contracts;
  • There are different types of inheritances: Single, Multi-level, Multiple and Hierarchical;
  • A derived contract can access all non-private members including state variables and internal methods. But using this is not allowed;
  • We can call a super contract’s function using a super keyword or using a super contract name;

Additional Information

Inheritance in Solidity – Solidity docs


Basic of Mappings in Solidity

Mappings are one of the most used complex data types in Solidity. Mappings act as hash tables which consist of key types and corresponding value type pairs – pretty similar to hash tables or dictionaries in other languages. They help in storing key-value pairs and enable retrieving values based on the supplied key.

Mappings are declared using the mapping keyword followed by data types for both key and value separated by the => notation. Mappings have identifiers like any other data type and they can be used to access the mapping and can only have type of storage and are generally used for state variables. Solidity automatically creates a getter function for it.

Although it is similar to a hash table and dictionary, Solidity does not allow iterating through mapping. A value from mapping can be retrieved if the key is known. The next example illustrates working with mapping.

Another characteristic about mapping is the absence of iteration support but there are ways to work round this limitation. Notice that iterating and looping are an expensive operation in Ethereum in terms of gas usage and should generally be avoided.

💡 Gotchas

  • Mappings do not have a length, nor do they have a concept of a key or a value being set
  • It is also possible to have nested mapping, that is mapping consisting of mappings
  • Mappings can only be used for state variables that act as storage reference types
  • Mapping cannot be declared within functions as memory mappings
  • When mappings are initialized every possible key exists in the mappings and are mapped to values whose byte-representations are all zeros

Additional Information

Types in Solidity – Solidity Docs v0.4.21


How is the structure of a smart contract

Smart contracts are the basic unit of deployment and execution for EVMs. A contract contains state variables, functions, function modifiers, events, structures, and enums. Contracts also support inheritance. Inheritance is implemented by copying code at the time of compiling. Smart contracts also support polymorphism.

Every transaction on Ethereum Virtual Machine costs us some amount of Gas. The lower the Gas consumption the better is your Solidity code. The Gas consumption of Memory is not very significant as compared to the gas consumption of Storage. Therefore, it is always better to use Memory for intermediate calculations and store the final result in Storage.

State variables

The variable can be used at multiple places within code and they will all refer to the value stored within it. Solidity provides two types of variable: state and memory.

The default for function parameters (including return parameters of functions) is memory, the default for local variables is storage.

Storage

Persistent data is referred to as storage and is represented by state variables. These values get stored permanently on the blockchain. You need to declare the type so that the contract can keep track of how much storage on the blockchain it needs when it compiles.

Structure

Structures or structs helps implement custom user-defined data types. A structure is a composite data type, consisting of multiple variables of different data types. They are very similar to contracts; however, they do not contain any code within them. They consist of only variables.

Additional Information

ANATOMY OF SMART CONTRACTS by Ethereum.org


EVM – Ethereum Virtual Machine

Intro

Solidity is a programming language targeting Ethereum Virtual Machine (EVM). Ethereum blockchain helps extend its functionality by writing and executing code known as smart contracts. Ethereum Virtual Machines have been successfully implemented in various programming languages including C++, Java, JavaScript, Python, Ruby, and many others.

EVM executes code that is part of smart contracts. Smart contracts are written in Solidity; however, EVM does not understand the high-level constructs of Solidity. EVM understands lower-level instructions called bytecode. Solidity code needs a compiler to take its code and convert it into bytecode that is understandable by EVM.

For every instruction implemented on the EVM, a system that keeps track of execution cost, assigns to the instruction an associated cost in Gas units (See our What is Gas? article). When a user wants to initiate an execution, they reserve some Ether, which they are willing to pay for this gas cost.

In order to facilitate Keccak-256 cryptographic hash scheme, the EVM is a stack-based architecture with a word size of 256-bits. This architecture also allows for the use of elliptic-curve cryptography in Ethereum’s signature scheme for validating the origin and integrity of transactions.

EVM

Additional Information

ETHEREUM VIRTUAL MACHINE (EVM) by Ethereum.org