API Reference

The core methods and types available on the zapChain plugin instance.

Plugin Setup

constructor(config?)

new ZapChainPlugin(config?: ZapChainConfig)

Initializes a new instance of the ZapChain automation plugin.

Parameters
config.storageStorageAdapter
Persistence layer (e.g., LocalStorageAdapter). Default: InMemory.
config.pollIntervalnumber
Global polling interval in ms. Default: 12000 (12s).
config.enableLoggingboolean
Enable verbose console logs. Default: false.
config.useWebSocketbooleanv2.0
Enable WebSocket subscriptions for real-time block monitoring. Falls back to polling if unavailable. Default: false.

Rule Management

createRule(rule)

createRule(rule: Partial<RuleDefinition>): Promise<string>

Creates and registers a new automation rule. Automatically detects connected wallet if metadata.createdBy is missing.

Parameters
ruleRuleDefinition
The complete rule object including conditions and actions.
Returns
Promise<string>
The unique ID of the created rule.

enableRule(ruleId)

enableRule(ruleId: string): Promise<void>

Activates a rule. The engine will immediately start monitoring for trigger conditions.

disableRule(ruleId)

disableRule(ruleId: string): Promise<void>

Deactivates a rule. It will simply be ignored by the engine loop.

deleteRule(ruleId)

deleteRule(ruleId: string): Promise<void>

Permanently removes a rule from storage and stops its execution.

listRules()

listRules(): Promise<RuleInfo[]>

Returns a list of all rules (active and disabled) currently managed by the plugin.

getRule(ruleId)

getRule(ruleId: string): Promise<RuleDefinition | undefined>

Retrieves the full definition of a specific rule.

Execution & Safety

getExecutionLogs(ruleId?)

getExecutionLogs(ruleId?: string): ExecutionLog[]

Returns the history of rule executions. Useful for debugging or UI history.

Parameters
ruleIdstring
(Optional) Filter logs by a specific Rule ID.

simulateRule(ruleId)

simulateRule(ruleId: string): Promise<SimulationResult>

simulateRule(ruleId)

simulateRule(ruleId: string): Promise<SimulationResult>

Runs an internal simulation using eth_call for all contract actions in the rule. Returns gas estimates and potential revert reasons without broadcasting a transaction.

setKillSwitch(enabled)

setKillSwitch(enabled: boolean): Promise<void>

Emergency Stop. Globally pauses ALL rule executions when set to true.

isKillSwitchActive()

isKillSwitchActive(): boolean

Returns the current status of the emergency kill-switch.

Condition Types

balance

Triggers based on wallet balance changes.

tokenAddress
0x0 for ETH, or ERC20 contract address.
operator
>, <, ==, >=, <=.
value
Amount in Wei (use web3.utils.toWei).

gas_price

Triggers when network gas price meets a target.

operator
Comparison operator.
value
Gas price in Gwei.

Action Types

contract_call

Executes a smart contract transaction.

contractAddress
Target contract address.
functionName
Name of function to call.
abi
Contract ABI (minimal for the function).
args
Function arguments array.
value
ETH to send in wei (optional).

native_transfer v2.0

Send ETH/MATIC directly to any address without requiring a contract ABI. Perfect for simple transfers, auto-sweeping, and tipping.

to
Recipient address (EOA or contract).
value
Amount to send in wei.
gasLimit
Optional gas limit (default: 21000 for EOA).
// Example: Auto-sweep to cold wallet
{
  type: 'native_transfer',
  to: '0xColdWallet...',
  value: web3.utils.toWei('1', 'ether')
}

notification

Send HTTP webhook notifications.

webhookUrl
HTTPS endpoint URL.
method
POST or GET.
payload
JSON body to send.
headers
Optional HTTP headers.

Execution Logging v2.0 Enhanced

ExecutionLog

Every rule execution is logged with detailed status information for debugging.

status
SUCCESS | FAILED | SKIPPED
skipReason
Why the rule was skipped (if status is SKIPPED):
  • KILL_SWITCH_ACTIVE
  • COOLDOWN_ACTIVE
  • MAX_EXECUTIONS_REACHED
  • SIGNATURE_INVALID
  • SIMULATION_FAILED
  • CONDITIONS_NOT_MET

Per-Rule Configuration v2.0

RuleConfig.pollInterval

Override the global polling interval for individual rules. Useful for time-sensitive conditions.

// Gas price monitoring every 1 second
config: {
  pollInterval: 1000,  // Override global 12s
  simulateFirst: true
}