safeTransferFrom does not transfer etherium to the target ERC-721

0 votes

I create a contract with ERC-721 and I try to transfer the token with money. I am using web3.js and openzeppelin. So, The transaction is confirmed, but no money is sent to the target wallet.

Here is the contract buy function;

function buy(uint256 _tokenId) public payable { address buyer = msg.sender; require(_isApprovedOrOwner(msg.sender, _tokenId), "ERC721: transfer caller is not owner nor approved"); approve(buyer, _tokenId); safeTransferFrom(ownerOf(_tokenId), buyer, _tokenId); }

And here is web3.js :

const buy = (2,2) => { //Token ID: 2 //Price: 2 ether contract.methods.buy(2).send({ from: account, value: web3.utils.toWei(2, 'ether') }) }

Please help me. Thank you.

Apr 7, 2022 in Blockchain by Soham
• 9,710 points
967 views

1 answer to this question.

0 votes

I changed my contract buy function like this;

function buy(uint256 _tokenId, address payable _owner, uint256 _amount) public payable { address payable buyer = msg.sender; address payable owner = _owner; //<-- *payable (important) _transfer(ownerOf(_tokenId), buyer, _tokenId); owner.transfer(_amount); //<--- this function send the amount to the token owner. }

This helped in solving the problem!

answered Apr 11, 2022 by Rahul
• 9,680 points

Related Questions In Blockchain

+1 vote
1 answer

How does a miner get to know that a transaction is verified by all the nodes?

Contrary to the popular belief, it is ...READ MORE

answered Mar 27, 2018 in Blockchain by Johnathon
• 9,090 points
2,825 views
0 votes
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,914 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
45,198 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,443 views
0 votes
1 answer

safeTransferFrom does not transfer etherium to the target. ERC-721

I changed my contract buy function like ...READ MORE

answered Apr 7, 2022 in Blockchain by Rahul
• 9,680 points

edited Mar 13, 2023 by Gunashree 2,047 views
0 votes
1 answer

Where does Hyperledger fabric store the public key and private key of the user?

It signs the transaction (eg. initiated by ...READ MORE

answered Mar 24, 2022 in Blockchain by Rahul
• 9,680 points
601 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP