Skip to main content

Get started with Credo

This quickstart will guide you through creating a basic Credo agent that can manage DIDs and credentials.
1

Install core dependencies

Install the core Credo package and required storage module:
npm install @credo-ts/core @credo-ts/askar @openwallet-foundation/askar-nodejs
The @credo-ts/askar package provides secure storage for keys and data. For Node.js, you’ll also need @openwallet-foundation/askar-nodejs.
2

Install platform dependencies

Install the platform-specific package for Node.js:
npm install @credo-ts/node
3

Create and initialize your agent

Create a new file agent.ts and add the following code:
agent.ts
import { Agent, ConsoleLogger, LogLevel } from '@credo-ts/core'
import { AskarModule } from '@credo-ts/askar'
import { agentDependencies } from '@credo-ts/node'
import { askar } from '@openwallet-foundation/askar-nodejs'

// Initialize the agent
const agent = new Agent({
  config: {
    logger: new ConsoleLogger(LogLevel.info),
  },
  dependencies: agentDependencies,
  modules: {
    askar: new AskarModule({
      askar,
      store: {
        id: 'my-agent',
        key: 'my-secret-key-must-be-at-least-32-characters-long',
      },
    }),
  },
})

// Initialize the agent
await agent.initialize()

console.log('Agent initialized!')

// Create a DID
const didResult = await agent.dids.create({
  method: 'key',
})

console.log('Created DID:', didResult.didState.did)

// Shutdown the agent
await agent.shutdown()
This example creates a minimal agent with Askar storage. The agent can create DIDs, manage keys, and store data securely.
4

Run your agent

Execute your agent:
npx tsx agent.ts
You should see output similar to:
Agent initialized!
Created DID: did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH
The agent will create a wallet file in your current directory. Make sure to use a secure key in production and never commit it to version control.

What’s next?

Now that you have a basic agent running, explore these topics:

DIDComm messaging

Enable peer-to-peer messaging between agents

Issue credentials

Learn how to issue verifiable credentials

Verify presentations

Verify credential presentations from holders

OpenID4VC

Use OpenID for Verifiable Credentials

More examples

To enable DIDComm messaging, add the DIDComm module:
import { DidCommModule, DidCommHttpOutboundTransport } from '@credo-ts/didcomm'
import { DidCommHttpInboundTransport } from '@credo-ts/node'

const agent = new Agent({
  config: {
    logger: new ConsoleLogger(LogLevel.info),
  },
  dependencies: agentDependencies,
  modules: {
    askar: new AskarModule({
      askar,
      store: { id: 'my-agent', key: 'my-secret-key' },
    }),
    didcomm: new DidCommModule({
      endpoints: ['http://localhost:3000'],
      transports: {
        inbound: [new DidCommHttpInboundTransport({ port: 3000 })],
        outbound: [new DidCommHttpOutboundTransport()],
      },
    }),
  },
})
To work with AnonCreds credentials, add the AnonCreds module:
import { AnonCredsModule } from '@credo-ts/anoncreds'
import { anoncreds } from '@hyperledger/anoncreds-nodejs'

const agent = new Agent({
  config: {
    logger: new ConsoleLogger(LogLevel.info),
  },
  dependencies: agentDependencies,
  modules: {
    askar: new AskarModule({
      askar,
      store: { id: 'my-agent', key: 'my-secret-key' },
    }),
    anoncreds: new AnonCredsModule({
      anoncreds,
      registries: [],
    }),
  },
})
To use OpenID for Verifiable Credentials:
import { OpenId4VcModule } from '@credo-ts/openid4vc'

const agent = new Agent({
  config: {
    logger: new ConsoleLogger(LogLevel.info),
  },
  dependencies: agentDependencies,
  modules: {
    askar: new AskarModule({
      askar,
      store: { id: 'my-agent', key: 'my-secret-key' },
    }),
    openId4Vc: new OpenId4VcModule(),
  },
})

Need help?

Join the community

Join our Discord channel or mailing list for support

Build docs developers (and LLMs) love