Withdraw an Identity’s balance#
The purpose of this tutorial is to walk through the steps necessary to withdraw part of an identity’s balance from Platform to a Dash address.
Overview#
Over time, users may want to convert some of their identity’s Platform credits back to Dash for use on the Core chain.
Prerequisites#
General prerequisites (Node.js / Dash SDK installed)
A configured client: Setup SDK Client
A Dash Platform Identity with a credit balance: Tutorial: Register an Identity
A Core chain address to receive the withdrawn credits as Dash
Code#
import { setupDashClient } from '../setupDashClient.mjs';
const { sdk, keyManager } = await setupDashClient();
const { identity, signer } = await keyManager.getTransfer();
console.log('Identity balance before withdrawal:', identity.balance);
// Default: testnet faucet address. Replace or override via WITHDRAWAL_ADDRESS.
const toAddress =
process.env.WITHDRAWAL_ADDRESS || 'yXWJGWuD4VBRMp9n2MtXQbGpgSeWyTRHme';
const amount = 190000n; // Credits to withdraw
const amountDash = Number(amount) / (1000 * 100000000);
console.log(`Withdrawing ${amount} credits (${amountDash} DASH)`);
try {
const remainingBalance = await sdk.identities.creditWithdrawal({
identity,
amount,
toAddress,
signer,
});
console.log(`Identity balance after withdrawal: ${remainingBalance} credits`);
} catch (e) {
console.error('Something went wrong:\n', e.message);
}
What’s Happening#
After connecting to the client, we get the transfer key signer using keyManager.getTransfer() and log the identity’s current balance. We also convert the credit amount to Dash for display (1000 credits = 1 duff = 0.00000001 DASH). We then call sdk.identities.creditWithdrawal() with the identity, withdrawal amount in credits, the destination Core chain address, and the signer to authorize the withdrawal. The remaining credit balance is logged to confirm the withdrawal succeeded.