fdev
The Freenet Development Tool (fdev) is a command-line utility to create, build, publish, inspect, and test Freenet contracts or delegates. It also supports local node simulations, a TUI-based WASM runtime, and optional network metrics gathering.
Table of Contents
- Overview
- Installation
- Local Node Example
- Creating a New Package
- Building a Contract or Delegate
- Publishing a Contract or Delegate
- Updating a Contract
- Contract State Builder Example
- Inspecting a Compiled WASM
- Using the Local WASM Runtime (TUI)
- Querying Connected Peers
- Testing (Single-Process or Multi-Process)
- Network Metrics Server
- Directory & Module Structure
- Common Workflows
Overview
fdev helps Freenet developers:
- Create new contract or web-app packages.
- Build Rust-based WASM contracts/delegates.
- Publish new contracts or delegates.
- Update existing contracts’ state.
- Inspect compiled artifacts (hash, version, etc.).
- Run local TUI-based or multi-process network simulations.
- Query your node for connected peers.
- Optionally run a metrics server for simulation insights.
Installation
Usually you'll build fdev as part of the Freenet project:
- Clone or be inside the Freenet repository.
- Navigate to
freenet-core/main/crates/fdev. - Build in release mode:
- You can then run it directly:
Or placetarget/release/fdevon your PATH.
Local Node Example
If you want to try out a contract in local mode, you typically run a separate “local node” process that listens for contract commands. There is a local-node executable (or an equivalent) in the Freenet repository. You can do something like:
# Example: run the local node (CLI options may vary)
Once the local node is up, you can run fdev or a script to send commands to it.
Below is a legacy style example (paths/names may differ in current code):
# Example: older usage for local node exploration
In newer code, you will likely use fdev wasm-runtime, described in a later section, to do an equivalent local testing workflow.
Creating a New Package
fdev new scaffolds a new Freenet package. Two options:
contract: A standard WASM contract.webapp: A contract container that also bundles a front-end (TypeScript/webpack by default).
Example:
Generates Rust cargo boilerplate (and for web apps, TypeScript/webpack scaffolding too).
Building a Contract or Delegate
Use fdev build to compile a Rust-based WASM contract or delegate. For example:
--package-typedefaults tocontract.--featurescan specify crate features, e.g.freenet-main-contractorfreenet-main-delegate.--debugproduces an unoptimized WASM (useful for local tests).--versionsets the embedded Freenet ABI version (defaults to0.0.1).
fdev looks for a freenet.toml in your current directory that defines if your contract is standard or a webapp, and (for webapps) how to compile front-end code.
After building, the output artifact is typically placed in build/freenet/ unless overridden by your config file.
Publishing a Contract or Delegate
fdev publish uploads a new contract or delegate to a node (either local or network mode).
Example: Publishing a contract:
--code: path to your built WASM.--parameters: optional contract parameters file (typically binary format).--state: optional initial state file (typically binary format).
Example: Publishing a webapp contract with pre-compressed archive:
# First compress your webapp directory
|
# Then publish the webapp contract
--webapp-archive: path to your xz-compressed tar archive containing the webapp files. The archive should contain an index.html file at the root level.--webapp-metadata: optional path to metadata file for the webapp (can be any binary format).
This alternative to the TypeScript/webpack build process allows you to provide your own pre-compressed webapp archive.
Example: Publishing a delegate:
- If you skip
--nonceand--cipher, a default local-only encryption is used (fine for tests, not recommended for production).
By default, fdev publish pushes in local mode unless you specify --mode network or set MODE=network.
Updating a Contract
To push a state delta to an existing contract (identified by its Base58 key):
--delta: The state delta file (JSON or binary).--releaseindicates you want to push to the network, instead of local-only.
Contract State Builder Example
Sometimes you only want to build the “state artifact” for a contract or a web front-end. fdev build can do this if your freenet.toml includes a state-sources or webapp config.
Older Freenet docs mention build_state as a separate script, but in practice you can do:
# Build a web-based front end
Similarly, you can specify --state for a model-only contract:
(Adjust paths, actual flags, and config to match your usage.)
Inspecting a Compiled WASM
fdev inspect prints metadata about a built WASM artifact, such as its hash, version, or a derived contract key.
Examples:
# Show code hash + contract API version
# Display the contract key (hash+empty params => key)
# For a delegate
Using the Local WASM Runtime (TUI)
fdev wasm-runtime provides a local, interactive environment to test your contract. For instance:
- The tool will connect to a local Freenet node by default (see
--mode,--address,--portif needed). - Commands you type—like
put,get,update, orexit—are forwarded to the local node. - Additional command data is read from the file specified by
--input-file.
Common subcommands once inside the TUI:
help # print instructions
put # publish a fresh contract state
get # retrieve the current contract state
update # apply a delta to the contract state
exit # quit TUI
Querying Connected Peers
You can list a node’s open connections:
It prints a table of peer identifiers and socket addresses for debugging or analysis.
Testing (Single-Process or Multi-Process)
fdev test orchestrates an entire simulated network of Freenet nodes for end-to-end testing.
Single Process
Spins up multiple in-memory nodes under one process:
- --gateways: number of gateway nodes
- --nodes: number of normal nodes
- --events: random events (contract puts, updates, etc.)
Multi-Process
- One node acts as a supervisor (you run
fdev test ... network --mode supervisor). - Others run as peers (
--mode peer) connecting to the supervisor. This can scale across multiple machines or containers.
(See internal documentation or run fdev test --help for more detail.)
Network Metrics Server
- Launches an HTTP server (default port
55010) for collecting or pushing network stats and event logs. - You can then visualize or store the data for debugging or simulation metrics analysis.
Directory & Module Structure
Here’s a quick look at the major modules in the fdev crate:
fdev
├── src
│ ├── main.rs # CLI entrypoint, top-level subcommands
│ ├── config.rs # Config structs, subcommand definitions
│ ├── commands/ # 'put', 'update', connect to node, etc.
│ ├── build.rs # Builds Rust WASM, web assets, etc.
│ ├── wasm_runtime/ # Local TUI runtime for testing contracts
│ ├── testing/ # Tools for single vs multi-process simulations
│ ├── network_metrics_server # Optional server for collecting network stats
│ └── util.rs # Shared utility helpers
└── Cargo.toml
Common Workflows
Below are a few typical steps you might perform:
- Create a new contract (or webapp):
- Build:
- Publish (locally by default):
- Update the contract:
- Inspect a compiled WASM:
- Run local TUI (optionally):
- Check open peers:
- Simulate a small test network:
- (Optional) Start metrics server:
Feel free to run fdev <subcommand> --help for more details on any step. Enjoy building with Freenet!Below is a comprehensive README for fdev that combines the existing reference documentation and the original README content. You can drop it in place of your current README.md.
fdev
The Freenet Development Tool (fdev) is a command-line utility to create, build, publish, inspect, and test Freenet contracts or delegates. It also supports local node simulations, a TUI-based WASM runtime, and optional network metrics gathering.
Table of Contents
- Overview
- Installation
- Local Node Example
- Creating a New Package
- Building a Contract or Delegate
- Publishing a Contract or Delegate
- Updating a Contract
- Contract State Builder Example
- Inspecting a Compiled WASM
- Using the Local WASM Runtime (TUI)
- Querying Connected Peers
- Testing (Single-Process or Multi-Process)
- Network Metrics Server
- Directory & Module Structure
- Common Workflows
Overview
fdev helps Freenet developers:
- Create new contract or web-app packages.
- Build Rust-based WASM contracts/delegates.
- Publish new contracts or delegates.
- Update existing contracts’ state.
- Inspect compiled artifacts (hash, version, etc.).
- Run local TUI-based or multi-process network simulations.
- Query your node for connected peers.
- Optionally run a metrics server for simulation insights.
Installation
Usually you'll build fdev as part of the Freenet project:
- Clone or be inside the Freenet repository.
- Navigate to
freenet-core/main/crates/fdev. - Build in release mode:
- You can then run it directly:
Or placetarget/release/fdevon your PATH.
Local Node Example
If you want to try out a contract in local mode, you typically run a separate “local node” process that listens for contract commands. There is a local-node executable (or an equivalent) in the Freenet repository. You can do something like:
# Example: run the local node (CLI options may vary)
Once the local node is up, you can run fdev or a script to send commands to it.
Below is a legacy style example (paths/names may differ in current code):
# Example: older usage for local node exploration
In newer code, you will likely use fdev wasm-runtime, described in a later section, to do an equivalent local testing workflow.
Creating a New Package
fdev new scaffolds a new Freenet package. Two options:
contract: A standard WASM contract.webapp: A contract container that also bundles a front-end (TypeScript/webpack by default).
Example:
Generates Rust cargo boilerplate (and for web apps, TypeScript/webpack scaffolding too).
Building a Contract or Delegate
Use fdev build to compile a Rust-based WASM contract or delegate. For example:
--package-typedefaults tocontract.--featurescan specify crate features, e.g.freenet-main-contractorfreenet-main-delegate.--debugproduces an unoptimized WASM (useful for local tests).--versionsets the embedded Freenet ABI version (defaults to0.0.1).
fdev looks for a freenet.toml in your current directory that defines if your contract is standard or a webapp, and (for webapps) how to compile front-end code.
After building, the output artifact is typically placed in build/freenet/ unless overridden by your config file.
Publishing a Contract or Delegate
fdev publish uploads a new contract or delegate to a node (either local or network mode).
Example: Publishing a contract:
--code: path to your built WASM.--parameters: optional contract parameters.--state: optional initial state JSON or binary.
Example: Publishing a delegate:
- If you skip
--nonceand--cipher, a default local-only encryption is used (fine for tests, not recommended for production).
By default, fdev publish pushes in local mode unless you specify --mode network or set MODE=network.
Updating a Contract
To push a state delta to an existing contract (identified by its Base58 key):
--delta: The state delta file (JSON or binary).--releaseindicates you want to push to the network, instead of local-only.
Contract State Builder Example
Sometimes you only want to build the “state artifact” for a contract or a web front-end. fdev build can do this if your freenet.toml includes a state-sources or webapp config.
Older Freenet docs mention build_state as a separate script, but in practice you can do:
# Build a web-based front end
Similarly, you can specify --state for a model-only contract:
(Adjust paths, actual flags, and config to match your usage.)
Inspecting a Compiled WASM
fdev inspect prints metadata about a built WASM artifact, such as its hash, version, or a derived contract key.
Examples:
# Show code hash + contract API version
# Display the contract key (hash+empty params => key)
# For a delegate
Using the Local WASM Runtime (TUI)
fdev wasm-runtime provides a local, interactive environment to test your contract. For instance:
- The tool will connect to a local Freenet node by default (see
--mode,--address,--portif needed). - Commands you type—like
put,get,update, orexit—are forwarded to the local node. - Additional command data is read from the file specified by
--input-file.
Common subcommands once inside the TUI:
help # print instructions
put # publish a fresh contract state
get # retrieve the current contract state
update # apply a delta to the contract state
exit # quit TUI
Querying Connected Peers
You can list a node’s open connections:
It prints a table of peer identifiers and socket addresses for debugging or analysis.
Testing (Single-Process or Multi-Process)
fdev test orchestrates an entire simulated network of Freenet nodes for end-to-end testing.
Single Process
Spins up multiple in-memory nodes under one process:
- --gateways: number of gateway nodes
- --nodes: number of normal nodes
- --events: random events (contract puts, updates, etc.)
Multi-Process
- One node acts as a supervisor (you run
fdev test ... network --mode supervisor). - Others run as peers (
--mode peer) connecting to the supervisor. This can scale across multiple machines or containers.
(See internal documentation or run fdev test --help for more detail.)
Network Metrics Server
- Launches an HTTP server (default port
55010) for collecting or pushing network stats and event logs. - You can then visualize or store the data for debugging or simulation metrics analysis.
Directory & Module Structure
Here’s a quick look at the major modules in the fdev crate:
fdev
├── src
│ ├── main.rs # CLI entrypoint, top-level subcommands
│ ├── config.rs # Config structs, subcommand definitions
│ ├── commands/ # 'put', 'update', connect to node, etc.
│ ├── build.rs # Builds Rust WASM, web assets, etc.
│ ├── wasm_runtime/ # Local TUI runtime for testing contracts
│ ├── testing/ # Tools for single vs multi-process simulations
│ ├── network_metrics_server # Optional server for collecting network stats
│ └── util.rs # Shared utility helpers
└── Cargo.toml
Common Workflows
Below are a few typical steps you might perform:
- Create a new contract (or webapp):
- Build:
- Publish (locally by default):
- Update the contract:
- Inspect a compiled WASM:
- Run local TUI (optionally):
- Check open peers:
- Simulate a small test network:
- (Optional) Start metrics server:
Feel free to run fdev <subcommand> --help for more details on any step. Enjoy building with Freenet!