Complete guide to abikit's artifact caching feature for faster builds and offline development
Artifact Caching
abikit's artifact caching feature allows you to copy your contract artifacts (e.g., .json files from Foundry's out directory or Hardhat's artifacts directory) to a local, managed cache directory. This can significantly speed up subsequent SDK generation builds, enable offline development, and ensure consistent builds across different environments.
How it Works
When artifact caching is enabled (mode: copy), abikit will:
- Copy Artifacts: During the
abikit buildprocess, it will copy the.jsonartifact files for all contracts defined in yourcontracts.yamlfrom their source directories (e.g.,foundryOut) to a specified local cache directory (e.g.,artifacts/). - Hash Tracking: It tracks a hash of the source artifact directory. If
copyOnBuildisfalse(the default), artifacts are only re-copied if the source directory's hash changes, preventing unnecessary file operations. - Prioritized Resolution: When
abikitneeds to load an artifact, it first checks the cache. If the artifact is found in the cache, it's loaded from there, bypassing the potentially slower process of resolving from source directories.
Configuration
To enable artifact caching, add an artifactSources.cache section to your contracts.yaml:
artifactSources:
defaults:
foundryOut: ../smart-contracts/out # Path to your Foundry 'out' directory
cache:
mode: copy # Required: Set to 'copy' to enable artifact caching
dir: artifacts # Optional: Directory where artifacts will be cached (default: 'artifacts' relative to config)
copyOnBuild: false # Optional: Set to true to force copying on every build, even if source is unchanged.
# Default is false, which optimizes by only copying when source artifacts change.
contracts:
MyContract: {}
AnotherContract: {}
generation:
targets:
- language: typescript
framework: viem
outDir: ./sdk/ts
- language: python
framework: web3py
outDir: ./sdk/py
mode: copy
This is the primary setting to enable artifact caching. When set to copy, abikit will manage a local copy of your artifacts.
dir: <path>
Specifies the directory where the artifacts will be copied. This path is relative to your contracts.yaml file. If not specified, it defaults to artifacts/.
copyOnBuild: <boolean>
false(default): Artifacts are only copied to the cache if the source artifacts have changed since the last build. This is the recommended setting for most workflows as it optimizes build times.true: Artifacts are copied to the cache on everyabikit buildcommand, regardless of whether the source has changed. Use this if you need to ensure the cache is always refreshed, even for minor, untracked changes.
CLI Commands for Cache Management
abikit provides dedicated commands to manage your artifact cache:
abikit cache stats [config]
Displays statistics about the current artifact cache, including:
- The cache directory path.
- The number of cached artifacts.
- The timestamp of the last cache operation.
abikit cache stats
# Example output:
# 📊 Cache statistics...
# ✅ Cached 2 artifacts to /path/to/your/project/artifacts
# ⏰ Last Cache Time: 10/26/2025, 10:30:00 AM
abikit cache clear [config]
Removes all cached artifacts and the cache directory itself. This is useful for cleaning up your environment or forcing a complete re-copy of artifacts.
abikit cache clear
# Example output:
# 🗑️ Clearing artifact cache...
# ✅ Artifact cache cleared
Benefits of Artifact Caching
- Faster Builds: By loading artifacts from a local, optimized cache, abikit can bypass potentially slow file system scans of large
outorartifactsdirectories, leading to quicker SDK generation. - Offline Development: Once artifacts are cached, you can continue generating SDKs even if your original smart contract project's build output is unavailable or if you're working offline.
- Consistent Builds: Ensures that all team members or CI/CD pipelines use the exact same set of artifacts, reducing "it works on my machine" issues.
- CI/CD Optimization: In continuous integration/continuous deployment pipelines, caching artifacts can significantly reduce build times by allowing subsequent builds to reuse previously copied artifacts.
Integration with abikit build
When artifactSources.cache.mode: copy is enabled, the abikit build command automatically handles the caching process:
- It checks if artifacts need to be copied (based on
copyOnBuildand source hash). - If copying is needed, it performs the copy operation.
- It then proceeds with the SDK generation using either the cached or newly copied artifacts.
Best Practices
Development Workflow
- Enable caching in your
contracts.yamlfor faster iteration - Use
copyOnBuild: falsefor optimal performance (default) - Clear cache when switching between different contract versions or branches
- Commit cache directory to version control for team consistency (optional)
CI/CD Integration
- Pre-cache artifacts in your CI pipeline before running
abikit build - Use
copyOnBuild: truein CI to ensure fresh artifacts on every build - Cache the cache directory in your CI system for faster subsequent builds
Team Collaboration
- Share cache directory via version control for consistent builds across team members
- Document cache settings in your project README
- Use consistent paths for cache directories across different environments
Troubleshooting
Cache Not Working
- Verify that
artifactSources.cache.modeis set tocopy - Check that the cache directory path is correct and writable
- Run
abikit cache statsto see current cache status
Stale Artifacts
- Use
abikit cache clearto force a fresh copy of artifacts - Set
copyOnBuild: trueto always copy artifacts on every build - Check that your source artifact directories are up to date
Performance Issues
- Ensure
copyOnBuild: falsefor optimal performance (default) - Use relative paths for cache directories
- Consider using faster storage for cache directories
Next Steps
- Learn about Configuration options
- Check out the CLI Reference for all commands
- See Getting Started for quick setup