Information¶
General Information¶
Retrieve information¶
Retrieve information about the token by calling the .getInformation()
instance method.
It has a cache mechanic so you can safely call it multiple time without querying the blockchain every time.
You can force a refresh by using the argument forceRefresh: true
of the options
parameter.
Information you can retrieve are the following:
Information | Method |
---|---|
name |
.getName() |
symbol |
.getSymbol() |
decimals |
.getDecimals() |
onchainId |
.getOnchainId() |
version |
getVersion.() |
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();
Note
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.
```javascript 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 TREX 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:
Contract | Address | Instance |
---|---|---|
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
Warning
It is recommended that you always use the methods of the Token class to manipulate the TREX, and avoid the usage of the methods of the sub-contracts.