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) {
            } else {

app.get("/getGenesTest", function (req,res) {
    var id = dragoncore.getGenesNum().toString();
    var details = dragoncore.getGenesTest.call(id);

-----------------------------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!!!

  • web3@0.19.0 or web3@0.16.0 is the same as above. – Will_Z Feb 6 '18 at 0:46
  • I'd suggest to trigger an event when createGeneTest completes, that way you can inspect the transaction receipt to be sure your transaction has completed successfully. If getGenesesNum() returns zero then createGenesTest 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

I see your method dragoncore.getGenesNum returns an integer. So the error message makes sense to me. I propose you try in your app.js line 97 either :

  • var id = dragoncore.getGenesNum.call()
  • var id = dragoncore.getGenesNum()
  • var id = dragoncore.getGenesNum() comes back alway 0, never changed. – Will_Z Feb 6 '18 at 0:42
  • frustrated two days... – Will_Z Feb 6 '18 at 0:55
  • "Non-constant solidity functions can not return a value" --- ethereum.stackexchange.com/questions/21209/… , should I use event insteadly? @Pierre Label – Will_Z Feb 6 '18 at 2:51
  • Yes you should try with event instead though your function is constant so this should not apply to you. – Pierre Label Feb 6 '18 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.