Skip to main content

Agent class

Provides a common context for all plugin methods.

This is the main entry point into the API of Veramo. When plugins are installed, they extend the API of the agent and the methods they provide can all use the common context so that plugins can build on top of each other and create a richer experience.

Signature:

export declare class Agent implements IAgent

Implements: IAgent

Constructors

ConstructorModifiersDescription
(constructor)(options)Constructs a new instance of the Agent class

Properties

PropertyModifiersTypeDescription
context?readonlyRecord<string, any>(Optional)
methodsreadonlyIPluginMethodMapThe map of plugin + override methods

Methods

MethodModifiersDescription
availableMethods()Lists available agent method names
emit(eventType, data)

Broadcasts an Event to potential listeners.

Listeners are IEventListener instances that declare eventTypes and implement an async onEvent({type, data}, context) method. Note that IAgentPlugin is also an IEventListener so plugins can be listeners for events.

During creation, the agent automatically registers listener plugins to the eventTypes that they declare.

Events are processed asynchronously, so the general pattern to be used is fire-and-forget. Ex: agent.emit('foo', {eventData})

In situations where you need to make sure that all events in the queue have been exhausted, the Promise returned by emit can be awaited. Ex: await agent.emit('foo', {eventData})

In case an error is thrown while processing an event, the error is re-emitted as an event of type CoreEvents.error with a EventListenerError as payload.

Note that await agent.emit() will NOT throw an error. To process errors, use a listener with eventTypes: [ CoreEvents.error ] in the definition.

execute(method, args)

Executes a plugin method.

Normally, the execute() method need not be called. The agent will expose the plugin methods directly on the agent instance but this can be used when dynamically deciding which methods to call.

getSchema()Returns agent plugin schema