Describe the bug I am trying to call the public variable "workCount" from a smart contract using web3
Steps to reproduce:
const work = new web3.eth.Contract(ABI,Address)
const workCount = await work.methods.workCount().call()
Expected behavior
I am expecting these two lines of code to return the value of workCount
Actual behavior:
Once I run the application I get the following error:
Uncaught (in promise) TypeError: work.methods.workCount is not a function
if I change the code to the following:
const workCount = await work.methods.workCount.call()
then this error is shows up:
Uncaught (in promise) TypeError: Cannot read property 'call' of undefined
Contract Code:
pragma solidity ^0.5.0;
contract workReg {
uint public workCount = 0;
struct Work {
uint id;
string authorName;
string workType;
string description;
uint amount;
}
mapping(uint => Work) public works;
constructor() public {
createWork("Heba","Book", "IP blockchain book", 100);
}
function createWork(string memory _authorName, string memory _workType, string memory _description, uint _amount ) public {
workCount ++;
works[workCount] = Work(workCount, _authorName,_workType, _description, _amount);
}
function getID() view public returns(uint){
return works[workCount].id;
}
function getworkType() view public returns(string memory){
return works[workCount].workType;
}
function getdescription() view public returns(string memory){
return works[workCount].description;
}
function getAmount() view public returns(uint){
return works[workCount].amount;
}
}