bitcore icon indicating copy to clipboard operation
bitcore copied to clipboard

Impossible create/use wallet

Open Droppix opened this issue 6 years ago • 3 comments

Hi,

I try to create a wallet from your sample (Irene.js), but don't work, I have error : Error: Import credentials first with setCredentials()

I work on node v8. Can you confirm, it's possible create wallet(s) BTC/BCH/ETH on node server ?

var Client = require('bitcore-wallet-client/index').default;
var client = new Client({
  baseUrl: 'http://locallhost:3232/bws/api',
  verbose: false,
});

client.createWallet("My Wallet", "Irene", 2, 2, {network: 'testnet'}, function(err, secret) {
  if (err) {
    console.log('error: ',err);
    return
  };
});

If you have any samples, I would be delighted, because the documentation of your services is almost non-existent!

Droppix avatar Nov 08 '19 11:11 Droppix

I also encountered the same error. error: Error: Import credentials first with setCredentials()

weizihua avatar Nov 21 '19 09:11 weizihua

The docs around this are non-existent, but you need to set the credentials on the client before using it to make requests.

Try this:

var Client = require('./bitcore-wallet-client/index').default;


var fs = require('fs');
var BWS_INSTANCE_URL = 'http://localhost:3232/bws/api'

// Generates a new extended private key
var ireneKeys = Client.Key.create();

var client = new Client({
  baseUrl: BWS_INSTANCE_URL,
  verbose: false
});

client.credentials = ireneKeys.createCredentials("test", { coin: 'btc', network: 'testnet', account: 0, n: 2 });

client.createWallet("My Wallet", "Irene", 2, 2, {network: 'testnet'}, function(err, secret) {
  if (err) {
    console.log('error: ',err);
    return
  };
  // Handle err
  console.log('Wallet Created. Share this secret with your copayers: ' + secret);
  fs.writeFileSync('irene-secret.dat', ireneKeys.mnemonic);
  fs.writeFileSync('irene.dat', client.toString());
});

rowandh avatar Nov 22 '19 04:11 rowandh

For anyone running into the same issue with the latest version of bitcore-wallet-client:

import Client from "bitcore-wallet-client";
import fs from 'fs'
const BWS_INSTANCE_URL = "https://bws.bitpay.com/bws/api";

const k = new Client.Key();
const creds = k.createCredentials("test", {
  coin: "btc",
  network: "testnet",
  account: 0,
  n: 2,
});

const client = new Client({
  baseUrl: BWS_INSTANCE_URL,
  logLevel: "debug",
});

export const irene = () => {
  client.fromObj(creds);   // set credentials
  client.createWallet("My Wallet", "Irene", 2, 2, {network: 'testnet'}, function(err: any, secret: string) {
    if (err) {
      console.log('error: ',err);
      return
    };
    // Handle err
    console.log('Wallet Created. Share this secret with your copayers: ' + secret);
    fs.writeFileSync('irene.dat', client.toString({}));
  });
};

agonzalezv avatar Jul 16 '24 13:07 agonzalezv