0

I wrote a contract which I will deposit eth in and this contract should mint on another contract, but it does not seem to work. Why?

Here is my code:

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

import "@openzeppelin/contracts/access/Ownable.sol";
import "hardhat/console.sol";

abstract contract BH {
    function mintB(uint256 _numberOfButts) external virtual payable;

    function totalSupply() public view virtual returns (uint256);

    function bOfOwner(address _owner)
        external
        view
        virtual
        returns (uint256[] memory);

    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual;
}

contract BHFreeMint is Ownable {
    BH private bla;
    address wallet = "";

    uint256 public _mintPrice = 0.03 ether;

    mapping(address => bool) private _fMintList;
    mapping(address => uint256) private _fMintListClaimed;
    mapping(address => uint256) private _fMintAllowed;

    bool public _freeMintActive = true;

    constructor(address dependedContract) {
        butts = BH(dependedContract);
    }

    //modifiers
    modifier onlyFreeMinters() {
        require(
            _fMintList[_msgSender()],
            "You are not on the free mint list"
        );
        _;
    }

    function addToFreeList(
        address[] calldata addresses,
        uint256[] calldata allowed
    ) external onlyOwner {
        for (uint256 i = 0; i < addresses.length; i++) {
            require(addresses[i] != address(0), "Address can not be null");

            _fMintList[addresses[i]] = true;

            _fMintListClaimed[addresses[i]] > 0
                ? _freeMintListClaimed[addresses[i]]
                : 0;

            _fMintAllowed[addresses[i]] = allowed[i];
        }
    }

    function setPrice(uint256 _price) external onlyOwner {
        _mintPrice = _price;
    }

    function onFreeMintList(address addr) external view returns (bool) {
        return _fMintList[addr];
    }

    function freeMintsLeft(address addr) external view returns (uint256) {
        return
            _fMintList[addr]
                ? _fMintAllowed[addr] - _fMintListClaimed[addr]
                : 0;
    }

    function setFreeMintState(bool val) external onlyOwner {
        _freeMintActive = val;
    }

    function removeFromFreeMintList(address[] calldata addresses)
        external
        onlyOwner
    {
        for (uint256 i = 0; i < addresses.length; i++) {
            require(addresses[i] != address(0), "Address can not be null");
            _fMintList[addresses[i]] = false;
        }
    }

    function _mint(address _to, uint256 _b) internal {
        bla.mintB{value: _mintPrice * _b}(_b);
        uint256[] memory boo = butts.bOfOwner(address(this));
        require(boo.length > _b, "Not enough butts minted");
        for (uint256 i = 0; i < _b; i++) {
            b.transferFrom(address(this), _to, boo[i]);
        }
    }

    function gift(address _to, uint256 _b) external onlyOwner {
        _mint(_to, _b);
    }

    function fMint(uint256 _numberOfB) external onlyFreeMinters {
        require(_fMintActive, "Free Mint is not active");
        require(
            butts.totalSupply() + _numberOfB <= 8888,
            "Purchase exceeds max supply"
        );
        require(
            _fMintListClaimed[_msgSender()] + _numberOfB <=
                _fMintAllowed[_msgSender()],
            "Purchase exceeds max allowed"
        );

        _fMintListClaimed[_msgSender()] += _numberOfB;
        _mint(_msgSender(), _numberOfB);
    }

    function withdraw() public onlyOwner {
        uint256 _amount = address(this).balance;
        require(payable(wallet).send(_amount));
    }

    fallback() external payable {
        // custom function code
    }

    receive() external payable {
        // custom function code
    }
}
2
  • Please post only the relevant part of the code, and pinpoint where your problem is and what is the error Sep 24 at 4:43
  • Without the code for the mintB we can't say anything.
    – Ismael
    Sep 25 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.