7-4. TransferOwnership Component

transfer ownership
  1. TransferOwnership component's role

  2. Component code

    2-1. Rendering transferOwnership button

    2-2. TransferOwnership component

  3. Interact with contract: transferOwnership method

  4. Update data to store: updateOwnerAddress action

1) TransferOwnership component's role

The owner of photo can transfer photo's ownership to another user. By sending transferOwnership transaction, new owner's address will be saved in ownership history, which keep tracks of past owner addresses.

2) Component code

2-1) Rendering TransferOwnership button

We are going to render TransferOwnership button on the FeedPhoto component only when photo's owner address matches with logged-in user's address (which means you are the owner).

2-2) TransferOwnership component

3) Interact with contract: transferOwnership method

We already made transferOwnership function in Klaystagram contract at chapter 4. Write Klaystagram Smart Contract. Let's call it from application.

  1. Invoke the contract method: transferOwnership

    • id: Photo's tokenId

    • to: Address to transfer photo's ownership

  2. Set transaction options

    • from: An account that sends this transaction and pays the transaction fee.

    • gas: The maximum amount of gas that the from account is willing to pay for this transaction.

  3. After sending the transaction, show progress along the transaction lifecycle using Toast component.

  4. If the transaction successfully gets into a block, call updateOwnerAddress function to update new owner's address into the feed page.

4) Update information in redux store: updateOwnerAddress action

After transferring ownership, FeedPhoto needs to be rerendered with new owner's address. To update new owner's address, let's call feed data from store and find the photo that has the tokenId from the receipt. Then push new owner's address to photo's ownerHistory and setFeed.

Last updated