Forc has a dependency management system which can pull packages using git
, ipfs
, path
, or the community registry
. This allows users to build and share Forc libraries.
You can add dependencies manually in your Forc.toml
, or by using the forc add
command.
forc add
The forc add
CLI supports various sources and optional flags:
forc add <dep> [--path <PATH>] [--git <URL> --tag <TAG>] [--ipfs <CID>] [--contract-dep]
From a Git branch:
forc add custom_lib --git https://github.com/FuelLabs/custom_lib --branch master
From a local path:
forc add custom_lib --path ../custom_lib
From IPFS:
forc add custom_lib --ipfs QmYwAPJzv5CZsnA...
From registry (forc.pub):
forc add custom_lib@0.0.1
Add as a contract dependency:
forc add my_contract --git https://github.com/example/contract --contract-dep
Optional:
--salt <HEX>
for custom contract salt. --package <NAME>
to target a specific package in a workspace. --manifest-path <PATH>
to specify a manifest file. ⚠️ Note: We do not currently support offline mode for projects that use registry sources. Also wildcard declarations
(ex: custom_lib = *)
to get the latest version available for that package or caret declarations(ex: custom_lib = ^0.1)
to getSemVer
compatible latest available option for a given dependency is not supported yet.
Once the package is added, running forc build
will automatically fetch and resolve the dependencies.
Forc.toml
If your Forc.toml
doesn't already have a [dependencies]
or [contract-dependencies]
table, add one. Below, list the package name and its source.
[dependencies]
custom_lib = { path = "../custom_lib" }
[dependencies]
custom_lib = { ipfs = "QmYwAPJzv5CZsnA..." }
[dependencies]
custom_lib = "0.0.1"
You can remove one or more dependencies using the forc remove
command:
forc remove <dep> [--contract-dep] [--package <NAME>] [--manifest-path <PATH>]
Remove from [dependencies]
:
forc remove custom_lib
Remove from [contract-dependencies]
:
forc remove my_contract --contract-dep
Target a specific package in a workspace:
forc remove custom_lib --package my_project
To update dependencies in your Forc directory you can run:
forc update
For path and ipfs dependencies this will have no effect. For git dependencies with a branch reference, this will update the project to use the latest commit for the given branch.