makerdao/dai.js

Error: cdpPromise.onPending is not a function

Closed this issue · 6 comments

Hello guys!
I'm trying to use transaction promise methods onPending, onMined and onFinalized, but I'm getting this error:

image

I'm using v0.6.1 with the very same example code from the docs: https://makerdao.com/documentation/#transactions

Thank you.

You've found a mismatch between our documentation and our code. The top-level maker.openCdp method doesn't handle the transaction lifecycle hooks at the moment. We'll have to make some changes to support this. In the meantime, you can use this workaround:

await maker.authenticate(); 
const cdpPromise = maker.service('cdp').openCdp(); // EDIT: fixed typo
// now you can use cdpPromise.onPending, etc.

Thanks for the response, but unfortunately didn't work:
image

oh, i'm sorry, i should have written maker.service('cdp'), not maker.get('service'). i hadn't fully woken up yet, apparently 😅

Great! it's working.
But now I want to do the same for following transactions, something like this:

await this.maker.authenticate();
const cdpPromise = maker.service('cdp').openCdp();
cdpPromise.onPending(console.log('pending!'));
const cdp = await cdpPromise;
await cdp.lockEth(eth); // how to manage this Tx as with .openCdp()?
await cdp.drawDai(dai); // same than previous comment

Thank you in advance!

drawDai should work in the same way:

const drawPromise = cdp.drawDai(dai);
drawPromise.onPending(() => console.log('pending'));
await drawPromise;

lockEth however will not work this way because it's actually several transactions, behind the scenes. We're working on a solution to that.

We've just released v0.9.1, which has a different way of setting up transaction lifecycle hooks:

const cdpPromise = maker.service('cdp').openCdp();
const txManager = maker.service('transactionManager');
txManager.listen(cdpPromise, {
  pending: tx => {
    console.log(`pending: ${tx.contract}.${tx.method}`);
  },
  mined: tx => {
    console.log(`mined: ${tx.contract}.${tx.method}`);
  }
});
const cdp = await cdpPromise;

If you do this with lockEth, each of your callbacks will fire multiple times, one for each transaction. You'll get one for converting ETH to WETH, one to approve transferring WETH, one for converting WETH to PETH, one to approve transferring PETH, and one to lock PETH into the Dai system. (The approval transactions will only happen the first time or if approval was revoked.)