SOLIDITY - Importing files local/external, using libraries⛓

Topics: How to import files local/external, using libraries

Hello again to my channel! I am sure that you want to learn something about Solidity today? Yes? - good, let's have a look at how to import files local and external as well as how to use libraries. Solidity is still a safe bet to get into Web3 and Blockchain. All the information was derived from solidity-by-example. Big shout-out to the Team 🔥 Keep going with your great work! Let's jump in!

Solidity Basics Intro(1).png

Importing files ⚡️

You can either import files locally or externally. Below you can see the folder structure they were using ⬇️

Screenshot 2022-05-18 at 07.10.22.png

Below you can find the sample file Foo.sol. There is nothing complicated going on within the contract (declaration of variables, simple function, contract, error).

asdasdqasd.jpg

The second file (code below) contains the logic for importing Foo.sol. Try out yourself in your favorite IDE! 😊

asdawsd23.jpg

You can also import contracts from GitHub. This will be the case very often! I am using contracts from Chainlink for example. They have a lot of really helpful contracts. One example is a contract that allows you to get the actual exchange rate of ETH/USD. Below you can see an example of how to import contracts external ⬇️

sjkdynxf7384.jpg

Libraries ⚡️

They are pretty similar to contracts. However, you can declare any state variable but you can't send ether. It is important to keep in mind that a library must be deployed and linked before the contract is deployed if the library is not embedded into the contract. Below you can find an example using libraries in Solidity ⬇️

asdq3d.jpg

asdqwsd98.jpg

That's it for today! Have fun trying out the sample code yourself! Everything you are learning from scratch might be quite hard in the beginning but you will earn the rewards in the future! 🚀

Thanks for reading this article! If you want to support me you can do it as follows:

  1. Give me a follow here on Hashnode, Twitter, Medium, Instagram, TikTok or YouTube.
  2. Like the article
  3. Leave a short comment
 I really appreciate every kind of support! Every interaction you are doing with the content will help me grow and deliver better content with time. 🚀

Thank you, 
VEGXCODES