Adding participants

Adding participants

A participant can be added to a participant registry using either the API or the command line.

Before you start

Before you follow these steps, you must have modeled a participant in a Business Network Definition and deployed it as a Business Network.

The procedure below shows an example using the following model of a participant from the Digital Property sample Business Network Definition: digitalproperty-network

Please note: If you are adding the participant using the composer participant add command, ensure that the JSON representation of the participant is wrapped in single quotes.

namespace net.biz.digitalPropertyNetwork

participant Person identified by personId {
  o String personId
  o String firstName
  o String lastName
}

Procedure

  1. Add the participant to a participant registry
    • JavaScript API
    const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;

    async function addParticipant() {
        let businessNetworkConnection = new BusinessNetworkConnection();

        try {
            await businessNetworkConnection.connect('admin@digitalPropertyNetwork');
            let participantRegistry = await businessNetworkConnection.getParticipantRegistry('net.biz.digitalPropertyNetwork');
            let factory = businessNetworkConnection.getFactory();
            let participant = factory.newResource('net.biz.digitalPropertyNetwork', 'Person', 'mae@biznet.org');
            participant.firstName = 'Mae';
            participant.lastName = 'Smith';
            await participantRegistry.add(participant);
            await businessNetworkConnection.disconnect();
        } catch(error) {
            console.error(error);
            process.exit(1);
        }
    }

    addParticipant();
  • Command line

    composer participant add -c admin@network -d '{"$class":"net.biz.digitalPropertyNetwork.Person","personId":"mae@biznet.org","firstName":"Mae","lastName":"Smith"}'