Distinct Attribute

If an attribute is distinct, it is used to identify a token.

A distinct attribute is a Token Attribute that has distinct set to true:
<attribute name="balance" distinct="true">
…
</attribute>

The number of unique values of this attribute is the number of token instances. The TokenScript engine records each value and uses that to identify each token.

If there is no distinct attribute defined, TokenScript takes ownerAddress=${ownerAddress} as its RDN.

Getting Multiple instances of the token defined

The following code defines a distinct attribute called tokenId. If the smart contract returns 2 values for it:
  • 0x59a7a9fd49fabd07c0f8566ae4be96fcf20be5e1
  • 0xd915c8AD3241F459a45AdcBBF8af42caA561A154
then the TokenScript engine identifies 2 tokens, each identified with:
  • tokenID=0x59a7a9fd49fabd07c0f8566ae4be96fcf20be5e1
  • tokenID=0xd915c8AD3241F459a45AdcBBF8af42caA561A154
<ts:attribute name="tokenId" distinct="true">
  <ts:type>
    <ts:syntax>1.3.6.1.4.1.1466.115.121.1.40</ts:syntax>
  </ts:type>
  <ts:origins>
    <ethereum:call function="balanceOf" contract="EntryToken">
      <ts:data>
        <ts:uint256 ref="ownerAddress"></ts:uint256>
      </ts:data>
    </ethereum:call>
  </ts:origins>
</ts:attribute>

You have 1 contract that defines 2 tokens

For example, you can have 2 TokenScript files.

The first has:
<token name="tokenA">
  …
  <attribute name="tokenID" distinct="true">
    <origins>
      <ethereum:call function="getTokenABalance" contract="MyContract" as="uint"/>
    </origins>
  </attribute>
The second has:
<token name="tokenB">
  …
  <attribute name="tokenID" distinct="true">
    <origin>
      <ethereum:call function="getTokenBalance" contract="MyContract" as="uint"/>
    </origin>
  </attribute>

Although two tokens refer to the same contract "MyContract", and even if they point to the same contract address, a TokenScript engine is able to interpret that there are two tokens.

However, if both TokenScripts has the same distinct attribute from the same origin, it's an error.

A Smart Token identified by a customised attribute

For example, you have one token defined like this:
<token name="car">
  …
  <attribute name="VIN" distinct="true">
    <origins>
      <ethereum:call function="getCars" contract="CarContract"/>
    </origins>
  </attribute>

Then, depends on how many values are returned, the TokenScript engine should interpret that there are that many number of Car Tokens, each with a different distinct VIN (Vehicle Identification Number), all of these Car Tokens are instances defined by this single TokenScript file.