Import a multsig wallet

(Carlos Faria) #1

Hi guys,

I’m using bitcore-wallet-client and I’m trying to API.import a wallet (2-3 multisig), but I’m obtaining a “Illegal State”.

  var client = new Client({
    verbose: true

  var wallet = fs.readFileSync(filePath,'utf8');
  client.import(wallet, {});

  client.getStatus({}, function(err, response){
    client.getTxHistory({}, function (err, txs) {

The “Illegal State” happen when I do getTxHistory

And one more question, what is the purpose of _import ?


(Iván Socolsky) #2

The ‘Illegal State’ you are getting is probably due to the wallet not being complete (as in all copayers having joined the wallet). Sometimes this happens when the wallet is not saved after the last copayer joins. To confirm this is what is happening, you can take a look at the response from the getStatus call. If response.wallet.status == "pending" it means the wallet is not complete yet.
The _import method tries to regain access to an existent wallet in BWS. It allows users to access their wallets by just importing the seed on a different device.
Hope this helps!

(Carlos Faria) #3

Hi @isocolsky thanks for the reply!

The status of the wallet is complete. I think I’m doing something wrong, I’m importing the wallet .dat file related with one copayer, is the correct way?

(Iván Socolsky) #4

Ok I suspect what is happening is that the credentials included in the wallet.dat you are importing do not have all the info required to access the wallet (should have nb of copayers, required signatures, and the complete public key ring). This is the check for credential completeness:

Credentials.prototype.isComplete = function() {
  if (!this.m || !this.n) return false;
  if (!this.publicKeyRing || this.publicKeyRing.length != this.n) return false;
  return true;

What I meant in my previous response is, once the wallet is complete, copayer credentials get updated with all this info and needs to be saved. This is probably what is causing the issue. Can you please confirm?

(Carlos Faria) #5

isComplete ir returning false, as you expected.

But I successful join all other copayers. So I don’t understand, maybe x-identity argument in header file is not the same as when I created a wallet?

(Chris Rico) #6

Try calling client.openWallet after importing. That was necessary for me before I could use the client for anything.

You can see my code here.

(Carlos Faria) #7

Thanks @Chris but didn’t result, Illegal State, and openWallet is returning undefined …

(Chris Rico) #8

@CarlosFaria you need to do something like this…

function load(client, callback) {
	try {
		client.openWallet(function (err, complete) {
			if (err) return callback(err);
			if (!complete) return callback('Wallet is unusable until all copayers have joined');
			return callback();
	} catch (e) {
		return callback(e);

var client = new bitcore({baseUrl: host});
load(client, function(err) {
	if (err) throw err;
	// now you can use the client to communicate with the server