Libraries
import declaration allows to use functions, services and data types defined in another module on the file system. While it's a very simple mechanic, together with NPM flexibility it enables full-blown package management in Aqua.
Available Aqua Libraries
- Builtin services API: @fluencelabs/aqua-lib (see on NPM)
- Registry: @fluencelabs/registry (see on NPM)
- IPFS API: @fluencelabs/aqua-ipfs (see on NPM)
How To Use Aqua Libraries
To use a library, you need to download it by adding the library to dependencies in package.json and then running npm install.
If you're not familiar with NPM, package.json is a project definition file. You can specify dependencies to be downloaded from npm and define custom commands (scripts), which can be executed from the command line, e.g. npm run compile-aqua.
To create an NPM project, run npm initin a directory of your choice and follow the instructions.
Here's an example of adding aqua-lib to package.json dependencies:
json
json
After running npm i, you will have @fluencelabs/aqua-lib in node_modules
In Aqua
After the library is downloaded, you can import it in your .aqua script as documented in Imports And Exports:
typescript
typescript
Check out corresponding pages for the API of available libraries.
In TypeScript and JavaScript
To execute Aqua functions, you need to be connected to the Fluence network. The easiest way is to add JS SDK to dependencies:
json
json
After executing npm install, the Aqua API is ready to use. Now you need to export registry functions to TypeScript, that's easy. Create a file export.aqua:
aqua
aqua
Now, install Aqua compiler and compile your Aqua code to TypeScript:
sh
sh
That's it. Now let's call some functions on the Registry service:
typescript
typescript