Dependencies
Dependencies allow you to use code from other ingots in your project. Fe supports both local path dependencies and remote git dependencies.
The [dependencies] Section
Section titled “The [dependencies] Section”Add dependencies to your fe.toml:
[ingot]name = "my_project"version = "1.0.0"
[dependencies]utils = "../shared/utils"token_lib = { source = "https://github.com/example/token-lib.git", rev = "a1b2c3d4e5f6" }Local Path Dependencies
Section titled “Local Path Dependencies”Reference ingots on your local filesystem:
Simple Path Syntax
Section titled “Simple Path Syntax”[dependencies]my_lib = "../path/to/my_lib"Explicit Path Syntax
Section titled “Explicit Path Syntax”[dependencies]my_lib = { path = "../path/to/my_lib" }Both forms are equivalent. The path is relative to your project’s fe.toml.
Example: Monorepo Structure
Section titled “Example: Monorepo Structure”my-workspace/├── contracts/│ ├── fe.toml│ └── src/lib.fe└── shared/ ├── utils/ │ ├── fe.toml │ └── src/lib.fe └── types/ ├── fe.toml └── src/lib.fe[ingot]name = "contracts"version = "1.0.0"
[dependencies]utils = "../shared/utils"types = "../shared/types"Git Remote Dependencies
Section titled “Git Remote Dependencies”Pull ingots from git repositories:
[dependencies]token_lib = { source = "https://github.com/example/token-lib.git", rev = "abc1234" }Required Fields
Section titled “Required Fields”| Field | Description |
|---|---|
source | Git repository URL |
rev | Git commit hash (full or abbreviated) |
Note: Only commit hashes are supported for rev. Tags and branch names are not allowed because Fe does not yet support lock files. Pinning to exact commits ensures reproducible builds.
Optional Fields
Section titled “Optional Fields”| Field | Description |
|---|---|
path | Subdirectory within the repository containing the ingot |
Examples
Section titled “Examples”Pin to a specific commit:
[dependencies]lib = { source = "https://github.com/org/repo.git", rev = "a1b2c3d4" }Use a subdirectory in the repository:
[dependencies]contracts = { source = "https://github.com/org/monorepo.git", rev = "e7f8a9b0c1d2", path = "packages/contracts" }Using Dependencies
Section titled “Using Dependencies”Once declared, import from dependencies using their name:
// Import from the 'utils' dependencyuse utils::calculate_feeuse utils::SafeMath
// Import from the 'token_lib' dependencyuse token_lib::ERC20use token_lib::TransferThe dependency name in fe.toml becomes the root of the import path.
Dependency Names
Section titled “Dependency Names”The name you give a dependency determines its import path:
[dependencies]# This ingot is imported as 'helpers'helpers = "../some/path/to/utils"// Import using the name 'helpers', not the directory nameuse helpers::some_functionVersion Conflicts
Section titled “Version Conflicts”If two dependencies require different versions of the same ingot, you may encounter conflicts. Strategies to resolve:
- Update dependencies to use compatible versions
- Use path dependencies to control exact versions
- Contact dependency maintainers about version compatibility
Summary
Section titled “Summary”| Dependency Type | Syntax |
|---|---|
| Local (simple) | name = "path/to/ingot" |
| Local (explicit) | name = { path = "path/to/ingot" } |
| Git remote | name = { source = "url", rev = "ref" } |
| Git with path | name = { source = "url", rev = "ref", path = "subdir" } |