1

I deployed a contract which has a function recordData(bizname, id) function. I have a expressjs api layer. I want to make sure that when the function is called from this api layer using web3 the transaction is completed

contract.recordData('abc', 123, {from: '0x123...'})
.once('transactionHash', function(hash){ ... })
.once('receipt', function(receipt){ ... })
.on('confirmation', function(confNumber, receipt){ ... })
.on('error', function(error){ ... })
.then(function(receipt){
    // will be fired once the receipt its mined
});

when i run this i get TypeError: .once is not a function.

  • Which framework are you using? You are using once but it doesn't seem to be a standard function for javascript. – Ismael Jul 10 '17 at 16:33
  • hello @ismael I am using a library called web3js web3js.readthedocs.io/en/1.0/callbacks-promises-events.html – shresthaal Jul 10 '17 at 16:43
  • 1
    It says in the top of the page This documentation is work in progress and web3.js 1.0 is not yet released! You can find the current documentation for web3 0.x.x at github.com/ethereum/wiki/wiki/JavaScript-API. – Ismael Jul 10 '17 at 16:52
  • 2
    Hi @Ismael - I'd be tempted to add your comment as an answer, just to make it more obvious to anyone who has similar issues, and doesn't bother to read your comments (as well as the wiki page... ). – Richard Horrocks Jul 11 '17 at 18:37
1

It says in the top of the page http://web3js.readthedocs.io/en/1.0/callbacks-promises-events.html:

This documentation is work in progress and web3.js 1.0 is not yet released! You can find the current documentation for web3 0.x.x at github.com/ethereum/wiki/wiki/JavaScript-API.

It is unfortunate but the only documentation available in readthedocs is for the unreleased 1.0 version, hopefully it will released soon. But until then the documentation for 0.xx is at https://github.com/ethereum/wiki/wiki/JavaScript-API.

1

If you're using web3 non-1.0, you can add a waitForReceipt() function to check the receipt every 1 second, which is also taught in here:

contract.myFunction(arg1, arg2, { from: ... })
.then((txhash) => {
  waitForReceipt(txhash.tx, () => {
    .. to something ..
  })
})
function waitForReceipt(txhash, callback) {
  console.log(txhash)
  this.state.web3.eth.getTransactionReceipt(txhash, (error, receipt) => {
    if (error) {
      console.log(error)
    }
    if (receipt !== null) {
      if (callback)
        callback(receipt)
    } else {
      // Try again in 1 second
      window.setTimeout(function () {
        waitForReceipt(txhash, callback)
      }, 1000)
    }
  })
}

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.