0
votes

I am using web3.js v1.0 with solidity ^0.4.17 with Ganache v1.1.0. I am trying to call a send transaction and it fails with the error message below.

Returned error: Error: Error: [ethjs-query] while formatting outputs from RPC 'undefined' for method 'sendRawTransaction' Error: [ethjs-format] hex string 'undefined' must be an alphanumeric 66 utf8 byte hex (chars: a-fA-F) string, is 0 bytes

MyContract.sol

  function createStarCard(string name, uint price) public {
    require(msg.sender == owner);

    uint starCardId = starCards.push(StarCard(name, price));
    starCardIdToOwner[starCardId] = owner;
  }

App.js

  createStarCard = ({ name, price }) => {
    window.web3.eth.getAccounts().then((accounts) => {
      this.state.ContractInstance.methods.createStarCard(name, price).send({
        from: accounts[0],
        gas: 300000,
      }).then((receipt) => {
        console.log(receipt)
      }).catch((err) => {
        console.log(err.message) <-- Caught error message
      })
    })
  }

Google search results with the error message pointed me to the following issues, but they weren't helpful in my case:

Update: sharing my constructor for App.js

  constructor(props) {
    super(props)

    if (typeof window.web3 !== 'undefined') {
      this.web3Provider = window.web3.currentProvider;
    } else {
      console.log("Use Ganache web3")
      this.web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
    }

    window.web3 = new Web3(this.web3Provider);

    const contractAddress = "0x1bdaf0cd259887258bc13a92c0a6da92698644c0"
    const ContractInstance = new window.web3.eth.Contract(Abi, contractAddress);

    this.state = {
      ContractInstance,
    }
  }
2
How do you create this.state.ContractInstance? What does this.state.ContractInstance.address return?gaiazov
@gaiazov I updated the question with the information. It has _address property instead of address and the value is the contract's address.Maximus S

2 Answers

1
votes

It looks like the problem is with the Ganache mac app. I solved this by using ganache-cli instead.

0
votes

I solved this by reinstalling Metamask.