🖋️
Tokenscript
  • Tokenization and dApps
  • TokenScript
    • Introduction to TokenScript
      • The Framework
      • Benefits for Users
      • What can TokenScript Do?
      • DeFi with, and without Tokenscript
      • Tokenscript examples in AlphaWallet
    • Quickstart Tutorial
  • Basic Concepts
    • TokenScript File
    • Attributes
    • Cards
      • Token Card
      • Action Card
      • Activity Card
    • Data Objects
    • Attestation
    • TokenScript Syntax
    • Magic Link
  • Deploy TokenScript
    • Deploy TokenScript
      • Signing a TokenScript
    • Features Implemented
    • TokenScript Specs
      • Encoding Attestation in URI
    • TokenScript Guides
      • Mini-guide: Add a Ropsten token to AlphaWallet
      • Mini-guide: Deploy a token on Ropsten testnet
      • Introduction to Token Negotiation
  • External Links
  • Github
Powered by GitBook
On this page

Was this helpful?

  1. Basic Concepts

Attributes

Define attributes so that token data becomes available to Cards and Websites.

PreviousTokenScript FileNextCards

Last updated 4 years ago

Was this helpful?

In TokenScript you can define Attributes for token or for card.Examples of a token's attribute:

  • In Ethereum, all ERC20 Tokens have an balance attribute.

  • For a Car Ownership Token, one attribute might be its model.

The values of these tokens may have various origins defined in the . For an Ethereum token, a typical origin would be a call to an Ethereum contract or an Ethereum event.

Having attributes and the origins of their values defined allows a to provide this data; furthermore, monitor changes to this data and push updates to the code that uses such data, such as the code in a . More on this can be found in the that TokenScript takes.

A does not define specific token attributes, however some are always assumed. When used on Ethereum token, the most important operational attribute is ownerAddress which is always the Ethereum Address of the owner.

The most commonly used attribute is "balance" as defined in ERC20.

Attributes are declared in TokenScript. The following is a minimalist declaration, where an attribute "balance" is defined. The value originates from an Ethereum function call balanceOf

<ts:attribute name="balance">
        <ts:origins>
            <ethereum:call function="balanceOf" as="uint">
                <ts:data><ts:address ref="ownerAddress"/></ts:data>
            </ethereum:call>
        </ts:origins>
    </ts:attribute>

Let's take another more complex example: For a token representing a ticket for a soccer match, its attributes should contain the information when and where the match happens, which teams play, which seat is reserved and so on. Another example of an Attribute declaration declares the locality of a soccer match in the :

 <ts:attribute name="locality">
      <ts:type><ts:syntax>1.3.6.1.4.1.1466.115.121.1.15</ts:syntax></ts:type>
      <ts:origins>
          <ethereum:call function="getLocality" contract="EntryToken" as="utf8">
              <ts:data>
                  <ts:uint256 ref="tokenId"/>
              </ts:data>
          </ethereum:call>
      </ts:origins>
</ts:attribute>
constructor(tokenInstance) {
        this.props = tokenInstance;
        this.props.baseNode = ".eth";
        this.props.fullName = this.props.ensName + this.props.baseNode;
        ...
    }
  • Search / index of a token (e.g. in a market place)

  • Selection

  • Describe criteria of actions

  • Set the role of a token

Attributes are just declarations. They are never directly shown to a wallet. They are just here to let the wallet know and to allow TokenScript to build further operations and representations on it. To make them visible you need cards.

Attribute is a categorical declaration. There are other declarations inside the <attribute> tags, for example <origins> or <token>.

If you want TokenScript to querry a non-blockchain API for information, like weather or exchange prices from a data provider, currently this can't be part of the attribute tag, but part of an action card.

Related references

An token attribute is defined, so that the TokenScript engine knows how to get its value when needed. For example, an Action Card of an renews the ENS domain and uses the attribute ensName, which was declared in the XML file:

Once defined, the attribute is available to all of the defined for this token in the same TokenScript file without special permissions. It also became available in the to allow functionalities like:

<origins> element
TokenScript Engine
Card
data-driven and event-driven approach
TokenScript Engine
Operational Attributes
TokenScript for an entry token
ENS TokenScript
Card
The Token Layer
Token Negotiation
<attribute> element
<origins> element
Bytes32
Data