Skip to main content
Version: v0.4.x

Agent Setup

info

This guide assumes you have followed the Prerequisites, and you have a valid Node.JS or React Native project setup.

caution

Aries Framework JavaScript is still in active development, and as such some APIs are still experimental. When using any experimental features, make sure to use an exact version of AFJ (0.4.0) instead of a range (^0.4.0), to prevent accidental breaking changes. If you're not leveraging any experimental features, you can use a range (^0.4.0) to get the latest bugfixes and features.

For AFJ 0.4.x, the following features are experimental:

  • Implementing your own AnonCredsRegistry and AnonCreds service implementation.
  • Using the shared component libraries from @aries-framework/aries-askar, @aries-framework/indy-vdr and @aries-framework/anoncreds-rs
  • Using OpenID4VC from the @aries-framework/openid4vc-client module
  • W3C JWT Verifiable Credentials
  • Using multi-tenancy from the @aries-framework/tenants module
  • Using BBS+ Signatures from the @aries-framework/bbs-signatures module
  • Using the cheqd module from the @aries-framework/cheqd module

Installing the required dependencies

First we have to install the minimal amount of dependencies that are required for configuring an Aries Framework JavaScript (AFJ) agent.

yarn add @aries-framework/core@^0.4.0 @aries-framework/node@^0.4.0

Additional setup

No additional setup is required for Node.JS

Setting up the agent

this section does not assume any knowledge of the agent configuration. In the Agent Config tutorial we will discuss in-depth what every field in the configuration does and when to set it.

In order to use the agent in the application we have to configure and initialize it. This following configuration is quite generic and possibly not enough for your specific use cases. Please refer to the tutorials for a more use-case-specific agent setup.

import type { InitConfig } from '@aries-framework/core'
import { Agent } from '@aries-framework/core'
import { agentDependencies } from '@aries-framework/node'

const config: InitConfig = {
label: 'docs-agent-nodejs',
walletConfig: {
id: 'wallet-id',
key: 'testkey0000000000000000000000000',
},
}

const agent = new Agent({
config,
dependencies: agentDependencies,
})

Adding a wallet and storage implementation

After creating the Agent instance, we need to provide the agent with a wallet and storage implementation. AFJ provides a few implementations out of the box, but you can also implement your own. Currently the following Wallet and Storage implementations are supported out of the box. Follow the specific guides to set up the wallet and storage implementation of your choice.

Setting up the transports

Finally, we have to set an outbound transport that will handle traffic from the agent. It is also possible to set an inbound transport in the same way as the outbound transport.

Sets up an WS outbound and HTTP inbound and outbound transport.

import { HttpOutboundTransport, WsOutboundTransport } from '@aries-framework/core'
import { HttpInboundTransport } from '@aries-framework/node'

// ... agent setup from prevous section ...

agent.registerOutboundTransport(new HttpOutboundTransport())
agent.registerOutboundTransport(new WsOutboundTransport())
agent.registerInboundTransport(new HttpInboundTransport({ port: 3000 }))

Initializing the agent

Finally, we can initialize the agent and it's ready for use.

agent
.initialize()
.then(() => {
console.log('Agent initialized!')
})
.catch((e) => {
console.error(`Something went wrong while setting up the agent! Message: ${e}`)
})

Next Steps

Now that you have your agent setup, it's time to start building your application. Head over to the tutorials page to get started.

Useful resources