0

Im implementing a NFT Marketplace. Where I created Two contracts and an Interface. One contract is Tokens.sol and anotherone is MarketPlace.sol In Tokens Contract I Implemented functions like Minting and publishing operations and in Marketplace contract I handled buy and sell and other operations and in Interface I declared some getter functions and a minting function. All the getter functions are working fine but the Mint function is not working. It is throwwing an VM Revert Error. Here are the code snippets. Tokens.sol

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

import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155URIStorage.sol";

contract Token is ERC1155URIStorage {
 using Counters for Counters.Counter;
 Counters.Counter private _tokenIds;
function createAd(string memory _uri,address receiver) external payable{
    _tokenIds.increment();
    uint256 newTokenId = _tokenIds.current();
    _mint(receiver, newTokenId, 1, "");
    _setURI(newTokenId, _uri);
    Ad memory newAd = Ad(
        newTokenId,
        _uri,
        receiver,
        new address[](0),
        false,
        0,
        0
    );
    ads[newTokenId] = newAd;
    emit AdCreated(newTokenId, _uri, receiver);
}

Itoken.sol

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

interface ITokens {
    struct Video {
        uint id;
        string URI;
        uint256 price;
        uint256 views;
        uint256 likes;
        uint256 dislikes;
        uint256 shares;
        uint256 comments;
        uint256 total;
        uint256 timestamp;
    }

function getVideo(uint _id) external view returns (Video memory);


function createAd(string memory _uri,address receiver) external payable;
}

marketplace.sol

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

import "./ITokens.sol";

contract MarketPlace  {
    ITokens private _tokens;

    constructor(address tokens) {
        _tokens = ITokens(tokens);
    }

    function getVideo(uint _id) external view returns (ITokens.Video memory) {
        return _tokens.getVideo(_id);
    }
    
    function mint() public returns(bool ){
        _tokens.createAd("kakakak");
        return true;
    }
}

and the error is

transact to MarketPlace.mint errored: VM error: revert.

revert
    The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send `should be less than your current balance.`
Debug the transaction to get more information.

1 Answer 1

0

As the error is saying, the createAd() method defined in the ITokens interface is a payable one, thus you need to also mark the mint() method defined in the MarketPlace contract as payable.

That's because you're calling the _tokens.createAd("kakakak"); method from the mint()one which needs to be able to receive value in order to pass it to the targeted one.

Update the mint() method as follows:

function mint() public payable returns(bool ){
    _tokens.createAd("kakakak");
    return true;
}
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.