TradeTrust Electronic Bill of Lading (eBL)
The Electronic Bill of Lading (eBL) is a digital document that can be used to prove the ownership of goods. It is a standardised document that is accepted by all major shipping lines and customs authorities. The Token Registry repository contains both the smart contract
code for token registry (in /contracts
) as well as the node package for using this library (in /src
).
- Installation
- Usage
- Deployment
- Configuration
- Development
- Subgraph
- Notes
npm install --save @tradetrust-tt/token-registry
To use the package, you will need to provide your own Web3 provider or signer (if you are writing to the blockchain). This package exposes the Typechain (Ethers) bindings for the contracts.
The TradeTrustToken
is a Soulbound Token (SBT) tied to the Title Escrow. The SBT implementation is loosely based on OpenZeppelin's implementation of the ERC721 standard.
An SBT is used in this case because the token, while can be transferred to the registry, is largely restricted to its designated Title Escrow contracts.
See issue #108 for more details.
import { TradeTrustToken__factory } from "@tradetrust-tt/token-registry/contracts";
const connectedRegistry = TradeTrustToken__factory.connect(tokenRegistryAddress, signer);
await connectedRegistry.mint(beneficiaryAddress, holderAddress, tokenId, remarks);
await connectedRegistry.restore(tokenId, remarks);
await connectedRegistry.burn(tokenId, remarks);
The Title Escrow contract is used to manage and represent the ownership of a token between a beneficiary
and holder
.
During minting, the Token Registry will create and assign a Title Escrow as the owner of that token.
The actual owners will use the Title Escrow contract to perform their ownership operations.
Important
A new remark
field has been introduced for all contract operations.
The remark
field is optional and can be left empty by providing an empty string "0x"
.
Please note that any value in the remark
field is limited to 120 characters, and encryption is recommended.
Please refer to the sample encryption implementation here.
import { TitleEscrow__factory } from "@tradetrust-tt/token-registry/contracts";
const connectedEscrow = TitleEscrow__factory.connect(existingTitleEscrowAddress, signer);
Transferring of beneficiary
and holder
within the Title Escrow relies on the following methods:
function transferBeneficiary(address nominee, bytes calldata remark) external;
function transferHolder(address newHolder, bytes calldata remark) external;
function transferOwners(address nominee, address newHolder, bytes calldata remark) external;
function nominate(address nominee, bytes calldata remark) external;
Note
The transferBeneficiary
transfers only the beneficiary and transferHolder
transfers only the holder.
To transfer both beneficiary and holder in a single transaction, use transferOwners
.
In the event where the holder
is different from the beneficiary
, the transfer of beneficiary will require a nomination done through the nominate
method.
Rejection of transfers for any wrongful transactions.
function rejectTransferBeneficiary(bytes calldata _remark) external;
function rejectTransferHolder(bytes calldata _remark) external;
function rejectTransferOwners(bytes calldata _remark) external;
Important
Rejection must occur as the very next action after being appointed as beneficiary
and/or holder
. If any transactions occur by the new appointee, it will be considered as an implicit acceptance of appointment.
There are separate methods to reject a beneficiary
(rejectTransferBeneficiary
) and a holder
(rejectTransferHolder
). However, if you are both, you must use rejectTransferOwners
, as the other two methods will not work in this case.
Use the returnToIssuer
method in the Title Escrow.
function returnToIssuer(bytes calldata remark) external;
The addresses of the current owners can be retrieved from the beneficiary
, holder
and nominee
methods.
Example:
const currentBeneficiary = await connectedEscrow.beneficiary();
const currentHolder = await connectedEscrow.holder();
const nominatedBeneficiary = await connectedEscrow.nominee();
Different ways to get provider or signer:
import { Wallet, providers, getDefaultProvider } from "ethers";
// Providers
const mainnetProvider = getDefaultProvider();
const metamaskProvider = new providers.Web3Provider(web3.currentProvider); // Will change network automatically
// Signer
const signerFromPrivateKey = new Wallet("YOUR-PRIVATE-KEY-HERE", provider);
const signerFromEncryptedJson = Wallet.fromEncryptedJson(json, password);
signerFromEncryptedJson.connect(provider);
const signerFromMnemonic = Wallet.fromMnemonic("MNEMONIC-HERE");
signerFromMnemonic.connect(provider);
Roles are useful for granting users to access certain functions only. Currently, here are the designated roles meant for the different key operations.
Role | Access |
---|---|
DefaultAdmin |
Able to perform all operations |
MinterRole |
Able to mint new tokens |
AccepterRole |
Able to accept a token returned to issuer |
RestorerRole |
Able to restore a token returned to issuer |
A trusted user can be granted multiple roles by the admin user to perform different operations. The following functions can be called on the token contract by the admin user to grant and revoke roles to and from users.
import { constants } from "@tradetrust-tt/token-registry";
await connectedRegistry.grantRole(constants.roleHash.MinterRole, accountAddress);
Important
Can only be called by default admin or role admin.
import { constants } from "@tradetrust-tt/token-registry";
await connectedRegistry.revokeRole(constants.roleHash.AccepterRole, accountAddress);
Important
Can only be called by default admin or role admin.
The standard setup does not add the role-admin roles so that users don't deploy (and, hence, pay the gas for) more than what they need. If you need a more complex setup, you can add the admin roles to the designated roles.
import { constants } from "@tradetrust-tt/token-registry";
const { roleHash } = constants;
await connectedRegistry.setRoleAdmin(roleHash.MinterRole, roleHash.MinterAdminRole);
await connectedRegistry.setRoleAdmin(roleHash.RestorerRole, roleHash.RestorerAdminRole);
await connectedRegistry.setRoleAdmin(roleHash.AccepterRole, roleHash.AccepterAdminRole);
Important
Can only be called by default admin.
Hardhat is used to manage the contract development environment and deployment. This repository provides a couple of Hardhat tasks to simplify the deployment process.
Starting from v4, we have included an easy and cost-effective way to deploy the contracts while also keeping options available for advanced users to setup the contracts their preferred way.
Tip
๐ก Please ensure that you have setup your configuration file before deployment.
See Configuration section for more details. The deployer (configured in your .env
file) will be made the default admin.
For users who want to quickly deploy their contracts without too much hassle, youโll only have to supply the name and symbol of your token to the command, and youโre ready to roll!
npx hardhat deploy:token --network stability --name "The Great Shipping Co." --symbol GSC
๐ This is the easiest and most cost-effective method to deploy. The deployed contract will inherit all the standard functionality from our on-chain contracts. This helps to save deployment costs and make the process more convenient for users and integrators.
Tip
๐ก Remember to supply the --network
argument with the name of the network you wish to deploy on.
See Network Configuration section for more info on the list of network names.
For experienced users who would like to have more control over their setup (or have extra ๐ฐ to spend ๐ธ), we have provided a few other options and commands. However, you should be aware that, depending on what youโre doing, the gas costs could be higher than the method described in Quick Start. You should already know what you are doing when using any of these options.
Deploys the token contract.
user@NMacBook-Pro token-registry % npx hardhat deploy:token --help
Usage: hardhat [GLOBAL OPTIONS] deploy:token --factory <STRING> --name <STRING> [--standalone] --symbol <STRING> [--verify]
OPTIONS:
--factory Address of Title Escrow factory (Optional)
--name Name of the token
--standalone Deploy as standalone token contract
--symbol Symbol of token
--verify Verify on Etherscan
deploy:token: Deploys the TradeTrust token
Tip
๐ก Note that the --factory
argument is optional. When not provided, the task will use the default Title Escrow Factory.
You can also reuse a Title Escrow factory that you have previously deployed by passing its address to the --factory
argument.
-
To use an existing version of Title Escrow factory, you can supply its address to the
โ-factory
argument. -
To use your own version of Title Escrow factory, you need to supply its address to the
--factory
with the--standalone
flag.
npx hardhat deploy:token --network polygon --name "The Great Shipping Co." --symbol GSC --factory 0xfac70
๐ This will deploy a "cheap" token contract with the name The Great Shipping Co. under the symbol GSC on the Polygon Mainnet
network using an existing Title Escrow factory at 0xfac70
.
Deploys the Title Escrow factory.
user@NMacBook-Pro token-registry % npx hardhat deploy:token --help
Usage: hardhat [GLOBAL OPTIONS] deploy:factory [--verify]
OPTIONS:
--verify Verify on Etherscan
deploy:factory: Deploys a new Title Escrow factory
If you want to deploy your own modified version or simply want to have your own copy of the Title Escrow factory, you can use this command:
npx hardhat deploy:factory --network amoy
๐ This will deploy a new Title Escrow factory on the Amoyy network without verifying the contract.
To verify the contract, pass in the --verify
flag.
When verifying the contracts through either the Hardhat's verify plugin or passing the --verify
flag to the deployment
tasks (which internally uses the same plugin), you will need to include your correct API key, depending on the network, in your .env
configuration. See Configuration section for more info.
- For Ethereum, set
ETHERSCAN_API_KEY
. - For Polygon, set
POLYGONSCAN_API_KEY
. - For Astron, set
ASTRONSCAN_API_KEY
.
Here's a list of network names currently pre-configured:
mainnet
(Ethereum)sepolia
polygon
(Polygon Mainnet)amoy
(Polygon Amoy)xdc
(XDC Network Mainnet)xdcapothem
(XDC Apothem TestNet)stabilitytestnet
(Stability TestNet)stability
(Stability Global Trust Network)astron
(astron Network MainNet)
Tip
๐ก You can configure existing and add other networks you wish to deploy to in the hardhat.config.ts
file.
Create a .env
file and add your own keys into it. You can rename from the sample file .env.sample
or copy the
following into a new file:
# Infura
INFURA_APP_ID=
# API Keys
ETHERSCAN_API_KEY=
POLYGONSCAN_API_KEY=
COINMARKETCAP_API_KEY=
STABILITY_API_KEY=
ASTRONSCAN_API_KEY=
# Deployer Private Key
DEPLOYER_PK=
# Mnemonic words
MNEMONIC=
Only either the DEPLOYER_PK
or MNEMONIC
is needed.
This repository's development framework uses HardHat.
Tests are run using npm run test
, more development tasks can be found in the package.json scripts.
npm install
npm test
npm run lint
npm run build
# See Deployment section for more info
npx hardhat deploy:token
npx hardhat deploy:factory
npx hardhat deploy:token:impl
Check out our Token Registry Subgraph Github repository for more information on using and deploying your own subgraphs for the Token Registry contracts.
- The contracts have not gone through formal audits yet. Please use them at your own discretion.