Accessing token information

Retrieve information

Retrieve information about the token by calling the .getInformation() method.

It has a cache mechanism so you can safely call it multiple times without querying the blockchain every time. You can force a refresh by using the argument forceRefresh: true present in the options parameter.

The information you can retrieve is as follows:

InformationMethod
name.getName()
symbol.getSymbol()
decimals.getDecimals()
onchainId.getOnchainId()
versiongetVersion.()
import { Token, Providers } from '@tokenyico/trex-sdk';
const provider = await Providers.getDefaultProvider('ropsten');

const token = await Token.at('TOKEN CONTRACT ADDRESS', { provider });
const name = await token.getName();

All these methods are also usable directly as a getter from the Token object. These methods will use the cached versions of the information, or the default provider of the token if they were not already retrieved.

 import { Token, Providers } from '@tokenyico/trex-sdk';
 const provider = await Providers.getDefaultProvider('ropsten');
 
 const token = await Token.at('TOKEN CONTRACT ADDRESS', { provider });
 const name = await token.getName;

Update information

To update any of the general information above, use the .setInformation method:

const tx = await token.setInformation({
  name: 'Some New Name',
  symbol: 'NSM',
  version: '1.2',
  decimals: 0,
  onchainID: 'ONCHAINID ADDRESS',
});

Sub-contracts

A T-REX contract is composed of many sub-contracts that you can directly call instead of using the methods of the Token class. To retrieve the addresses or instances of these contracts, use the following methods:

ContractAddressInstance
Identity Registry.getIdentityRegistryAddress().getIdentityRegistryInstance()
Trusted Issuers Registry.getTrustedIssuersRegistryAddress().getTrustedIssuersRegistryInstance()
Claim Topics Registry.getClaimTopicsRegistryAddress().getClaimTopicsRegistryInstance()
OnchainID.getOnchainIdAddress().getOnchainIdInstance()
Compliance.getComplianceAddress().getComplianceInstance()
import { Token, Providers } from '@tokenyico/trex-sdk';
const provider = await Providers.getDefaultProvider('ropsten');

const token = await Token.at('TOKEN CONTRACT ADDRESS', { provider });
const identityRegistryAddress = await token.getIdentityRegistryAddress({ provider });
const identityRegistry: Ethers.Contract = await token.getIdentityRegistryInstance();

When retrieving instances, you are provided with a contract object from the EtherJS library. This is loaded with the ABI, the interface and the desired contract type, on which you can call any smart contract methods. They will be loaded unless overridden by the same provider loaded in the token

It is recommended that you always use the methods of the Token class to manipulate the T-REX token and avoid the usage of the methods on the sub-contracts.