web3js can not touch smart contract.
var id = dragoncore.getGenesNum();
has no error, but always return back 0, never changed.
-----------------------------web3js code -----------------------------
app.get("/createGenesTest", function(req, res) {
var _genes = "333";
dragoncore.createGenesTest.sendTransaction(_genes, _owner,{
from: web3.eth.coinbase
}, function(error, transactionHash){
if (!error) {
res.send(transactionHash);
console.log(transactionHash);
} else {
res.send("Error");
console.log(error.toString());
}
});
});
app.get("/getGenesTest", function (req,res) {
var id = dragoncore.getGenesNum().toString();
var details = dragoncore.getGenesTest.call(id);
res.send(details);
});
-----------------------------smart contract code -----------------------------
uint256[] public geneses;
function createGenesTest(uint256 _genes, address _owner) public returns(uint256 id) {
id = geneses.push(_genes);
dragonIndexToOwner[id] = _owner;
}
function getGenesTest(uint256 _id) public constant returns(address) {
return dragonIndexToOwner[_id];
}
function getGenesNum() public constant returns(uint256){
return 1000;
//return geneses.length;
}
I also upload source code here
Thank you for your help first!!!
createGeneTest
completes, that way you can inspect the transaction receipt to be sure your transaction has completed successfully. IfgetGenesesNum()
returns zero thencreateGenesTest
failed, or you are deploying an old contract that doesn't match your code (try recompiling, and redeploying). – Ismael Feb 6 '18 at 13:39