I'm trying to call my contract's mint function from the Truffle console, but I keep getting an error.

The code looks like this:

  function mint(uint256 _optionId, address _toAddress, uint256 _amount, bytes calldata _data) external nonReentrant() {
    return _mint(Option(_optionId), _toAddress, _amount, _data);

   * @dev Main minting logic implemented here!
  function _mint(
    Option _option,
    address _toAddress,
    uint256 _amount,
    bytes memory _data
  ) internal {
    require(_canMint(msg.sender, _option, _amount), "MyFactory#_mint: CANNOT_MINT_MORE");
    uint256 optionId = uint256(_option);
    MyCollectible nftContract = MyCollectible(nftAddress);
    uint256 id = optionToTokenID[optionId];
    if (id == 0) {
      id = nftContract.create(_toAddress, _amount, "", _data);
      optionToTokenID[optionId] = id;
    } else {
      nftContract.mint(_toAddress, id, _amount, _data);

From the Truffle console, I'm calling it like this:

MyLootBox.at("0xB4e6e1DAB3148187Eb220dbB1268CAB9F0aA4F15").then(contract => contract.mint(0, accounts[0], 1, web3.utils.toHex("")))

The above command is returning this error:

{ Error: Transaction: 0xfbc4e7ae429fcb7d7393e463c32f6f4248637bace256551ff2677dbba18e4093 exited with an error (status 0).     at PromiEvent (/Users/me/Code/crypto/cryptojanky/node_modules/truffle/build/webpack:/packages/contract/lib/promievent.js:9:1)
    at TruffleContract.mint (/Users/me/Code/crypto/cryptojanky/node_modules/truffle/build/webpack:/packages/contract/lib/execute.js:169:1)
    at MyLootBox.at.then.contract (evalmachine.<anonymous>:0:86)
    at process._tickCallback (internal/process/next_tick.js:68:7)
   'Transaction: 0xfbc4e7ae429fcb7d7393e463c32f6f4248637bace256551ff2677dbba18e4093 exited with an error (status 0). \n     Please check that the transaction:\n     - satisfies all conditions set by Solidity `require` statements.\n     - does not trigger a Solidity `revert` statement.\n',

For some more context, I'm working off of OpenSea's example contracts.

Would really appreciate some help! Thanks in advance.

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.