Skip to main content
Version: v0.5.x

Create a connection

In this tutorial we will create a connection as Acme Corp with Bob. We will start with setting up both their agents with the minimal configuration required to follow this tutorial. After the initialization we will then create an invitation as Acme Corp and send it over to Bob. Bob will then accept this invitation and at that point they have established a connection and they know how to reach each other for sending a basic message, issuing a credential, verifying a proof, etc.

info

This section assumes that

  1. You have set-up your development environment.
  2. You have basic knowledge of the required fields in the Agent Config

1. Setting up the agents

First for both agents we must setup and initialize an agent to work with. Depending on your target, React Native or Node.js, it might vary.

In this tutorial Bob will be in a React Native environment and Acme Corp in a Node.js environment.

Bob

For bob we need to setup a basic agent with a wallet, mediator and outbound transport.

🧔bob

Acme

For Acme we need to setup a basic agent with a wallet, inbound and outbound transport.

🏢acme

2. Creating an invitation

Now that we have setup both agents, we can create an invitation from Acme Corp.

New

This method will create an invitation using the legacy method according to 0434: Out-of-Band Protocol 1.1.

🏢acme
const outOfBandRecord = await agent.oob.createInvitation()

const serializedInvitation = outOfBandRecord.outOfBandInvitation.toUrl({ domain: 'https://example.org' })

Legacy

This method will create an invitation using the legacy method according to 0160: Connection Protocol.

🏢acme

3. Receiving the invitation

After we have created the invitation we have to transmit it to the other agent. Common practice, when sending it to a holder, it to embed the url inside a QR code. This QR code can then be scanned by the holder, in this case Bob. After this, because both have set autoAcceptConnections to true, the connection is established.

🧔bob

4. (additional) listen to incoming connection responses

When you quickly want to use the event or the data of a response to a connection request, you can start an TODO: agent event listener.

Another use case for this would be to get the connectionRecord of the connection as it is only created when the invitation has been received by the other agent. The connectionRecord is very essential in processes like TODO: issuing a credential or TODO: verifying a proof.

The connectionRecord can also be retrieved with agent.connections.findAllByOutOfBandId(id), but with this method there is no way of knowing if the invitation has been received.

🏢acme

5. Full code snippets

Below are both code snippets for each agent. These can be used as base but should be edited to fit your use case. The walletConfig.key must be changed as it can lead to other people knowing your "password" to your wallet.

Useful resources