dabit3 / polygon-ethereum-nextjs-marketplace

A full stack digital marketplace running on Ethereum with Polygon & Next.js
MIT License
1.3k stars 878 forks source link

Do not understand the logic of transfering msg.value #42

Open yeuyeuh opened 2 years ago

yeuyeuh commented 2 years ago

Hi,

I'm trying to learn solidity. I think I misunderstood something.

Here you said that : https://github.com/dabit3/polygon-ethereum-nextjs-marketplace/blob/c5a35262a430a6da1f9cd57cc731f227b5469716/contracts/NFTMarketplace.sol#L113

but just before you said that the seller is address(0) : https://github.com/dabit3/polygon-ethereum-nextjs-marketplace/blob/c5a35262a430a6da1f9cd57cc731f227b5469716/contracts/NFTMarketplace.sol#L109

So what I understand is that instead of transfering the msg.value to the old owner, you transfer it to address(0). Do you want to do that or I didn't understand it correctly ?

Thank you, Inaki

ghost commented 2 years ago

I think that's wrong when i buy nft the ethereum value dissapear into thin air becasue of seller address becoming address(0) but after moving idToMarketItem[tokenId].seller = payable(address(0)); after payable(idToMarketItem[tokenId].seller).transfer(msg.value); its working perfectly.

yeuyeuh commented 2 years ago

Ok thank you ! How do you check that with the HardHat test? I tried to had these 2 lines but I get "0" :

    const buyerBalance = await nftMarketplace.balanceOf(buyerAddress.address);
    console.log('buyerBalance: ', buyerBalance.toString())

So I think that balanceOf() is not the right function. Do you have a suggestion?

ghost commented 2 years ago

i have no clue about that i am learning myself and playing with it using truffle >.> I am basically experimenting it for my use,so i wanted to move out of hardhat.