Policy Playground
The Policy Playground is a hands-on example that demonstrates the SmartAgentKit plugin architecture. It is the recommended starting point for anyone looking to write custom policies or understand how the SDK's extensibility works.
What It Demonstrates
- Custom Plugin Definition — A
TargetBlockerPluginthat blocks calls to a specific address, implemented as a fullPolicyPluginobject. - Plugin Registration — Registering custom plugins with
pluginRegistryand querying the registry. - Config Validation — Runtime type checking before on-chain transactions.
- Init Data Encoding — Producing the
onInstallcalldata that matches a Solidity contract's decoder. - Address Resolution — Default addresses, per-chain overrides, and the resolution priority chain.
- Infrastructure Addresses — How
isInfrastructureplugins are automatically protected. - Mock Wallet Creation — Creating wallets with both built-in and custom policies using the mock client.
Quick Start
# Clone the repo
git clone https://github.com/smartagentkit/smartagentkit.git
cd smartagentkit
# Install and build
pnpm install && pnpm build
# Run the playground in mock mode (no RPC needed)
cd apps/examples/policy-playground
pnpm start:mockThe playground runs through 7 steps and prints the results of each operation. No chain connection, funding, or API keys required in mock mode.
Files
| File | Description |
|---|---|
src/custom-plugin.ts | Example PolicyPlugin<TargetBlockerConfig> implementation |
src/playground.ts | Main demo script that exercises the plugin API |
.env.example | Environment variables for live-chain mode |
What to Look At
Start with src/custom-plugin.ts to see how a plugin is defined:
export const targetBlockerPlugin: PolicyPlugin<TargetBlockerConfig> = {
id: "target-blocker",
name: "TargetBlockerHook",
moduleType: "hook",
isInfrastructure: false,
// ...
encodeInitData(config, trustedForwarder) { /* ... */ },
validateConfig(config) { /* ... */ },
toInstalledPolicy(config, moduleAddress) { /* ... */ },
};Then read src/playground.ts to see how the plugin is registered and used through the SDK.
Adapting for Your Own Policy
To use the playground as a starting point for your own policy:
- Copy
src/custom-plugin.tsand rename it (e.g.,src/my-policy-plugin.ts) - Change
id,name, and the config interface to match your policy - Update
encodeInitDatato produce the bytes your SolidityonInstallexpects - Update
validateConfigwith your own config checks - Import and register your plugin in
playground.tsinstead of the TargetBlockerPlugin - Run
pnpm start:mockto verify registration, validation, and encoding work
Once your plugin works in the playground, move on to writing the Solidity hook and deploying it. See the Custom Policies Guide for the full end-to-end walkthrough.
For Contributors
If you are thinking about contributing a new policy plugin, the playground is the fastest way to understand the full lifecycle:
- Run it to see how plugins work end-to-end
- Modify
custom-plugin.tsto experiment with your own config/encoding - When ready, follow the Custom Policies Guide to build a real Solidity hook + TypeScript plugin
Related
- Custom Policies Guide — Full walkthrough including Solidity contracts
- Policy Configuration — Built-in policy reference
- Policies API —
pluginRegistryandclient.policiesAPI reference