How to Transfer erc1155 Token After Payment With erc20 Token

I’m building a game with erc1155 tokens as collectables as well as an erc20 token as in-game currency. Both are essentially standard OpenZeppelin contracts. Down the road, I’d like to create a third smart contract that transfers ownership of one specific 1155 once a user has burned / transferred a specified amount of erc20 to pay for the collectable. In this case, the specific 1155 token for sale would have already been minted and in the contract owner’s wallet address.

Is it possible to do this through a third contract that would listen for a transfer of the erc20 and then access the wallet holding the 1155 to initiate a safeTransferFrom? And if so, I’m not sure if I need to write additional functionality into the standard 20 & 1155 contracts before deploying. If anyone could point me in the right direction I would appreciate it.

Did you find answer to your question? Currently struggle with it too)

Yes the solution to this is actually pretty straightforward. You need to create a smart contract specifically for this purpose. The key is to import your erc1155 contract into the new one like

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
ERC1155 public your1155 = ERC1155(address);

so that you can access its safeTransferFrom function. Then the main function in this new contract will (e.g) require (msg.value == yourPrice and whatever else it needs to do, then finally your1155.safeTransferFrom() to the sender.

You'll also need to authorize (from the erc1155) this new contract to send items from the account that owns them (which is obviously dangerous) so be sure the functions that send them only do so under your intended circumstances.