7-4. TransferOwnership Component

TransferOwnershipcomponent's roleComponent code
2-1. Rendering
transferOwnershipbutton2-2.
TransferOwnershipcomponentInteract with contract:
transferOwnershipmethodUpdate data to store:
updateOwnerAddressaction
1) TransferOwnership component's role
TransferOwnership component's roleThe 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
TransferOwnership buttonWe 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
TransferOwnership component3) Interact with contract: transferOwnership method
transferOwnership methodWe already made transferOwnership function in Klaystagram contract at chapter 4. Write Klaystagram Smart Contract. Let's call it from application.
Invoke the contract method:
transferOwnershipid:Photo's tokenIdto:Address to transfer photo's ownership
Set transaction options
from: An account that sends this transaction and pays the transaction fee.gas: The maximum amount of gas that thefromaccount is willing to pay for this transaction.
After sending the transaction, show progress along the transaction lifecycle using
Toastcomponent.If the transaction successfully gets into a block, call
updateOwnerAddressfunction to update new owner's address into the feed page.
4) Update information in redux store: updateOwnerAddress action
updateOwnerAddress actionAfter 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