0

I'm working on a smart contract and when I try to call my contract methods from the truffle console, I am getting a revert error. I can't figure out why this is happening. The contract is deployed to a local ganache network and the smart contract and revert error below. Any insight on this is very appreciated.

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";

contract FloodFill is ERC721Enumerable, Ownable {

    uint256 public maxTokens;
    mapping(string => string) private tokenColor;


    constructor(string memory name, string memory symbol, uint256 maxNftSupply) ERC721(name, symbol) {
        maxTokens = maxNftSupply;
    }

    function setTokenColor(string memory tokeId, string memory color) public onlyOwner{
        tokenColor[tokeId] = color;
    }

    function returnTokenColor(string memory tokeId) public view returns (string memory){
        return tokenColor[tokeId];
    }

}

I get a revert error when I try to call either method. In my full contract, I have no problem calling the other contract methods. The specific error I get with the following truffle console command is below

truffle console> instance.setTokenColor('1a', 'blue', {from: accounts[0]}) 


Uncaught Error: Returned error: VM Exception while processing transaction: revert
    at evalmachine.<anonymous>:0:10
    at sigintHandlersWrap (vm.js:274:12)
    at Script.runInContext (vm.js:142:14)
    at runScript (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:364:1)
    at Console.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:379:1)
    at bound (domain.js:416:15)
    at REPLServer.runBound [as eval] (domain.js:427:12)
    at REPLServer.onLine (repl.js:819:10)
    at REPLServer.emit (events.js:375:28)
    at REPLServer.emit (domain.js:470:12)
    at REPLServer.Interface._onLine (readline.js:364:10)
    at REPLServer.Interface._line (readline.js:700:8)
    at REPLServer.Interface._ttyWrite (readline.js:1045:14)
    at REPLServer.self._ttyWrite (repl.js:912:9) {
  data: {
    '0xfef3a53aba0054d8577d992d87fbbdbc8f981847079fc8cfbd059c214ee130e6': { error: 'revert', program_counter: 466, return: '0x' },
    stack: 'RuntimeError: VM Exception while processing transaction: revert\n' +
      '    at Function.RuntimeError.fromResults (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/utils/runtimeerror.js:94:13)\n' +
      '    at BlockchainDouble.processBlock (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/blockchain_double.js:627:24)\n' +
      '    at runMicrotasks (<anonymous>)\n' +
      '    at processTicksAndRejections (internal/process/task_queues.js:93:5)',
    name: 'RuntimeError'
  },
  hijackedStack: 'Error: Returned error: VM Exception while processing transaction: revert\n' +
    '    at Object.ErrorResponse (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-core-helpers/lib/errors.js:28:1)\n' +
    '    at /usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-core-requestmanager/lib/index.js:302:1\n' +
    '    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:107:1\n' +
    '    at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-providers-http/lib/index.js:98:1)\n' +
    '    at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)\n' +
    '    at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)\n' +
    '    at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:318:1)\n' +
    '    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:289:47)\n' +
    '    at IncomingMessage.emit (events.js:387:35)\n' +
    '    at IncomingMessage.emit (domain.js:532:15)\n' +
    '    at endReadableNT (internal/streams/readable.js:1317:12)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:82:21)'
}

1 Answer 1

0

Not sure it may help you, but I'm getting the same when the sender is not the owner, and I see you have the "onlyOwner" modifier on your function.

Can you try and remove the modifier and see if the transaction goes through? (or make sure you're calling the contract from the actual owner address?).

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.