Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ IDENTITY_ID='6cSbshXPYDA2CmBtD31X4uo7YLwtef4mVDt15zRok8Xg'
# CONTRACT_ID comes from the "$id" found in the "contract-register-minimal.js" response
CONTRACT_ID='4BRJbxsDTFY4GJGrCqM6KUjv1wSQDBuUYiGkuzgcrD5d'
# NETWORK sets which network to connect to: testnet, devnet, or local
NETWORK='testnet'
NETWORK='testnet'
# RECIPIENT_ID sets an identity ID to receive a credit transfer
RECIPIENT_ID='6cSbshXPYDA2CmBtD31X4uo7YLwtef4mVDt15zRok8Xg'
37 changes: 37 additions & 0 deletions 1-Identities-and-Names/identity-transfer-credits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/transfer-credits-to-an-identity.html
const Dash = require('dash');
const dotenv = require('dotenv');
dotenv.config();

const clientOpts = {
network: process.env.NETWORK,
wallet: {
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
unsafeOptions: {
skipSynchronizationBeforeHeight: process.env.SYNC_START_HEIGHT, // only sync from early-2022
},
},
};
const client = new Dash.Client(clientOpts);

const transferCredits = async () => {
const identityId = process.env.IDENTITY_ID; // Your identity ID
const identity = await client.platform.identities.get(identityId);

const recipientId = process.env.RECIPIENT_ID; // Recipient's ID
const recipientIdentity = await client.platform.identities.get(recipientId);
console.log('Recipient identity balance before transfer: ', recipientIdentity.balance);
const transferAmount = 1000; // Number of credits to transfer

await client.platform.identities.creditTransfer(
identity,
recipientId,
transferAmount,
);
return client.platform.identities.get(recipientId);
};

transferCredits()
.then((d) => console.log('Recipient identity balance after transfer: ', d.balance))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ align with the tutorials section found on the
After [creating an identity](./1-Identities-and-Names/identity-register.js), set
the `IDENTITY_ID` value in your `.env` file to your new identity ID. After
[registering a data contract](./2-Contracts-and-Documents/contract-register-minimal.js),
set the `CONTRACT_ID` value in your `.env` file to your new contract ID.
set the `CONTRACT_ID` value in your `.env` file to your new contract ID. To do
credit transfers between identities, create a second identity and set the
`RECIPIENT_ID` value in your `.env` file to its ID.

## Contributing

Expand Down