I have two contracts, one that issues a token and gives the approval for the Marketplace contract. And the other, Marketplace, allows you to put a token for sale and sell the token.

My problem happens in the following scenario: User A issues the token and gives permission to the Marketplace User A puts the token up for sale through the Marketplace User B buys the token through the Marketplace User B puts the token for sale -> Error because the Marketplace doesn't have the approval

That's why I want to give the approval for the Marketplace in the same sales function, however, it's giving an error.

function buyItem(uint256 id) 
    external {
      require(msg.value >= itemsForSale[id].price, "Not enough funds sent");
      require(msg.sender != itemsForSale[id].seller);

      itemsForSale[id].isSold = true;
      activeItems[itemsForSale[id].tokenId] = false;
      token.safeTransferFrom(itemsForSale[id].seller, msg.sender, itemsForSale[id].tokenId);
      // token.approve(address(this), itemsForSale[id].tokenId, {from: msg.sender}); // I want this line to work

      emit itemSold(id, msg.sender, itemsForSale[id].price);
  • 2
    the only one who can approve is the owner of the EOA. There is new stuff about approvals however, called Self Permit , which allows signed approvals. Not sure if it will work in your case but you might give it an investigation, the EIP proposal is 2612
    – Nulik
    Jul 17, 2021 at 2:07

2 Answers 2


same as you use approve() to approve the spending of a particular amount tokens by a particular address (spender here).

for example :

approve(contract_address, amount)

then in contract, you can call transferFrom() method in the contracts function as shown below:

function sellToken() public {
    transferFrom(sender, recipient, amount)

Let me know if this works for you or not.


If you can modify the token contract it should be possible to give authorization to some addresses to 'approve' tokens on behalf of the users.

OpenSea does something similar in isApprovedForAll from ERC721Tradable.sol.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.