Skip to content

Latest commit

 

History

History
115 lines (75 loc) · 3.76 KB

README.md

File metadata and controls

115 lines (75 loc) · 3.76 KB

CircleCI codecov

Token Registry

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

🧪 Join the Beta!

If you are interested in using and helping us at testing the new features of transferable records, please consider trying out our beta branch. We'd love to hear your feedback!😊

Installation

npm i @govtechsg/token-registry

Usage

To use the package, you will need to provide your own Web3 provider or signer (if you are writing to the blockchain).

TradeTrustERC721

Deploy new token registry

import { TradeTrustERC721Factory } from "@govtechsg/token-registry";

const factory = new TradeTrustERC721Factory(signer1);
const tokenRegistry = await tokenRegistryFactory.deploy("MY_TOKEN_REGISTRY", "TKN");

Connect to existing token registry

import { TradeTrustERC721Factory } from "@govtechsg/token-registry";

const connectedRegistry = TradeTrustERC721Factory.connect(existingERC721Address, signer1);

List of available functions

The contract supports all ERC721 methods

TitleEscrow

The TradeTrustErc721 Token Registry will clone a new TitleEscrow internally when minting or restoring titles.

Minting Title Escrow

import { TradeTrustERC721Factory } from "@govtechsg/token-registry";

const connectedRegistry = TradeTrustERC721Factory.connect(existingERC721Address, signer);
const tx = await connectedRegistry.mintTitle(beneficiaryAddress, holderAddress, tokenId);

Restoring Title Escrow

import { TradeTrustERC721Factory } from "@govtechsg/token-registry";

const connectedRegistry = TradeTrustERC721Factory.connect(existingERC721Address, signer);
const tx = await connectedRegistry.restoreTitle(beneficiaryAddress, holderAddress, existingTokenId);

Connect to Title Escrow

import { TitleEscrowFactory } from "@govtechsg/token-registry";

const connectedEscrow = TitleEscrowFactory.connect(existingTitleEscrowAddress, signer1);

For list of available functions on TitleEscrow simply check the type definitions as they are automatically generated using typechain.

Provider & Signer

Different ways to get provider or signer:

import { Wallet, providers, getDefaultProvider } from "ethers";

// Providers
const mainnetProvider = getDefaultProvider();
const ropstenProvider = getDefaultProvider("ropsten");
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);

Setup

npm install
npm lint
npm test
npx hardhat <command>

Development

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.

Notes

  • The contracts have not gone through formal audits yet. Please use them at your own discretion.