Getting started

Once you have the SDK installed in your project (see the previous section), you can start working with the T-REX standard on the Blockchain.

Configure a Provider and a Wallet

The SDK directly connects to the Blockchain and therefore requires a connection to a Blockchain data provider also known as a node.

For more information regarding nodes and the Blockchain, you can refer to this article

If you are using this SDK Inside a browser with a front-end application written in Vue or React, You may want to leverage and integrate with an extension such as Metamask.

For the JavaScript SDK, we use the EthersJS library to interface with Blockchain providers. Therefore, any provider supported by EthersJS will also be compatible with the SDK.

We export some of the EthersJS utilities so that you don't have to import EthersJS into your application. For example:

const provider = new TREX.Providers.JSONRpcProvider('http://localhost:8545');
const name = await token.getName({ provider });

This is equivalent to:

const ethers = require('ethers');
const provider = new ethers.providers.JsonRpcProvider('http://localhost:8545');
const name = await token.getName({ provider });

Using a provider

All methods from the SDK accept a last options argument. For methods using Blockchain data, these options include a provider field:

const identity = await token.getIdentityOfWallet('WALLET ADDRESS', { provider });

Wait for transaction confirmation

All write operation methods return a TransactionResponse object from Ethers.js. You can use the async/await syntax to make the call.

const myFunction = async() => {
  const transaction = await tx.wait();

Which returns the transaction confirmation. We provide tx.wait() because functions emitting transactions on the Blockchain do not wait for transaction confirmation. Which means we cannot chain them in the same block mined. When you use tx.wait(), you make sure the transaction has been mined before continuing.


All methods can be overridden by adding 'overrides', allowing you to set options manually such as GasPrice, GasLimit, Signer, Provider, etc. This parameter is the last of every method and is optional.

overrides = {
  // The maximum units of gas for the transaction to use
  gasLimit?: number,

  // The price (in wei) per unit of gas
  gasPrice?: BigNumber,

  // The nonce to use in the transaction
  nonce?: number,

  // The amount to send with the transaction (i.e. msg.value)
  value?: BigNumber,

  // The chain ID (or network ID) to use
  chainId?: number

You can then use it as below


or you can define it for the session this will be reset if you load the Token again

const token = await"CONTRACT ADDRESS", SIGNER);
token.overrides = overrides;