Import packages in Vyper 0.4.0
Vyper, a types of programming and staticly compiled for intelligent contracts based on solidity on the Ethereum blockchain, supports the import of bookstores and external modules using the `importing education '.
In this article, we will demonstrate how to import thesnekmatein Vyper version 0.4.0 package, focusing in particular on importing from the snekmate.tokens 'module'.
Education is imported
In Vyper, it is possible to useimport 'education to bring an external library or form within the contract. Here's how you can do it:
Python
from snekmate.tokens import ERC20 as a base_tken
Import of a function from the library
Def Get_snekmate_from_tokens ():
Return base_tokenc20 ()
`
In this example, we define a functionGET_SNEKMATE_FROM_TOKENS () which imports the contract ‘ERC20from the form
snekmate.takensand returns an application.
Import of multiple bookstores
To import multiple bookstores or modules, you can use the following syntax:
Python
from snekmate.takens import ERC20 as a base_token1
from snekmate.takens import ERC20 as a base_token2
Import of functions other than the library
Def Get_snekmate_from_tokens_1 ():
Return base_tken1er20 ()
Def Get_snekmate_from_tokens_2 ():
Return base_tken2erc20 ()
`
Import modules
To import a module, you must have it in the "Lib Libal project directory. In Vyper 0.4.0, the default position for modules is
Lib ‘. You can use the following syntax:
`Python
from snekmate.tokens import ERC20 as a base_tken
Import of a form from the bookcase
from snekmate.takens import ERC20, ERC721
Import of all functions and variables from the form
For the object in [ERC20, ERC721]:
Exec (f “import {item}”)
`
In this example, suppose that there is a packagesnekmatewith two modules:
takensand
utils. We import both modules using the syntax above.
Including packages in contracts
To include the packages in your contracts, you can simply add their directory to your listLibin the file 'Build_config.py' of Vyper. For example:
Python
Build_config.py
Lib = [
‘lib/snekmate’,
“
`
This tells Vyper to include thelib/snekmate” package during the compilation of contracts.
Conclusion
In this article, we have shown how to import external bookcases and modules in Vyper 0.4.0 using the `import 'and multiple imports. We also showed how to include the packages in your contracts by adding their directory to the list
Libin 'Build_config.py
.