How to get buyer address in a flow market purchase

Hi all. My question to you folks is: How do you determine the buyer (toAddress) when a moment is purchased??

I went through this contract link: https://flowscan.org/contract/A.c1e4f4f4c4257510.Market

Any help is really appreciated. Stuck here for a long time!

hey @quantum-guy7,

Although I don’t know the nitty gritty parts of the NBA Top Shot contract - I can provide some resources that may help clear some confusion.

What happens when someone buys an NFT from another user?

To send an NFT to another user, the seller would simply withdraw the NFT
from their Collection, then call the deposit function of the receiving user’s
Collection to complete the transfer.

Take a look on at NFT Token guide where it walks you through on how to create the transaction that sends to the ‘buyer address’. It is the buyer who initiates the transaction for the NFT deposit so in that logic you can emit events.

execute {
    // Get the recipient's public account object
    let recipient = getAccount(0x01)

    // Get the Collection reference for the receiver
    // getting the public capability and borrowing a reference from it
    let receiverRef = recipient.getCapability<&{ExampleNFT.NFTReceiver}>(/public/NFTReceiver)
        .borrow()
        ?? panic("Could not borrow receiver reference")

    // Deposit the NFT in the receivers collection
    receiverRef.deposit(token: <-self.transferToken)

    log("NFT ID 1 transferred from account 2 to account 1")
}

Please refer to the Flow NFT Standard repo for information about the official Flow NFT standard and an example implementation of it.

Hopefully that brings some clarity!

Hi quantum-guy7

From a Ressource you can access the address of the owner using self.owner
Need to Unwrap first, ex:

let owner = self.owner!
let address: Address = owner.address

From a Contract you can access the address of the contract using

self.account.address

Of course the use of this addresses depends on your coding context but I hope this can help you

Kind Regards

hi all, the event MomentPurchased received. i have no chance to execute script on chain. do you have some suggestion on it?

Hi xds2000

to execute a Cadence script on Flow Blockchain you may use Flow Client Library if you have skills around Javascript or Flow Cli.

You will find a complete description for executing a script, and step by step tutorials on Flow Doc.

I have resolved it . see my PR to handle buyer address, handle nft Deposit event for every transaction by xiaods · Pull Request #492 · diadata-org/diadata · GitHub</ti. hope it will help someone.