Skip to content

Commit 5eaddb0

Browse files
thephezclaude
andauthored
feat: migrate tutorials from js-dash-sdk to evo-sdk (#53)
* feat: add evo-sdk tutorials for read-only operations Add evo-sdk tutorial examples for identities, names, contracts, and documents. Includes setupEvoClient helper for configuration and 5 working examples. * refactor: make output consistent and init client right away * style: npm fmt * feat: add more tutorials * feat: add working credit transfer tutorial Also updates .env.example to include TRANSFER_KEY_WIF * feat: add working identity credit withdrawal * chore: update evo sdk to latest release * feat: add name registration and document tutorials * docs: update .env.example with recently added vars * feat: add minimal contract registration tutorial * feat: add contract update tutorial * feat: create nft contract tutorial * feat: add some nft-related tutorials * feat: remaining nft tutorials and env.example updates * chore: update evo-sdk dependency * chore: update to evo sdk 3.1-dev.1 * feat: add evo sdk client setup and identity register tutorial * feat: migrate identity-retrieve and document-submit to evo-sdk ESM Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: add links to tutorial docs pages * feat: migrate document-retrieve and document-delete to evo-sdk ESM Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: migrate document update to evo sdk * fix: add bug workaround to identity create * feat: migrate contracts tutorials to evo-sdk ESM Migrate all contract register/retrieve/update tutorials from legacy js-dash-sdk (CJS) to evo-sdk (ESM). Adds new variants (binary, indexed, timestamps, history-retrieve) and works around sdk.contracts.fetch() returning undefined for keepsHistory contracts (dashpay/platform#3165). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: delete old sdk tutorials * feat: migrate connect and create-wallet to evo-sdk ESM Replace legacy js-dash-sdk CJS scripts (connect.js, create-wallet.js, setupDashClient.js) with evo-sdk ESM equivalents. Add .local/ to .gitignore. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: migrate DPNS name tutorials to evo-sdk Migrate name-register, name-resolve, name-search, and name-get-identity-names from legacy js-dash-sdk (CJS) to evo-sdk (ESM). Add friendly error for duplicate name registration attempts. * chore: trivial updates * chore: remove outdated files * chore: whitespace cleanup * feat: migrate identity topup, transfer, and withdrawal to evo-sdk Replace legacy js-dash-sdk CJS scripts with evo-sdk ESM equivalents. Add env var overrides for recipient ID and withdrawal address with sensible testnet defaults. * feat: add identity update tutorials (add-key, disable-key) for evo-sdk Add evo-sdk ESM tutorials for adding and disabling identity keys. Add-key auto-detects next available key ID and uses exported dip13KeyPath helper instead of manual path construction. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: remove unneeded files * chore: remove outdated files * style: npm fmt updates * docs: update README * chore: typo fix * docs: update readme * docs: readme update * chore: remove old dash sdk from package.json --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f811e1b commit 5eaddb0

57 files changed

Lines changed: 1873 additions & 6969 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,41 @@ CONTRACT_ID='4BRJbxsDTFY4GJGrCqM6KUjv1wSQDBuUYiGkuzgcrD5d'
1717
NETWORK='testnet'
1818
# RECIPIENT_ID sets an identity ID to receive a credit transfer
1919
RECIPIENT_ID='6cSbshXPYDA2CmBtD31X4uo7YLwtef4mVDt15zRok8Xg'
20+
21+
# Private keys for IDENTITY_ID in WIF format
22+
# You can create an identity using the Dash Evo Tool and copy these keys from there
23+
# https://github.com/dashpay/dash-evo-tool
24+
MASTER_KEY_WIF=''
25+
CRITICAL_KEY_WIF=''
26+
TRANSFER_KEY_WIF=''
27+
28+
# DOCUMENT_ID is the ID of a document (obtained from document-submit output)
29+
# Used for document-update and document-delete tutorials
30+
DOCUMENT_ID=''
31+
32+
# NAME_LABEL is an optional username label for name registration (without .dash)
33+
# If not provided, tutorials will generate a unique 20+ character label automatically
34+
NAME_LABEL=''
35+
36+
# NFT Variables
37+
# NFT_CONTRACT_ID comes from contract-register-nft output
38+
NFT_CONTRACT_ID=''
39+
# NFT_OWNER_ID is the identity ID that owns the NFT documents
40+
# This should typically be the same as IDENTITY_ID above
41+
NFT_OWNER_ID=''
42+
# NFT_DOCUMENT_ID comes from nft-create output
43+
# Used for nft-set-price, nft-transfer, etc.
44+
NFT_DOCUMENT_ID=''
45+
46+
# NFT Marketplace Variables
47+
# NFT_PRICE is the listing price in credits for marketplace operations
48+
# Note: 1000 credits = 1 satoshi equivalent
49+
NFT_PRICE=1000
50+
# NFT_DOCUMENT_ID is the document ID to purchase from the marketplace
51+
# This should be a different document than NFT_DOCUMENT_ID (you can't buy your own NFT)
52+
NFT_DOCUMENT_ID=''
53+
# NFT_BUYER_ID is the identity ID of the buyer (different from NFT_OWNER_ID)
54+
NFT_BUYER_ID=''
55+
# NFT_BUYER_KEY_WIF is the CRITICAL_KEY_WIF for the buyer's identity
56+
# Required for purchase operations (AUTHENTICATION purpose key, not TRANSFER key)
57+
NFT_BUYER_KEY_WIF=''

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.local/
12
node_modules/
23
.env
34
.DS_Store

1-Identities-and-Names/identity-register.js

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/register-an-identity.html
2+
import { randomBytes } from 'node:crypto';
3+
import { Identity, Identifier } from '@dashevo/evo-sdk';
4+
import { setupDashClient } from '../setupDashClient.mjs';
5+
6+
const { sdk, keyManager, addressKeyManager } = await setupDashClient({
7+
requireIdentity: false,
8+
});
9+
10+
try {
11+
// Build the identity shell with 5 standard public keys
12+
const identity = new Identity(new Identifier(randomBytes(32)));
13+
keyManager.getKeysInCreation().forEach((key) => {
14+
identity.addPublicKey(key.toIdentityPublicKey());
15+
});
16+
17+
// Create the identity on-chain, funded from the platform address
18+
const result = await sdk.addresses.createIdentity({
19+
identity,
20+
inputs: [
21+
{
22+
address: addressKeyManager.primaryAddress.bech32m,
23+
amount: 5000000n, // Credits to fund the new identity
24+
},
25+
],
26+
identitySigner: keyManager.getFullSigner(),
27+
addressSigner: addressKeyManager.getSigner(),
28+
});
29+
30+
console.log(
31+
'Identity registered!\nIdentity ID:',
32+
result.identity.id.toString(),
33+
);
34+
} catch (e) {
35+
// Known SDK bug: proof verification fails but the identity was created
36+
// Issue: https://github.com/dashpay/platform/issues/3095
37+
// Extract the real identity ID from the error message
38+
const match = e.message?.match(/proof returned identity (\w+) but/);
39+
if (match) {
40+
console.log('Identity registered!\nIdentity ID:', match[1]);
41+
} else {
42+
console.error('Something went wrong:\n', e.message);
43+
}
44+
}

1-Identities-and-Names/identity-retrieve.js

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/retrieve-an-identity.html
2+
import { setupDashClient } from '../setupDashClient.mjs';
3+
4+
const { sdk, keyManager } = await setupDashClient();
5+
6+
// Identity ID from the identity create tutorial
7+
const IDENTITY_ID = keyManager.identityId;
8+
9+
if (!IDENTITY_ID) {
10+
throw new Error(
11+
'No identity found. Run the "Register an Identity" tutorial first or provide an identity ID.',
12+
);
13+
}
14+
15+
try {
16+
const identity = await sdk.identities.fetch(IDENTITY_ID);
17+
console.log('Identity retrieved:\n', identity.toJSON());
18+
} catch (e) {
19+
console.error('Something went wrong:\n', e.message);
20+
}

1-Identities-and-Names/identity-topup.js

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/topup-an-identity-balance.html
2+
import { setupDashClient } from '../setupDashClient.mjs';
3+
4+
const { sdk, addressKeyManager, keyManager } = await setupDashClient();
5+
const signer = addressKeyManager.getSigner();
6+
7+
try {
8+
// Identity ID from the identity create tutorial
9+
const IDENTITY_ID = keyManager.identityId;
10+
const identity = await sdk.identities.fetch(IDENTITY_ID);
11+
12+
const result = await sdk.addresses.topUpIdentity({
13+
identity,
14+
inputs: [
15+
{
16+
address: addressKeyManager.primaryAddress.bech32m,
17+
amount: 200000n, // Credits to transfer
18+
},
19+
],
20+
signer,
21+
});
22+
23+
console.log(`Top-up result:
24+
Start balance: ${identity.toJSON().balance}
25+
Final balance: ${result.newBalance}`);
26+
} catch (e) {
27+
console.error('Something went wrong:\n', e.message);
28+
}

1-Identities-and-Names/identity-transfer-credits.js

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/transfer-credits-to-an-identity.html
2+
import { setupDashClient } from '../setupDashClient.mjs';
3+
4+
const { sdk, keyManager } = await setupDashClient();
5+
const { identity, signer } = await keyManager.getTransfer();
6+
7+
// Default recipient (testnet). Replace or override via RECIPIENT_ID.
8+
const recipientId =
9+
process.env.RECIPIENT_ID ?? '7XcruVSsGQVSgTcmPewaE4tXLutnW1F6PXxwMbo8GYQC';
10+
const transferAmount = 100000n; // Credits to transfer
11+
12+
try {
13+
await sdk.identities.creditTransfer({
14+
identity,
15+
recipientId,
16+
amount: transferAmount,
17+
signer,
18+
});
19+
20+
const recipient = await sdk.identities.fetch(recipientId);
21+
console.log('Recipient identity balance after transfer:', recipient.balance);
22+
} catch (e) {
23+
console.error('Something went wrong:\n', e.message);
24+
}

0 commit comments

Comments
 (0)