2

I'm using the code given on the docs to create a new wallet, and it says that I am getting a: TypeError: Cannot read property 'name' of null error.

My code looks like:

var Client = require('coinbase').Client;

// blank intentionally, but completed actually
var client = new Client({
    'apiKey': '',
    'apiSecret': '',
});

client.createAccount({'name': 'New Wallet'}, function(err, acct) {
    console.log(acct.name + ': ' + acct.balance.amount + ' ' + acct.balance.currency);
});

What am I doing wrong?

Pal Kerecsenyi
  • 560
  • 4
  • 18
Olivier Gabison
  • 78
  • 1
  • 13
  • Could you post more of your code by any chance? It should be working if everything else is as the docs suggest. Maybe you've made a mistake somewhere else? Thanks. You can also try `if (err) throw err;` inside the function to see if an error has occurred. – Pal Kerecsenyi Jun 04 '18 at 15:08
  • 1
    Did you check your return value `acct`? The error message is quite obvious: `acct` is equal to `null`. When you have a callback, start by checking the return value for `err`. Check the following for more details: https://blog.risingstack.com/node-js-best-practices/. – rphonika Jun 04 '18 at 15:09
  • @PalKerecsenyi updated code – Olivier Gabison Jun 04 '18 at 15:18
  • Maybe add 'version to the client definition JSON as per https://developers.coinbase.com/docs/wallet/guides/bitcoin-wallet? Not sure if this will make a difference, but it may change the requested URL. – Pal Kerecsenyi Jun 04 '18 at 15:29
  • I've tried that already, at the beginning. Doesn't fix anything :/ – Olivier Gabison Jun 04 '18 at 15:32
  • Interesting... Maybe see https://github.com/bchavez/Coinbase/issues/21. It suggests to double check that your system time is correct as Coinbase is apparently time-sensitive. – Pal Kerecsenyi Jun 04 '18 at 15:35
  • I'll look into that. Thank you. – Olivier Gabison Jun 04 '18 at 16:01
  • Thanks, no problem. – Pal Kerecsenyi Jun 04 '18 at 16:05
  • @PalKerecsenyi I found that my acct is null. Why is this? Shouldn't a default account be made for me at the start? – Olivier Gabison Jun 05 '18 at 09:18
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/172487/discussion-between-olivier-gabison-and-pal-kerecsenyi). – Olivier Gabison Jun 05 '18 at 09:22

1 Answers1

1

acct is null, maybe because createAccount gives you an error. Try to

if(err){
 //handle err
 console.log(err)
}

This should give more information about what's going on

user3849960
  • 120
  • 2
  • 11
  • when I do this, I get an AuthenticationError: invalid signature error. – Olivier Gabison Jun 04 '18 at 15:15
  • Probably there is something wrong with your `client` object, regarding the authentication. Try to review the coinbase documentation and I recommend to update the question providing more details about how you set the client and about the error `AuthenticationError` that you get when running the code – user3849960 Jun 04 '18 at 15:21
  • Actually, my acct is null. How do I make it 'unnull'? – Olivier Gabison Jun 04 '18 at 16:03