Currently, I'm working on a project to mint an ERC1155 token. but I need to make a transfer before the mint. Imagine minting this NFT, the user should pay $10, so I have to convert $10 to the ETH amount after that transfer it to the owner of ERC1155, then mint it. I'm using solidity.
pragma solidity ^0.8.27;
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import {ERC1155Burnable} from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
import {ERC1155Pausable} from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Pausable.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
contract Cafe3 is ERC1155, Ownable, ERC1155Pausable, ERC1155Burnable {
uint256 public mintRate;
uint256 public tokenUrlRate;
mapping (uint256 => string) private _tokenURIs;
constructor()
ERC1155("")
Ownable(msg.sender)
{
mintRate = 0.0001 ether;
tokenUrlRate = 0.00001 ether;
}
function setMintRate(uint256 _rate) public onlyOwner{
mintRate = _rate;
}
function setTokenUrlRate(uint256 _rate) public onlyOwner{
tokenUrlRate = _rate;
}
function setURI(string memory newuri) public onlyOwner {
_setURI(newuri);
}
function uri(uint256 tokenId) override public view returns (string memory) {
return(_tokenURIs[tokenId]);
}
function setTokenUri(uint256 tokenId, string memory tokenURI) public payable
{
require(msg.sender.balance >= tokenUrlRate, "not enough ether sent for uri token");
_tokenURIs[tokenId] = tokenURI;
}
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function mint(address payable account, uint256 id, uint256 amount, bytes memory data)
payable public
{
uint256 cost = mintRate * amount;
require(msg.sender.balance >= cost, "not enough ether sent");
address owner = owner();
(bool success,) = owner.call{value: cost}("");
require(success, "Payment failed.");
_mint(account, id, amount, data);
}
// The following functions are overrides required by Solidity.
function _update(address from, address to, uint256[] memory ids, uint256[] memory values)
internal
override(ERC1155, ERC1155Pausable)
{
super._update(from, to, ids, values);
}
}