2

I have started geth node (connect to ropsten testnet) on my local OSX system.
Command: geth --testnet --fast --bootnodes "enode://20c9ad97c081d63397d7b685a412227a40e23c8bdc6688c6f37e97cfbc22d2b4d1db1510d8f61e6a8866ad7f0e17c02b14182d37ea7c3c8b9c2683aeb6b733a1@52.169.14.227:30303,enode://6ce05930c72abc632c58e2e4324f7c7ea478cec0ed4fa2528982cf34483094e9cbc9216e7aa349691242576d552a2a56aaeae426c5303ded677ce455ba1acd9d@13.84.180.240:30303" --datadir data--ws --wsport 8546 --wsorigins "*" --rpc --rpcport 8545 --rpccorsdomain "*" --nodiscover --ws --wsport 8546

Geth node is not in block synchronization status

eth.syncing => false

Geth version : 1.8.11-stable

XXX-iMac:~ XXXXX$ geth version

Geth
Version: 1.8.11-stable
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10.3
Operating System: darwin
GOPATH=
GOROOT=/usr/local/Cellar/go/1.10.3/libexec

Web3 version:
"^1.0.0-beta.34"

Javascript code Running on Node environment

var web3 = new Web3(
    new Web3.providers.WebsocketProvider('ws://127.0.0.1:8546')
);

const contractAbi =[...];
const contractAddress = 'xxxxx';
const contractInstance = new web3.eth.Contract(contractAbi, contractAddress);
var res = contractInstance.methods.currentTicket.call((err, result) => {
    if (err) {
        console.log("error getting currentTicket", err);
    }
    else {
        console.log("success getting currentTicket", result);
    }
});

Here currentTicket is a variable containing an integer value. Nothing is called, I looked for several github issues ticket and nothing helped me! Any kind of help will be appreciate!

UPDATE1:

I looked for below web3 issues ticket, but nothing helped me!
https://github.com/ethereum/web3.js/issues/989
https://github.com/ethereum/web3.js/issues/1093

UPDATE2:

Getting on front end works well.

async function callAsync(f, params) {
  if (!params) params = [];
  return new Promise((resolve, reject) => {
    f(...params, function(err, res){
      if (err) reject(err);
      resolve(res);
    });
  });
}
const contract = web3.eth.contract(contractAbi);
const contractInstance = contract.at(contractAddress);
currentTicket = (await callAsync(contractInstance.currentTicket.call)).c[0];

1 Answer 1

0

After 10 hours brainstorming, I found the 2 issues on my implementation.
One is because of geth node synchronization.

I have checked web3.eth.getBlock(0) and it showed genesis block. And when try with web3.eth.getBlock(1), it printed null.

And also web3.eth.getCode('0xc351acdf577aef7d81d8cc7d750a081d6f07ad93') was returning "0x" which means geth node is not getting contract bytecode.

The other is calling contract function.
According to public documentation it is needed to convert from contractInstance.methods.currentTicket.call to contractInstance.methods.currentTicket().call.

Hope this helps others with headache!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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