0

Created a very simple Meteor app to display the current block number using ethereum:block.

Problem: Even though the current block number is displayed when the page loads, it does not update both on the page and when running EthBlocks.latest.number

The valaue of EthBlock.latest.number updates only when the page is refreshed.

Shouldnt the variable EthBlocks.latest.number updates whenever geth detects a new block?

client/currentBlock.html

<head>
  <title>myDapp</title>
</head>

<body>
  {{> currentBlock}}
</body>

<template name="currentBlock">
  <h1>Current Block</h1>
  <p> {{ currentBlock }} </p>
</template>

client/currentBlock.js

    import { Template } from 'meteor/templating';
    import { ReactiveVar } from 'meteor/reactive-var';

    import './currentBlock.html';

    Template.currentBlock.onCreated(function helloOnCreated() {
      EthBlocks.init();
    });

    Template.currentBlock.helpers({
      currentBlock() {
        return EthBlocks.latest.number;
      }
    });

client/init.js

if (typeof web3 == 'undefined')
    web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));

Geth is started using

geth --rpc --rpccorsdomain "http://localhost:3000"
2
  • does it work if you refresh your browser? – thefett Oct 14 '17 at 18:18
  • @thefett Yes it does update when I refresh the browser. – Nyxynyx Oct 14 '17 at 18:31
0

I think this answers your question: Automatically update account balance with web3.js without polling

To summarize, unfortunately an intuitive system that just has things update isn't quite there yet, but you can use filters to listen for a new block

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.