To create a new token configuration as a JSON object. The token requires a name and a symbol. The Token is an integer, meaning decimals default to 0. Our Token won't have an OnchainID, so this field will be left blank in this example.

{
  "name": "Example Token",
  "symbol": "EXT",
  "decimals": 0,
  "onchainID": null
}

Next, you need to declare the rules that will be applied to the new Token.

Compliance

For the Tokens compliance, we will use a default contract with no specific rules:

{
  "name": "Example Token",
  "symbol": "EXT",
  "decimals": 0,
  "onchainID": null,
  "rules": {
    "complianceRules": {
      "useDefault": true
    }
  }
}

Identity Validation

For the validation of Identities, it requires the identity to be manually registered with a valid, specific KYC claim issued by a claim issuer, you can manage this using the Claim Issuer smart contract at the following address 0xD2902271342d077686B4B4Eb18b74DCb59624C9B. We add the specific KYC claim topic 1010101xxxxxxx with a specific ID 42 in the list of requiredClaims and the issuer 0xD2902271342d077686B4B4Eb18b74DCb59624C9B with the allowed topic of the claim in the trustedIssuers field.

{
  "name": "Example Token",
  "symbol": "EXT",
  "decimals": 0,
  "onchainID": null,
  "rules": {
    "complianceRules": {
      "useDefault": true
    },
    "holderRules": {
      "requiredClaims": [10101010000042],
      "trustedIssuers": {
        "0xD2902271342d077686B4B4Eb18b74DCb59624C9B": {
          "trustedTopics": [10101010000042]
        }
      }
    }
  }
}

You can also require an Identity Verification claim, issued by one of two Identity Verification providers partnered with. They both have a smart contract address 0x990De116847ea9C5d6ed9605a76DBE3462e2b714 and 0xfc5c8cfbd7dDFAA09e55fe5E3fc8d1563Ae0F006. We add the Identity Verification topic and the two issuers for this topic.

{
  "name": "Example Token",
  "symbol": "EXT",
  "decimals": 0,
  "onchainID": null,
  "rules": {
    "complianceRules": {
      "useDefault": true
    },
    "holderRules": {
      "requiredClaims": [10101010000042, 10101000100006],
      "trustedIssuers": {
        "0xD2902271342d077686B4B4Eb18b74DCb59624C9B": {
          "trustedTopics": [10101010000042]
        },
        "0x990De116847ea9C5d6ed9605a76DBE3462e2b714": {
          "trustedTopics": [10101000100006]
        },
        "0xfc5c8cfbd7dDFAA09e55fe5E3fc8d1563Ae0F006": {
          "trustedTopics": [10101000100006]
        }
      }
    }
  }
}

Deployment

To deploy the new Token, we must create a Token Factory from the configuration above:

const tokenFactory = await Token.createFactory({
  "name": "Example Token",
  "symbol": "EXT",
  "decimals": 0,
  "onchainID": null,
  "rules": {
    "complianceRules": {
      "useDefault": true
    },
    "holderRules": {
      "requiredClaims": [10101010000042, 10101000100006],
      "trustedIssuers": {
        "0xD2902271342d077686B4B4Eb18b74DCb59624C9B": {
          "trustedTopics": [10101010000042]
        },
        "0x990De116847ea9C5d6ed9605a76DBE3462e2b714": {
          "trustedTopics": [10101000100006]
        },
        "0xfc5c8cfbd7dDFAA09e55fe5E3fc8d1563Ae0F006": {
          "trustedTopics": [10101000100006]
        }
      }
    }
  }
})

Plan

Now you can generate the plan, a list of steps to be executed by the deployment process. The method will also validate the configuration JSON. In case it is not correct, the SDK throws an 'InvalidConfigurationError'.

await tokenFactory.makePlan();
console.info('Plan to be executed:');
console.info(tokenFactory.plan);

Trying to access the plan before it was generated will throw a PlanNotGeneratedError:

    console.info(tokenFactory.plan);
    // -> PlanNotGeneratedError: Trying to access a plan that does not exist on the factory. Call factory.makePlan() first.
    ```

## Events

Once our factory is created, and the plan has been reviewed, we can subscribe to events emitted during the deployment process.

```javascript
tokenFactory.on('fail', (event) => {
  console.error('Deployment of the token failed.');
  console.error(event);
});

tokenFactory.on('progress', (event) => { console.log(event); });

tokenFactory.on('deployed', (event) => {
  console.info(event);
  console.info(`The token was successfully deployed at address ${event.deploymentAddress}.`);
});

Execution

To execute a deployment plan, call deploy on the factory to return a token object. Emit the different progress events, and eventually conclude with a fail or success emission.

const token = await tokenFactory.deploy({ signer });