Manage your own wallet

Your own programmatic wallet

In addition to managing user wallets to trigger payments, you can use HandCash Connect to manage your own wallet. This is very useful if your app has payouts.

Instead of building your own wallet from scratch, you can leverage HandCash Connect.

ℹ️

Before this tutorial

Follow the getting started section before following this tutorial. First, you need your app to be registered in the HandCash Dashboard with the Pay permissions.

Steps

Log into HandCash Wallet

Log into the HandCash account you want to manage using Connect. You will need to authorize your own app with that particular account.

Get the redirection URL

const {HandCashConnect} = require('@handcash/handcash-connect');
const handCashConnect = new HandCashConnect({ 
   appId: '<app-id>', 
   appSecret: '<secret>',
});

const redirectionLoginUrl =  handCashConnect.getRedirectionUrl();
console.log('Open this link to authorize your app: ' + redirectionUrl);

Click the link generated to authorize your app.

Authorize your own app

The authorization link from the previous step will look like the following.

Authorize your own app and you will be redirected to the authorization success URL defined in your app.

Get your token authToken

After the redirection, inspect the link. You will need to retrieve the authToken from that URL. For example, in the following link:

Your authToken would be f7a0053318d1bb....7ad0691cd26307f. Grab it for the next step.

Trigger payments from your wallet

Paste the authTokenin your code and you are ready to trigger payments from your wallet:

const {HandCashConnect} = require('@handcash/handcash-connect');
const handCashConnect = new HandCashConnect({ 
   appId: '<app-id>', 
   appSecret: '<secret>',
}); 

const authToken = '<auth-token>';
const account = handCashConnect.getAccountFromAuthToken(authToken);
const paymentParameters = {
    description: "Paying to myself!",
    payments: [
        { destination: 'satoshi', currencyCode: 'USD', sendAmount: 0.10 },
    ]
};
const paymentResult = await account.wallet.pay(paymentParameters);
console.log(paymentResult);

Watch the tutorial

<https://youtu.be/arYq6xmHKTQ>

https://youtu.be/arYq6xmHKTQ