Hello, I have a problem with the code from the lecture. I copied it from Filip’s github page. The only modification I made is added some gas to contractInstance. Pressing "Get Data " button gives me Uncaught (in promise) Error. Looks like problem somewhere in contractInstance.methods.getPerson().call() inside fetchAndDisplay function. In other words, I cant get any data after transaction have been submitted. Need some help, please.
var web3 = new Web3(Web3.givenProvider);
var contractInstance;
$(document).ready(function () {
window.ethereum.enable().then(function (accounts) {
contractInstance = new web3.eth.Contract(
window.abi,
"0xdA5E6a762993FD52fB6881d0482E990ec21460d9",
{ from: accounts[0], gas: 400000 }
);
});
$("#get_data_button").click(fetchAndDisplay);
$("#add_data_button").click(inputData);
});
function inputData() {
var name = $("#name_input").val();
var age = $("#age_input").val();
var height = $("#height_input").val();
contractInstance.methods
.createPerson(name, age, height)
.send({ value: web3.utils.toWei("1", "ether") })
.on("transactionHash", function (hash) {
console.log("tx hash");
})
.on("confirmation", function (confirmationNumber, receipt) {
console.log("conf");
})
.on("receipt", function (receipt) {
console.log(receipt);
});
}
function fetchAndDisplay() {
contractInstance.methods
.getPerson()
.call()
.then(function (res) {
displayInfo(res);
});
}
function displayInfo(res) {
$("#name_output").text(res["name"]);
$("#age_output").text(res["age"]);
$("#height_output").text(res["height"]);
}
inpage.js:1 MetaMask: 'ethereum.enable()' is deprecated and may be removed in the future. Please use the 'eth_requestAccounts' RPC method instead.
For more information, see: https://eips.ethereum.org/EIPS/eip-1102
enable @ inpage.js:1
(anonymous) @ main.js:59
e @ jquery-3.4.1.min.js:2
t @ jquery-3.4.1.min.js:2
setTimeout (async)
(anonymous) @ jquery-3.4.1.min.js:2
c @ jquery-3.4.1.min.js:2
fireWith @ jquery-3.4.1.min.js:2
fire @ jquery-3.4.1.min.js:2
c @ jquery-3.4.1.min.js:2
fireWith @ jquery-3.4.1.min.js:2
ready @ jquery-3.4.1.min.js:2
B @ jquery-3.4.1.min.js:2
main.js:78 tx hash
main.js:84 {transactionHash: "0xcff6d5b7a452b546204fba2cb7e68e8f4af9e134b9bcb88f7f1f2e22895eac2c", transactionIndex: 0, blockHash: "0x9fdc759f697ee740d2f39cc2ace8cd0ad9f724a0c1157eb0e326b98205edb6f8", blockNumber: 25, from: "0xb375f7662ed7391ae5975aabba67aac1b35cc2d6", …}
web3.min.js:1 Uncaught (in promise) Error: Returned values aren't valid, did it run Out of Gas?
at i.decodeParameters (web3.min.js:1)
at o._decodeMethodReturn (web3.min.js:1)
at _.outputFormatter (web3.min.js:1)
at _.formatOutput (web3.min.js:1)
at u (web3.min.js:1)
at web3.min.js:1
at s._handle (inpage.js:17)
i.decodeParameters @ web3.min.js:1
o._decodeMethodReturn @ web3.min.js:1
outputFormatter @ web3.min.js:1
_.formatOutput @ web3.min.js:1
u @ web3.min.js:1
(anonymous) @ web3.min.js:1
_handle @ inpage.js:17
Promise.then (async)
fetchAndDisplay @ main.js:91
dispatch @ jquery-3.4.1.min.js:2
v.handle @ jquery-3.4.1.min.js:2