๐งช Usage Example: Local Test with Anvil
This guide walks you through a full example of using the Zaphenath CLI client in a local environment powered by Anvil. You'll create a key, test timeout behavior, and see the daemon in action with the CLI Client.
โ๏ธ 1. Start Anvil
Run Anvil with a fixed mnemonic and fast block time:
anvil --port 8545 \
--mnemonic "test test test test test test test test test test test junk" \
--block-time 1
๐ฆ 2. Deploy the Zaphenath Smart Contract
Export the default Anvil private key (auto-funded):
export TEST_PRIVKEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
Clone the contract repo and deploy it:
git clone https://github.com/Astervia/zaphenat.git
cd zaphenat
forge script script/Zaphenath.s.sol \
--broadcast \
--private-key $TEST_PRIVKEY \
--rpc-url http://localhost:8545
Extract the deployed contract address:
export CONTRACT_ADDRESS=$(jq -r \
'.transactions[] | select(.contractName=="Zaphenath") | .contractAddress' \
broadcast/Zaphenath.s.sol/31337/run-latest.json)
๐ 3. Save the Private Key (Optional)
To use with the CLI without re-passing it:
echo "$TEST_PRIVKEY" > ~/.zaphenathpkey
chmod 600 ~/.zaphenathpkey
๐๏ธ 4. Initialize the Local Configuration File
Zaphenath CLI uses a local config file to track keys, contract addresses, and network settings.
Initialize the config:
zaph config init
Optional: view the config content to confirm:
zaph config view
๐๏ธ 5. Create a Key On-Chain (with Small Timeout)
zaph contract create-key \
--key-id testkey \
--data deadbeefcafebabe \
--timeout 10 \
--gas-buffer 1.2 \
--contract-address $CONTRACT_ADDRESS \
--private-key-path ~/.zaphenathpkey \
--network anvil \
--rpc-url http://localhost:8545 \
-y
๐ 6. Try Reading Before Timeout (Should Fail)
zaph contract read-key \
--key-id testkey
Expect an error:
Data not available before timeout
โณ 7. Wait & Read After Timeout (Should Succeed)
Wait 10 seconds:
sleep 10
zaph contract read-key \
--key-id testkey
Expected output:
0xdeadbeefcafebabe
๐ 8. Start the Daemon
zaph daemon run \
--interval 5 \
--gas-buffer 1.2 \
-y
The daemon will keep the key "alive" by pinging it regularly.
๐ซ 9. Try Reading Again (Should Fail)
zaph contract read-key \
--key-id testkey
Expected:
Data not available before timeout
๐งฏ 10. Stop the Daemon
Use Ctrl+C to stop the daemon.
โ 11. Wait & Read Again (Should Succeed)
Wait another 10 seconds:
sleep 10
zaph contract read-key \
--key-id testkey
Expected:
0xdeadbeefcafebabe
โ Summary
| Step | Action | Expected Outcome |
|---|---|---|
| 1 | Start Anvil | Local testnet ready |
| 2 | Deploy contract | Contract deployed |
| 3 | Export key | Used for TX signing |
| 4 | Initialize config | Config file and key registered |
| 5 | Create key on-chain | Key created with timeout |
| 6 | Read immediately | โ Fails โ still within timeout |
| 7 | Read after timeout | โ Success |
| 8 | Start daemon | Key is pinged |
| 9 | Read while daemon active | โ Fails โ timeout keeps resetting |
| 10 | Stop daemon | Timer begins again |
| 11 | Read after inactivity | โ Success |