setApprovalForAll no works in ERC1155

I'm trying to authorize the ERC1155 contract itself to sell NFTs from the owner. Therefore, I put true in setApprovalForAll
// contract address
// setApprovalForAll
I check in the getter that it returns true:

However, when I try to buy a token with another account, I get the alert that the above has not been done.


            function saleBronce() public payable 
        safeTransferFrom(owner(), msg.sender, 11,1,"");

So what is the result of the owner(), and for this function saleBronce(), which contract does it exist?

The owner is who deployed the contract 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4 in JavaScript VM. And approves the same contract that has been deployed

The function is in Contract ERC1155:

// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token//ERC1155/ERC1155.sol";
import "";

contract Contract1155 is ERC1155, Ownable {

uint256 public constant BRONCE = 11;
uint256 public constant PLATA = 12;
uint256 public constant ORO = 13;
uint256 public constant PLATINO = 14;
uint256 public constant DIAMANTE = 15;
uint256 public constant URANIO = 16;

mapping(uint => string) private _URIS;

constructor() ERC1155("{id}.json") 

    _mint(msg.sender, BRONCE, 7000000000, "");
        _mint(msg.sender, PLATA, 250, "");
            _mint(msg.sender, ORO, 50, "");
                _mint(msg.sender, PLATINO, 30, "");
                    _mint(msg.sender, DIAMANTE, 10, "");
                        _mint(msg.sender, URANIO, 1, "");


function mint(address account, uint256 id, uint256 amount) public onlyOwner 
            _mint(account, id, amount, "");

function burn(address account, uint256 id, uint256 amount) public 
    require(msg.sender == account);
    _burn(account, id, amount);

function setUniqueURI(uint _tokenId, string memory _uri) public onlyOwner 
     _URIS[_tokenId] = _uri;

 function uri(uint256 _tokenId) override public view returns (string memory) 

        if(bytes(_URIS[_tokenId]).length != 0) 
         return string(_URIS[_tokenId]);

        return string(

               function saleBronce() public payable 
        safeTransferFrom(owner(), msg.sender, 11,1,"");

Ohhhh, now, I know what do you mean exactly.

Assume: Alice deploys this contract: Contract1155, and Bob wants to call saleBronce() to get token from Alice. So now, when Alice calls Contract1155.setApprovalForAll(Contract1155_address, 1), this means Contract1155 has access to Alice token, and in the contract, it means: _operatorApprovals[Alice][Contract1155] = true, but when Bob calls Contract1155.saleBronce(), this will call the safeTransferFrom in the Contract1155, so it will check: _operatorApprovals[Alice][Bob], and obviously, this is false, so you got an error.

Maybe you can deploy a new contract contains the function saleBronce(), such as

contract Sale {
  function saleBronce() public payable {
    Contract1155.safeTransferFrom(xx);  // <<<--- Set the parameters as you want

And Alice approves to this contract.

Hope I have made myself clear.

Wow, how interesting. Therefore, it is not very optimal to place sales functions within the ERC721 or ERC1155 contracts. We need an intermediary contract for this, Crowdsale type. For that contract to become responsible for the commercial exchange. Not?

At least for me, I think this is not a good idea.

1 Like