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!
Importing files ⚡️
You can either import files locally or externally. Below you can see the folder structure they were using ⬇️
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).
The second file (code below) contains the logic for importing Foo.sol. Try out yourself in your favorite IDE! 😊
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 ⬇️
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 ⬇️
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:
- Give me a follow here on Hashnode, Twitter, Medium, Instagram, TikTok or YouTube.
- Like the article
- 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