I have the following solidity contract code.
pragma solidity ^0.4.18;
contract Coursetro {
string fName;
uint age;
function setInstructor(string _fName, uint _age) public {
fName = _fName;
age = _age;
}
function getInstructor() public constant returns (string, uint) {
return (fName, age);
}
}
Running it on remix ide online it works very well and can set Instructor and get Instructor also, however when I try the two functions from a UI using web3js am not sure if it works since the
Coursetro.setInstructor("Name",34)
in console of browser displays the following in terminal "Where the testrpc is running"
Transaction: 0x58c224f215b33ccf5cc89aa63801c602dd1223726fcd297c7ca2ccf7295f17da Gas usage: 22360 Block Number: 5 Block Time: Thu Dec 14 2017 15:29:22 GMT+0000 (UTC)
but on running
Coursetro.getInstructor()
returns
(2) ["", e]
And from where am learning from the tutor says it should return
(2) ["Name", 34]
Here is my js code which is in an index.html file but wont include the html content since I do not see its relevance
<script>
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
web3.eth.defaultAccount = web3.eth.accounts[0];
var CoursetroContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"_fName","type":"string"},{"name":"_age","type":"uint256"}],"name":"setInstructor","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getInstructor","outputs":[{"name":"","type":"string"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]);
var Coursetro = CoursetroContract.at('0x51b126b8d96feaa77cef03fb0e64f8ec45339958');
console.log(Coursetro);
</script>
Mind you this is not the only one, I have tried another contract for voting and it works perfectly on the remix ide online but results fail on the web3 js UI part, suggesting its something am doing wrong but I cant seem to know what it is?