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:
- https://github.com/MetaMask/metamask-extension/issues/1870
- https://ethereum.stackexchange.com/questions/23679/callback-contain-no-result-error-error-ethjs-query-while-formatting-outputs
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,
}
}
this.state.ContractInstance
? What doesthis.state.ContractInstance.address
return? – gaiazov_address
property instead ofaddress
and the value is the contract's address. – Maximus S