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 "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Strings.sol";
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("https://raw.githubusercontent.com/Cainuriel/metadatas/main/{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(
abi.encodePacked(
"https://raw.githubusercontent.com/Cainuriel/metadatas/main/",
Strings.toString(_tokenId),
".json"
)
);
}
function saleBronce() public payable
{
safeTransferFrom(owner(), msg.sender, 11,1,"");
}
}
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
}
}
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?