Guides
Dash CoreDash PlatformDash.orgDash User DocsLog In
Guides
These docs are for v0.14.0. Click to read the latest docs for v0.25-redirect.

Topup an Identity's Balance

πŸ‘

New in Dash Platform Protocol v0.13

The purpose of this tutorial is to walk through the steps necessary to add credits to an identity's balance.

Overview

As users interact with Dash Platform applications, the credit balance associated with their identity will decrease. Eventually it will be necessary to topup the balance by converting some Dash to credits. Additional details regarding credits can be found in the Credits description.

For this tutorial you will need:

Code

const Dash = require('dash');

const clientOpts = {
  network: 'evonet',
  wallet: {
    mnemonic: 'a Dash wallet mnemonic with evonet funds goes here',
  }
};
const client = new Dash.Client(clientOpts);

const topupIdentity = async function () {
  try {
    const identityId = 'an identity ID goes here';
    const topUpAmount = 1000;  // Number of duffs

    const platform = client.platform;
    const status = await platform.identities.topUp(identityId, topUpAmount);
    const identity = await platform.identities.get(identityId);
    console.log('Identity credit balance:', identity.balance);
  } catch (e) {
    console.error('Something went wrong:', e);
  } finally {
    client.disconnect();
  }
}

topupIdentity();

What's Happening

After connecting to the Client, we call platform.identities.topUp with an identity ID and a topup amount in duffs. This creates a lock transaction and increases the identity's credit balance by the relevant amount (minus fee). The updated balance is output to the console.

πŸ“˜

Dash / Credit Conversion

Dash is converted to credits at a ratio of 1 duff : 1000 credits. This provides flexibility for very granular platform fees.