Skip to main content

Examples

The packages/sdk/example/ts/ folder contains runnable TypeScript examples that cover the full SDK surface. They all target Hedera testnet and share a single .env file.


Setup

1. Build the SDK first

The examples depend on @hashgraph/stablecoin-npm-sdk resolved from the local source (packages/sdk/). If the SDK has not been built yet, npm install inside the example folder will fail to resolve the package and all imports will break.

The easiest way is to run the root setup command, which installs and builds the entire project:

# From the repo root
npm run setup

If you cloned the repo and skipped this step, this is the most common reason examples fail to run.

2. Copy the env template

cd packages/sdk/example
cp .env.sample .env

3. Fill in .env

Open .env and fill in the values for the examples you want to run. See Environment Variables below for a full explanation of each variable.

4. Install dependencies and build the examples

cd packages/sdk/example/ts
npm install
npm run build

Build output is placed in packages/sdk/example/ts/build/.


Environment Variables

The .env file lives at packages/sdk/example/.env and is shared across all examples.

Core (required by all examples)

VariableDescription
MY_ACCOUNT_IDYour Hedera testnet account ID (e.g. 0.0.12345)
MY_PRIVATE_KEYED25519 or ECDSA private key for MY_ACCOUNT_ID (hex)
MY_PRIVATE_KEY_ECDSAECDSA private key (without 0x prefix) — required by the EVM external adapter and DFNS examples
FACTORY_ADDRESSHedera account ID of the deployed Factory contract (e.g. 0.0.XXXX)
RESOLVER_ADDRESSHedera account ID of the deployed Resolver contract (e.g. 0.0.XXXX)

FACTORY_ADDRESS and RESOLVER_ADDRESS are deployed infrastructure addresses for the Factory and Resolver contracts. If you are running against the shared public testnet deployment, use the addresses provided in the project's getting started guide.

External wallet examples

VariableDescription
TOKEN_ID(Optional) Reuse an existing token ID in testExternalEVM — skips token creation
TOKEN_ID_HEDERA(Optional) Reuse an existing token ID in testExternalHedera — skips token creation

Multisig example (multisigFreeze.ts)

VariableDescription
MULTISIG_ACCOUNT_IDThe Hedera account ID whose keys are managed via the multisig backend
BACKEND_URLURL of the multisig backend service (e.g. http://127.0.0.1:3001/api/transactions/)
CONSENSUS_NODE_URLCustom consensus node endpoint (e.g. 34.94.106.61:50211)
CONSENSUS_NODE_IDNode account ID for the above endpoint (e.g. 0.0.3)

DFNS examples (createDFNSMultisigAccount.ts / multisigFreezeDFNS.ts)

VariableDescription
DFNS_MULTISIG_ACCOUNT_IDAccount ID created by createDFNSMultisigAccount (set after running it)
DFNS_SERVICE_ACCOUNT_AUTHORIZATION_TOKENDFNS service account JWT
DFNS_SERVICE_ACCOUNT_CREDENTIAL_IDDFNS credential ID
DFNS_SERVICE_ACCOUNT_PRIVATE_KEY_OR_PATHDFNS EC private key (PEM string or path to file)
DFNS_APP_ORIGINApplication origin URL registered in DFNS
DFNS_APP_IDDFNS application ID
DFNS_BASE_URLDFNS API base URL (e.g. https://api.dfns.ninja)
DFNS_WALLET_IDDFNS wallet ID linked to the Hedera account
DFNS_WALLET_PUBLIC_KEYPublic key of the DFNS wallet (hex, no 0x)
DFNS_HEDERA_ACCOUNT_IDHedera account ID managed by the DFNS wallet

Running Examples

All scripts are defined in packages/sdk/example/ts/package.json. Run them from that directory:

cd packages/sdk/example/ts
npm run <script-name>

Each script builds the TypeScript first (npm run build) then runs the compiled output.


Example Reference

Token Creation

ScriptFileWhat it does
start-creationcreation.tsCreates a basic stablecoin with all roles assigned to your account and no reserve
start-creation-with-reservecreationWithReserve.tsCreates a stablecoin and deploys a Chainlink-compatible reserve data feed alongside it
start-creation-with-reserve-addresscreationWithReserveAddress.tsCreates a stablecoin and links it to an existing reserve at an EVM address
start-creation-assigning-keyscreationAssigningKeys.tsCreates a stablecoin and assigns HTS token keys (freeze, KYC, wipe, pause) from your account's public key

Token Operations

ScriptFileWhat it does
mintmint.tsCreates a token, associates it, grants KYC, then mints 10 tokens and asserts the final balance is correct
burnburn.tsCreates a token, burns 10 from the initial supply, and asserts the total supply decreased
wipewipe.tsCreates a token, mints tokens, wipes 1 from the account balance, and asserts the final balance

Role Management

ScriptFileWhat it does
rolesrole.tsCreates a token, revokes WIPE_ROLE, asserts it is gone, re-grants it, and asserts it is back

External Wallet Adapters

These examples run a comprehensive suite of ~40 operations against a real testnet token, covering every SDK method: basic ops, compliance, roles, supplier allowance, custom fees, rescue, reserve, holds, config updates, and delete.

ScriptFileAdapter usedWhat it does
test-external-evmtestExternalEVM.tsEXTERNAL_EVMRuns the full test suite; each operation is signed with ethers.js and broadcast to the JSON-RPC node
test-external-hederatestExternalHedera.tsEXTERNAL_HEDERARuns the full test suite; each operation is signed with the Hedera SDK and submitted to the network

Both print a summary table at the end showing PASS / FAIL / SKIP for every test.

The shared test suite logic lives in testExternalCommon.ts.

Tip: Set TOKEN_ID (for EVM) or TOKEN_ID_HEDERA (for Hedera) in .env to skip token creation and reuse an existing token across runs.

Multisig

ScriptFileWhat it does
multisig-freezemultisigFreeze.tsFull multisig flow: deploys a token with the CLIENT wallet, associates the multisig account, grants it FREEZE_ROLE, then submits a freeze via the MULTISIG wallet and co-signs with the deployer
create-dfns-multisig-accountcreateDFNSMultisigAccount.tsUtility: creates a Hedera account whose KeyList includes the DFNS wallet public key. Run this once and copy the printed account ID into DFNS_MULTISIG_ACCOUNT_ID in .env
multisig-freeze-dfnsmultisigFreezeDFNS.tsSame multisig freeze flow but the co-signer is a DFNS custodial wallet instead of a plain private key

Folder Structure

packages/sdk/example/
├── .env ← your credentials (gitignored)
├── .env.sample ← template with all variables documented
├── package.json
└── ts/
├── package.json ← npm scripts for all examples
├── tsconfig.json
├── build/ ← compiled JS output (generated by npm run build)

├── creation.ts
├── creationWithReserve.ts
├── creationWithReserveAddress.ts
├── creationAssigningKeys.ts
├── mint.ts
├── burn.ts
├── wipe.ts
├── role.ts
├── testExternalCommon.ts ← shared test suite (~40 operations)
├── testExternalEVM.ts
├── testExternalHedera.ts
├── multisigFreeze.ts
├── createDFNSMultisigAccount.ts
└── multisigFreezeDFNS.ts