diff --git a/README.md b/README.md index ac15320..e6bdbaa 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Unified interface for interacting with TradeTrust's various services such as doc npm i @tradetrust-tt/tradetrust-core ``` -## Basic Usage +## Basic Usages #### Wrapping and Signing of verifiable document @@ -134,9 +134,9 @@ async function start() { start() ``` -#### Wrapping & Minting of Transferrable Record +#### Wrapping and Minting of Transferrable Record -This example provides how to wrap the raw document and mint the tradetrust token for [transferrable record](https://docs.tradetrust.io/docs/tutorial/transferable-records/overview/) using the existing token registry address. Replace the place holders ``, ``, ``, `` and '' accordingly. After successfully minted, transaction hash will be displayed and the wrappedDocument should be successfully [verified](#verifying). +This example provides how to wrap the raw document and mint the tradetrust token for [transferrable record](https://docs.tradetrust.io/docs/tutorial/transferable-records/overview/) using the existing token registry address. Replace the place holders ``, ``, ``, `` and `` accordingly. After successfully minted, transaction hash will be displayed and the wrappedDocument should be successfully [verified](#verifying). ```ts import { TradeTrustToken__factory } from '@tradetrust-tt/tradetrust-core' @@ -160,7 +160,7 @@ async function start() { const transaction = await connectedRegistry.mint( '', '', - tokenId' + tokenId ) console.log(`Waiting for transaction ${transaction.hash} to be completed`) const receipt = await transaction.wait() @@ -171,52 +171,98 @@ async function start() { start() ``` -#### Manage ownership of tradetrust token +#### Manage Ownership of Transferable Record -This example demonstrates how to manage and represent the ownership of a TradeTrust token between a beneficiary and holder for [Title Transfer](https://docs.tradetrust.io/docs/topics/introduction/transferable-records/title-transfer), and eventually surrender the document. During [minting](#minting-of-transferrable-record), the [Token Registry](https://docs.tradetrust.io/docs/topics/appendix/glossary/#token-registry) will create and assign a [Title Escrow](https://docs.tradetrust.io/docs/topics/introduction/transferable-records/title-transfer/#title-escrow) as the owner of that token. The actual owners will use the Title Escrow contract to perform their ownership operations. +The examples in this section demonstrate how to manage and represent the ownership of a TradeTrust token between a beneficiary and holder for [Title Transfer](https://docs.tradetrust.io/docs/topics/introduction/transferable-records/title-transfer), and eventually surrender the document. During [minting](#minting-of-transferrable-record), the [Token Registry](https://docs.tradetrust.io/docs/topics/appendix/glossary/#token-registry) will create [Title Escrow](https://docs.tradetrust.io/docs/topics/introduction/transferable-records/title-transfer/#title-escrow) with initial owner and holder. In order to do the title transfer, we will need to connect to the titleEscrow first. ```ts import { connectToTitleEscrow } from '@tradetrust-tt/tradetrust-core' +import { Wallet, ethers } from 'ethers' + +const unconnectedWallet = new Wallet('') +const provider = new ethers.providers.JsonRpcProvider('') +const wallet = unconnectedWallet.connect(provider) +const tokenId = '' +const address = '' const titleEscrow = await connectToTitleEscrow({ tokenId, address, wallet }) ``` -After getting the titleEscrow instance, we can call the following methods to change the ownership of the tradetrust token. +After getting the titleEscrow, we can call the following methods to change the ownership of the tradetrust token. + +`nominate` + +Allow the owner of the transferable record to nominate a new owner. After nomination, +the holder need to endorse with transferBeneficiary method. + +```ts +const transaction = await titleEscrow.nominate(beneficiaryNomineeAddress) +await transaction.wait() +``` + +`transferBeneficiary` + +Allow the holder of the transferable record to endorse the transfer to new owner who is being nominated by the current owner. +If you are both the owner and holder, the change of ownership can happen without nomination. ```ts -/* -allow the holder of the transferable record to endorse the transfer to an approved owner and approved holder of the transferable record. -*/ const transaction = await titleEscrow.transferBeneficiary( beneficiaryNomineeAddress ) await transaction.wait() +``` + +`transferHolder` + +Allow the holder of the transferable record to change its holder. -// allow the owner of a transferable record to change its holder. +```ts const transaction = await titleEscrow.transferHolder(newHolderAddress) await transaction.wait() +``` -/* change the owner and holder. It will fail if the provided holder and owner's addresses are the same as the current owner and current holder's addresses. - */ +`transferOwners` +Allow the entity (who is both an owner and holder) to change to the new owner and holder of the document + +```ts const transaction = await titleEscrow.transferOwners( beneficiaryNomineeAddress, newHolderAddress ) await transaction.wait() +``` -/* allow the owner of the transferable record to nominate a new owner of the transferable record. It will fail if you are not the owner of the transferable record. - */ -const transaction = await titleEscrow.nominate(beneficiaryNomineeAddress) -await transaction.wait() +`surrender` -/* -allow the entity (who is both an owner and holder) to surrender it's transferable record to the token registry. -*/ +Allow the entity (who is both an owner and holder) to surrender it's transferable record to the issuer of the token registry at the end of it's life cycle. + +```ts const transaction = await titleEscrow.surrender() await transaction.wait() ``` +After the the transferable record is surrendered by the owner, the issuer of the token registry need to accept or reject that surrender. +Reference [here](#wrapping-and-minting-of-transferrable-record) on how to get the connected registry. + +`restore` + +Allow the issuer of the token registry to reject the surrender. + +```ts +const transaction = await connectedRegistry.restore(tokenId) +await transaction.wait() +``` + +`burn` + +Allow the issuer of the token registry to accept the surrender and burn the document. + +```ts +const transaction = await connectedRegistry.burn(tokenId) +await transaction.wait() +``` + #### Verifying This example provides how to verify tradetrust document using your own provider configurations. diff --git a/package.json b/package.json index f31b1d5..f7b237f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@minhtetoo/tradetrust-core", - "version": "1.0.19", + "name": "@tradetrust-tt/tradetrust-core", + "version": "1.0.6", "description": "", "main": "dist/cjs/index.js", "module": "dist/esm/index.js",