I’m creating my first contract with Truffle and Ganache, and after being able to create several ERC721 tokens, I’m getting this error in create function, that I can’t figure out why it’s happening to me. I have searched and tried different things but I can’t find a solution. If anyone has any suggestions, it would be of great help to me. This is my contact.

// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;

import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/cryptography/ECDSAUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol";

contract Kargain is ERC721BurnableUpgradeable, AccessControlUpgradeable {
    using SafeMathUpgradeable for uint256;
    using ECDSAUpgradeable for bytes32;

    uint256 private constant COMMISSION_EXPONENT = 4;
    uint256 private _tokenCurrentId;
    address payable private _platformAddress;
    uint256 private _platformCommission;

    mapping (uint => Token) private _tokens;
    mapping (uint256 => address payable) private _offers;
    mapping (uint256 => uint256) private _offers_closeTimestamp;

    event TokenCreated(address indexed creator, uint256 indexed tokenId);
    event OfferReceived(address indexed payer, uint tokenId);
    event OfferAccepted(address indexed payer, uint tokenId);
    event OfferRejected(address indexed payer, uint tokenId);

    struct Token {
        address owner;
        uint amount;
        bool isValue;
        bool offer;
        bool offerAccepted;

    struct TransferType {
        address from;
        address to;
        uint256 tokenId;
        uint256 amount;

    modifier onlyAdmin(){
        require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "Kargain: Caller is not a admin");

    function initialize(address payable platformAddress_, uint256 platformCommissionPercent_)
    initializer public {
        _platformAddress = platformAddress_;
        _platformCommission = platformCommissionPercent_;
        __ERC721_init("Kargain", "KGN");
        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);

    function platformCommission() public view returns(uint256){
        return _platformCommission;

    function setPlatformCommission(uint256 platformCommission_) public onlyAdmin {
        _platformCommission = platformCommission_;

    function platformAddress() public view returns(address payable){
        return _platformAddress;

    function setPlatformAddress(address payable platformAddress_) public onlyAdmin {
        _platformAddress = platformAddress_;

    function create(address payable creator, uint256 tokenId, uint256 amount) public payable{
        require(_exists(tokenId), "Kargain: Id for this token already exist");
        super._mint(creator, _tokenCurrentId);
        _tokens[tokenId].owner = creator;
        _tokens[tokenId].isValue = true;
        _tokens[tokenId].amount = amount;
        emit TokenCreated(creator, tokenId);

    function _exists(uint256 _tokenId) internal view override returns (bool) {
        address owner = _tokens[_tokenId].owner;
        return owner != address(0);

    function purchaseToken(address payable payer, uint256 _tokenId) public payable {
        require(_exists(_tokenId), "Kargain: Auction for this token not exist");
        require(_tokens[_tokenId].offer, "Kargain: An offer is pending");
        require(_tokens[_tokenId].offerAccepted, "Kargain: Offer was accepted");
        require(msg.value != _tokens[_tokenId].amount, "Kargain: the offer amount is invalid");
        address payable refundAddress = _offers[_tokenId];
        _offers[_tokenId] = payer;
        emit OfferReceived(msg.sender, _tokenId);



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.