Create a Service

Creating A Service

This section details how to create a service using the ers-scripts repo.

Set Up

If you are trying to execute a transaction it is assumed that you have also read the Set Up section. If you are just looking for an example read on

To be able to create a service you first need to specify the Ethereum account you want to call createService, note that this address will be set as the "owner" of the service however that can be changed post-creation. To do this, you must input the private key of the account you wish to use into the .env file. The .env file should look something like this:


Replace the stand-in private keys (pulled from Hardhat) with the private key you wish to use. Make sure that you are using the correct private key for the network you are deploying to.

Executing the Script

The script to create a service is located in tasks/serviceCreation.ts. To execute the script run:

yarn createService --network [network] --service-name [name] --content [content] --append-id [true/false]


  • service-name is the name you wish to give your service, each name must be unique so if it has been chosen previously it will revert
  • content is an https or ipfs address of the content you wish to tie to the chips enrolled in the service
  • append-id is a boolean that determines whether or not the chipId will be appended to the end of the content string

When the script is run the service-name is transformed into a bytes32 representation that is used as the serviceId for the service like so:

const serviceId = ethers.utils.formatBytes32String(serviceName);

We then form the ServiceRecord struct that will be used to create the service, note that we convent the passed content into bytes and pass in the CONTENT_APP_RECORD_TYPE as the recordType (which is defined as bytes32("contentApp")):

    const serviceRecord: ServiceRecord = {
      recordType: CONTENT_APP_RECORD_TYPE,
      content: stringToBytes(content),

The ServiceRecord struct and the serviceId are then passed to the smart contract:

    await rawTx({
      from: serviceCreator,
      to: servicesRegistry.address,
      data: servicesRegistry.interface.encodeFunctionData(