Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
fix: add doc for title transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
MinHtet-O committed May 28, 2024
1 parent 0143a44 commit c7b5179
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 22 deletions.
86 changes: 66 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 `<your_private_key>`, `<your_provider_url>`, `<token_registry_address>`, `<beneficiary_address>` and '<holder_address>' 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 `<your_private_key>`, `<your_provider_url>`, `<token_registry_address>`, `<beneficiary_address>` and `<holder_address>` 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'
Expand All @@ -160,7 +160,7 @@ async function start() {
const transaction = await connectedRegistry.mint(
'<beneficiary_address>',
'<holder_address>',
tokenId'
tokenId
)
console.log(`Waiting for transaction ${transaction.hash} to be completed`)
const receipt = await transaction.wait()
Expand All @@ -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('<your_private_key>')
const provider = new ethers.providers.JsonRpcProvider('<your_provider_url>')
const wallet = unconnectedWallet.connect(provider)

const tokenId = '<your_token_id>'
const address = '<your_token_registry_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.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit c7b5179

Please sign in to comment.