Skip to main content

createAgent() function

Helper function to create a new instance of the Agent class with correct type

Signature:

export declare function createAgent<T extends IPluginMethodMap, C = Record<string, any>>(
options: IAgentOptions & {
context?: C
},
): TAgent<T> & {
context?: C
}

Parameters

ParameterTypeDescription
optionsIAgentOptions & { context?: C; }Agent configuration options

Returns:

TAgent<T> & { context?: C; }

configured agent

Remarks

Use TAgent to configure agent type (list of available methods) for autocomplete in IDE

Example

import { createAgent, IResolver, IMessageHandler } from '@veramo/core'
import { AgentRestClient } from '@veramo/remote-client'
import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'
const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({
plugins: [
new CredentialIssuer(),
new AgentRestClient({
url: 'http://localhost:3002/agent',
enabledMethods: ['resolveDid', 'handleMessage'],
}),
],
})