TransWikia.com

Web3js can not touch smart contract, always return 0

Ethereum Asked by Will_Z on November 17, 2021

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

One Answer

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()

Answered by Pierre Label on November 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP