Best Way To Create Automatically Redirect Wallets

Discussion in 'Technical Development' started by Talles, Jun 20, 2016.

  1. 2017/12/15 - Decred v1.1.2 released! → Release Notes  → Downloads
  1. Talles

    Talles New Member

    Jun 20, 2016
    2
    0
    João Pessoa pb
    Hello guy's, I'm from Brazil and I'm studying to create an exchange, I've some experience with bitcoin, ethereum and security. My doubt is, what's the best way to implement an automatically creation of the new users decreed wallet, and how can i set these new wallets to automatically withdraw to my cold wallet? What's the best approach to implement this. Btw I'm a nodejs developer.
     
  2. practitioner

    practitioner New Member

    Jun 20, 2016
    3
    2
    BM-NB7CUwJW1AsrydfdnpJCGy52mHyq4Env
    Location.setLocation = callRandom({});
    just my thoughts:

    1. create just one DCR cold wallet (exchange owned wallet), only you have the seed, public/private passphrase to send coins. For user deposits call getnewaddress RPC on opened wallet or pre generate list of addresses for users your wallet will use. Associate that specific deposit address with user (in your exchange internal auditing system/dbs). You can call getreceivedbyaddress or query blockchain directly to get the amounts user deposited. For withdrawal, you will have second - hot wallet - where you will hold just small portion of cold wallet balance. When user initiate withdrawal, you will unlock hot wallet and use sendtoaddress or sendmany (multiple withdrawal processing e.g. every 10 minutes/hour tec.) to send coins + update your internal auditing system.

    2. do it using DCR wallet accounts (numerous accounts for numerous users) but still one wallet (cold) and one hot wallet.

    3. multiple standalone wallets - not viable imo.

    good luck!
     
    Talles likes this.
  3. Talles

    Talles New Member

    Jun 20, 2016
    2
    0
    João Pessoa pb
    Is there any nodejs tool to handle this or do i need to call it using linux batch scripts?
     
  4. practitioner

    practitioner New Member

    Jun 20, 2016
    3
    2
    BM-NB7CUwJW1AsrydfdnpJCGy52mHyq4Env
    Location.setLocation = callRandom({});
    Simple example - connection to DCR wallet RPC via web sockets in Node.

    var fs = require('fs');
    var WebSocket = require('ws');
    var cert = fs.readFileSync('rpc.cert');
    var user = "user";
    var password = "pass";

    var ws_wallet = new WebSocket(
    'wss://127.0.0.1:9110/ws',
    {
    headers: {'Authorization': 'Basic '+new Buffer(user+':'+password).toString('base64')},
    cert: cert,
    ca: [cert]
    }
    );

    ws_wallet.on('open', function()
    {
    console.log('CONNECTED');
    ws_wallet.send('{"jsonrpc":"1.0","id":"0","method":"getstakeinfo","params":[]}');
    });

    ws_wallet.on('message', function(data, flags)
    {
    console.log(data.toString());
    });

    ws_wallet.on('error', function(err) {
    console.log('ERROR:' + err);
    });

    ws_wallet.on('close', function(data)
    {
    console.log('DISCONNECTED');
    });

    for legacy RPC methods look here: https://github.com/decred/dcrwallet/blob/master/rpc/legacyrpc/rpcserverhelp.go

    if you would need to create/load wallets via RPC, that's supported only in gRPC implementation ( https://github.com/decred/dcrwallet/blob/master/rpc/documentation/api.md )

    **EDIT** oh, sure or you can also use dcrctl from bash to command the wallet.
     
    Talles likes this.

Share This Page