Basically, i want get the callback result of first method to get each index value in pass it to the second method to scan this value, in this case is an ethereum transaction to get the input value. The problem is the callback named "cb" isn't triggered.


var tx;

web3.eth.getBlock(6339515, function(err, result){
    for(var i = 0; i <= result.transactions.length; i++){
        tx = result.transactions[i];
        .then(function() {} )
        .catch(function(error) {
            console.log('error: \n' + err);

async function getInputTransaction(tx) {
    web3.eth.getTransaction(tx, function(err, cb){
        console.log('got here');
        let decodeInput = web3.utils.hexToAscii(cb.input);
        decodeInput = decodeInput.split("_").pop();
            console.log('\nInput decoded: ' + '\u001b[1;32m' + decodeInput + '\u001b[0m');
            console.log('error: ' + error);

What am i missing here?

  • What version of web3.js are you on? Apr 26, 2020 at 7:57
  • web3js 1.0.0-beta.37 Apr 26, 2020 at 7:58
  • First of all, please upgrade to v1.2.6. Apr 26, 2020 at 7:59
  • Also, get rid of the global var tx. It is redundant in your script. Apr 26, 2020 at 8:03
  • Also, in your implementation, function getInputTransaction doesn't need to be declared async. Apr 26, 2020 at 8:04

1 Answer 1


The callback passed to getBlock is triggered just fine under web3.js v1.2.1.

A few side issues that you might want to fix:

  1. The global var tx seems redundant
  2. Function getInputTransaction doesn't need to be declared async
  3. In the callback passed to getBlock, ensure err == null before using result
  4. In the callback passed to getTransaction, ensure err == null before using cb
  • Thanks for helping. Did all the instructions and yes, err is returning null, which is right, isn't? If a change if(err != null) to if(err == null) of getBlock i got an error "'input' of undefined" Debuggin shows "cb" continues not be triggered. Apr 26, 2020 at 8:36
  • @RAFAELDASILVA: Yes, it should be "ensure err == null" in my answer. I don't understand your question though, because there is no cb parameter in the callback that you pass to getBlock. You should ensure err == null in both of the callbacks. Apr 26, 2020 at 8:41
  • i meant when i debbug, "cb" of getInputTransaction is not triggered because i got the follow error: "'input' of undefined". according to the documentation, "input" parameter is one of variables of the callback parameter "cb" Apr 26, 2020 at 8:44
  • @RAFAELDASILVA: Yes, but when err != null, the input parameter is probably not provided. Apr 26, 2020 at 8:47
  • even with err == null i got "input' of undefined" Apr 26, 2020 at 8:52

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.