[SOLVED] Using Meteor wrapAync and/or bindEnvironment when calling function in methods.js using async function in fixtures.js


This Content is from Stack Overflow. Question asked by theredtexan

My Meteor project has the DASH SDK installed as an NPM package. The goal is to call the “funds” function in methods.js from fixtures.js whenever a transaction is received. The address and amount are console logging from fixtures.js correctly, but I am receiving an error regarding bindEnvironment due to fibers. It does not console log from methods.js.


import { Meteor } from 'meteor/meteor';

Meteor.startup(() => {
  const Dash = require("dash");
  const mnemonic = 'fake fake fake fake fake fake fake fake fake fake fake fake';
  const client = new Dash.Client({ network: "testnet", wallet: { mnemonic } });
  async function listenUnconfirmedTransaction() {
    const account = await client.wallet.getAccount();
    account.on('FETCHED/CONFIRMED_TRANSACTION', (data) => {
        var amount = data.payload.transaction.outputs[0]._satoshis;
        var address = data.payload.transaction.outputs[0].script.toAddress("testnet").toString();
        console.log("Amount: " + amount + ", Address: " + address);
        if (address) {
            Meteor.call('funds', address, amount, (error) => { if (error) { console.log(error); }});


import { Meteor } from 'meteor/meteor';

  'funds': function (address, received) {
    console.log("Address: " + address + ", Received: " + received);

I have looked into the bindEnvironment and wrapAsync for Meteor, but I am not understanding how I can use them in this situation. Please advise


Ok, if you run Meteor up to version 2.7.3 you need to wrap that(details further down).

2.8 is now in preparation and it makes the move from Fibers (still compatible with NodeJS 14 but not with Node 16) to async. I think async now works server side, just keep an eye on this: https://forums.meteor.com/t/eta-of-2-8-release/58720

Wrapping for Fibers. This is basically running async code as if it was synchronous.

const bound = Meteor.bindEnvironment(callback => callback())

 bound(() => {
  ...your code goes here.


This Question was asked in StackOverflow by theredtexan and Answered by Paul Paulincai It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?