0

Im trying to create a basic product list/buy/sell form locally. While trying to run a transaction on Metamask I get a console error with this stack:

MetaMask - RPC Error: [ethjs-query] while formatting outputs from RPC '{"value":{"code":-32603,"data":{"message":"VM Exception while processing transaction: revert","code":-32000,"data":{"0x0d09d04fe1bb5ae95f317da347e180514d3e7bbbe71998eb60e778b986b95afb":{"error":"revert","program_counter":48,"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"}}}}' 

I am running on localhost I have started restarting everything - Truffle, Ganache, Chrome, the App - but in vain. Any ideas?

Transaction Function: I am trying to add a product. Heres my smart contract method :

function createProduct(string memory _name, uint _price) public { 
 //Make sure parameters are correct 
 require(bytes(_name).length > 0); 
 require(_price > 0); 
 //Increment Product Count productCount++; 
 //Create the product 
 products[productCount] = Product(productCount, _name, _price, 
  msg.sender, false); 
 //Trigger an event 
 emit ProductCreated(productCount, _name, _price, msg.sender, false); }

Heres how Im calling it within my app:

createProduct(name, price) {
    this.setState({ loading: true });
    this.state.marketplace.methods.createProduct(name, price).send({ from:this.state.account })
      .once('receipt', (receipt) => {
        this.setState({ loading: false });
      })
  }
4
  • The error is in the contract. Post your transaction function Oct 27 at 20:35
  • I am trying to add a product. Heres my smart contract method : function createProduct(string memory _name, uint _price) public { //Make sure parameters are correct require(bytes(_name).length > 0); require(_price > 0); //Increment Product Count productCount++; //Create the product products[productCount] = Product(productCount, _name, _price, msg.sender, false); //Trigger an event emit ProductCreated(productCount, _name, _price, msg.sender, false); }
    – shrew-tea
    Oct 28 at 6:04
  • Heres how Im calling it within my app: createProduct(name, price) { this.setState({ loading: true }); this.state.marketplace.methods.createProduct(name, price).send({ from:this.state.account }) .once('receipt', (receipt) => { this.setState({ loading: false }); }) }
    – shrew-tea
    Oct 28 at 6:06
  • @shrew-tea What's products? There's nothing obvious, perhaps you have the wrong address, abi, or using an old copy of the contract.
    – Ismael
    Oct 31 at 7:51

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.