Get 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

Create a provider

The SDK directly connects to the Blockchain and therefore requires a connection to a Blockchain data provider (a node).

Info

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

If you are using this SDK Inside a browser such as 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 });

Is equivalent to:

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

Use 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.

Overrides

All methods can be overridden by adding 'overrides', allowing you to set options manually (e.g., 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

myFunction(overrides);

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

const token = await Token.at("CONTRACT ADDRESS", SIGNER);
token.overrides = overrides;
}