fuzd
Run the fuzd server as a node process, on a libsql database.
npx fuzd --port 34002 --chain "31337=http://127.0.0.1:8555#finality=1&worstCaseBlockTime=2" --mnemonic "<mnemonic>"
With no --db it runs on :memory:: the database is created and set up at start, and lost when the process stops. No chain is served unless one is given.
For a local dev node, give the chain by its RPC URL alone and fuzd reads its id from the node (see A local dev chain):
npx fuzd --port 34002 --chain "http://127.0.0.1:8545#finality=1&worstCaseBlockTime=2" --mnemonic "<mnemonic>"
Options
Every option falls back to an environment variable, which the process env or a .env / .env.local file in the working directory may set (then .env.default shipped with the package). A flag overrides its variable.
| flag |
env |
default |
|
-p, --port <port> |
|
3000 |
port to listen on |
-d, --db <url> |
DB |
:memory: |
libsql database url (:memory:, file:./fuzd.db, a remote url); :memory: and file: ones are set up at start (the setup is idempotent), a remote one through /admin/setup |
-c, --chain <chainId>=<rpc> |
CHAIN_<chainId> |
none |
a chain to serve, repeatable; the rpc may end with #finality=<blocks>&worstCaseBlockTime=<seconds>&protocol=<ethereum\|starknet> (defaults 12, 15, ethereum) |
-c, --chain <rpc> |
CHAIN_FROM_NODE |
none |
one ethereum chain given by its http(s) rpc alone (same suffix): its id is read from the node, see A local dev chain |
-m, --mnemonic <mnemonic> |
HD_MNEMONIC |
the test ... junk mnemonic, from .env.default |
the remote accounts are derived from it |
--admin-token <token> |
TOKEN_ADMIN |
none: the admin routes are closed |
password of the admin routes (user admin) |
--time-lock-decryption <true\|false> |
TIME_LOCK_DECRYPTION |
true |
decrypt time-locked executions with drand mainnet |
--payment-account <address> |
PAYMENT_ACCOUNT |
none |
account whose remote account covers a gas price above what an execution authorised |
--contract-timestamp <address> |
CONTRACT_TIMESTAMP |
none |
contract the chain time is read from, instead of the latest block |
--dev |
DEV |
off |
enable the development routes, like /admin/setChainOverride (which also needs the admin token); --dev sets DEV=true, the only value that enables them |
-i, --process-interval <seconds> |
|
1 |
seconds between two runs of the queue, the transactions and the status checks when the last run found nothing more to do (during a burst they run back to back); 0 disables it |
The default mnemonic (from .env.default) is public: it is meant for a local chain only. Give your own for anything else.
# the same configuration from the environment
DB=:memory: CHAIN_31337="http://127.0.0.1:8555#finality=1&worstCaseBlockTime=2" HD_MNEMONIC="<mnemonic>" npx fuzd --port 34002
A local dev chain
A chain given by its RPC URL alone (--chain <rpc>, or CHAIN_FROM_NODE=<rpc>) is served under the id its node reports with eth_chainId, so a dev stack whose chain id is chosen at start (or is simply whatever the node says) passes only the URL. At most one chain is given this way; <chainId>=<rpc> chains may sit beside it, and one for the same id wins over it.
- At start fuzd waits for the node (it asks every second, and says so every 10 seconds) and opens its port only once it knows the id, so a dev stack may start fuzd beside the node.
- While fuzd runs it checks the node's identity (its id and block 0's hash) every 2 seconds. When the node is replaced by another chain (a new id, or the same id with a new block 0, which every hardhat restart and every fresh anvil is), what fuzd holds for the old chain is wrong: its broadcaster nonces are ahead of the new chain's, so its transactions would never be mined. fuzd then stops processing, forgets everything it held for the old chain id (scheduled and broadcast executions, archives, broadcaster nonces and debts, gas configuration), serves the new id, and resumes. The same chain restarted from its state (same id, same block 0) changes nothing, and a node that does not answer for a while changes nothing either.
- The identity is not stored in the database: a
file: database reused by a new fuzd process against a reset chain is not detected. Keep one database per chain (a dev tool's per-chain state directory, for example).
- Two anvil nodes started fresh on the same id within the same second have the same block 0 (it differs only by its start time), so they are one identity to fuzd.
Several processes on one database
Several fuzd processes may share one database (a file: or remote libsql url) to process more at once: each run claims the due items it processes, so two processes never handle the same one, and the items of a process that died come back after the lease (PROCESSING_LEASE_DURATION_MS, 2 minutes by default). See docs/adr/0004-claim-due-items-with-a-lease.md. After upgrading, a remote database needs /admin/setup once (it adds the claim columns); :memory: and file: ones are set up at every start.
Develop
pnpm build
pnpm test # spawns the built CLI on free ports, and anvil (foundry, on PATH) on two free ports, or the two FUZD_TEST_ANVIL_PORTS gives (e.g. `8660,8661`)