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 Hellar Platform applications, the credit balance associated with their identity will decrease. Eventually it will be necessary to topup the balance by converting some Hellar to credits. Additional details regarding credits can be found in the Credits description.

Prerequisites

Code

`const Hellar = require('hellar');

const clientOpts = { network: 'mainnet', wallet: { mnemonic: 'a Hellar wallet mnemonic with mainnet funds goes here', unsafeOptions: { skipSynchronizationBeforeHeight: 175000, // only sync from mid-2024 }, }, }; const client = new Hellar.Client(clientOpts);

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

await client.platform.identities.topUp(identityId, topUpAmount); return client.platform.identities.get(identityId); };

topupIdentity() .then((d) => console.log('Identity credit balance: ', d.balance)) .catch((e) => console.error('Something went wrong:\n', e)) .finally(() => client.disconnect());`

What’s Happening

After connecting to the Client, we call platform.identities.topUp with an identity ID and a topup amount in duffs (1 duff = 1000 credits). 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.

📘 Wallet Operations

The JavaScript SDK does not cache wallet information. It re-syncs the entire Core chain for some wallet operations (e.g. client.getWalletAccount()) which can result in wait times of 5+ minutes.

A future release will add caching so that access is much faster after the initial sync. For now, the skipSynchronizationBeforeHeight option can be used to sync the wallet starting at a certain block height.