Web Wallets Using Copay

Victor Gonzalez from CoinFabrik forked the Copay project and modified the code to facilitate the creation of online wallet services. Currently, the Copay project handles your wallet on your browser, desktop, and mobile devices but not on a Copay server. The new Bitcore Wallet Service does store your wallets on a server, but they are not live: a wallet and the balance it contains are only updated when you use the Bitcore Wallet Client.

Both Bitcore Wallet Service and Copay establish a connection to the Insight server to send and receive information to the blockchain each time a wallet is opened. The key limitation for running multiple wallets on a Copay server is the number of connections to the Insight server. We modified the Copay project code to receive blockchain updates for all the addresses in the different wallets through a single connection to the insight server. Currently, this only works for 1-1 wallets.

We are planning to include multi-signature wallets soon. We will modify the code so that copayers who use online bitcoin wallets also communicate with one another via a single connection shared amongst Insight mailboxes.

Code

The code is available at github.

Prerequisites

MongoDB: This code assumes that mongodb is on localhost. Change this line if you need to point to another host.

Installation

$ git clone https://github.com/CoinFabrik/copay.git
$ cd copay
$ git checkout tags/online-bitcoin-wallets-0.0.1
$ npm install
$ node example.js

Playing with Wallets

The program will prompt the user for an e-mail and password, used for encrypting wallets, and then it will create ten 1-1 wallets.
The program runs a REPL to allow the user to issue commands and query information. For example:

> var wallet = convenience.getAnyWallet()
> wallet.getAddresses()[0]

The above code will print one of the new wallet’s addresses. The user may send some bitcoins to this address.

To spend the bitcoins in the wallet, the user may enter the following command:
> convenience.spend(wallet, <destinationAddress>, <amountInSatoshis>)
To get the balance of the wallet:
> convenience.getBalance(wallet)

Notes

  • MongoDB is used to store both the user’s identity and the wallet. The code can easily be modified to use another database. Additionally, add authentication and encryption to secure the connection between Copay and the database.
  • It is important to note that the bitcoin community is divided on using online wallet services instead of a decentralized wallet since decentralization is at the heart of bitcoin, and online services pose greater security risks.
  • As is the case with any software which will be used to handle other people’s money, a security professional should review any product you develop based on our code.

Resources

If you liked this article, you might also like:

 

  • MOURAD ILYES MLIK

    Hello,

    I am having an issue with the __dirname in the config.js file, when I try to create a wallet the process hang at creating profile and I can seen this error in the dev console “Uncaught ReferenceError: __dirname is not defined”

    • Hi Mourad, the BitPay team has made significant changes to Copay in the last months and, beyond the issues you are experiencing, I think you should move to bitcore-wallet-client.

      Could you please describe the project you are working on to help you better?

      • MOURAD ILYES MLIK

        Hey thanks for the fast respond !… I am aware of the changes they made, they redesigned it completely, your version is the closest thing I got to a working wallet so far.

        I didn’t change anything in your code yet, just cloned it then performed bower install then npm install then npm run. when I navigate to create a new wallet it hangs at creating profile (look at the pic)

        when I check the chrome dev console I see the error I pasted in my first comment, it seems like nodejs can’t resolve the pluginsPath because it doesn’t understand what is __direname is, so it can’t locate mongodbplugin which BTW is in copay home directory.

        The code I am talking about is found in config.js:

        pluginsPath: __dirname + ‘/’,

        plugins: {
        mongodbplugin: true
        },”

        • We will review this code in the following days and give you more feedback.

          • MOURAD ILYES MLIK

            Excellent, Thank you.