diff --git a/bindings/nodejs/examples/client/04-get-output.ts b/bindings/nodejs/examples/client/04-get-output.ts index 38e26d6b8c..f2d47434d2 100644 --- a/bindings/nodejs/examples/client/04-get-output.ts +++ b/bindings/nodejs/examples/client/04-get-output.ts @@ -10,13 +10,15 @@ require('dotenv').config({ path: '.env' }); // In this example we will get output from a known outputId. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], localPow: true, }); try { diff --git a/bindings/nodejs/examples/client/05-get-address-balance.ts b/bindings/nodejs/examples/client/05-get-address-balance.ts index 9f8491b8cb..ebf47bd31d 100644 --- a/bindings/nodejs/examples/client/05-get-address-balance.ts +++ b/bindings/nodejs/examples/client/05-get-address-balance.ts @@ -11,21 +11,20 @@ require('dotenv').config({ path: '.env' }); // conditions and sum the amounts and native tokens. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL', 'MNEMONIC']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], }); try { - if (!process.env.MNEMONIC) { - throw new Error('.env MNEMONIC is undefined, see .env.example'); - } const secretManager = new SecretManager({ - mnemonic: process.env.MNEMONIC, + mnemonic: process.env.MNEMONIC as string, }); // Generate the first address diff --git a/bindings/nodejs/examples/client/06-simple-block.ts b/bindings/nodejs/examples/client/06-simple-block.ts index 423e850a6f..dcd26aca7b 100644 --- a/bindings/nodejs/examples/client/06-simple-block.ts +++ b/bindings/nodejs/examples/client/06-simple-block.ts @@ -10,13 +10,15 @@ require('dotenv').config({ path: '.env' }); // In this example we will send a block without a payload. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL', 'EXPLORER_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], localPow: true, }); diff --git a/bindings/nodejs/examples/client/07-get-block-data.ts b/bindings/nodejs/examples/client/07-get-block-data.ts index 7a5750937a..f8a45ec4ec 100644 --- a/bindings/nodejs/examples/client/07-get-block-data.ts +++ b/bindings/nodejs/examples/client/07-get-block-data.ts @@ -10,13 +10,15 @@ require('dotenv').config({ path: '.env' }); // In this example we will send a block and get the data and metadata for it. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], }); try { diff --git a/bindings/nodejs/examples/client/08-data-block.ts b/bindings/nodejs/examples/client/08-data-block.ts index 1d46d0da03..c7a84b46d0 100644 --- a/bindings/nodejs/examples/client/08-data-block.ts +++ b/bindings/nodejs/examples/client/08-data-block.ts @@ -17,13 +17,15 @@ require('dotenv').config({ path: '.env' }); // In this example we will send a block with a tagged data payload. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL', 'EXPLORER_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], }); const options = { diff --git a/bindings/nodejs/examples/client/09-transaction.ts b/bindings/nodejs/examples/client/09-transaction.ts index a205341003..636d767a3f 100644 --- a/bindings/nodejs/examples/client/09-transaction.ts +++ b/bindings/nodejs/examples/client/09-transaction.ts @@ -10,25 +10,23 @@ require('dotenv').config({ path: '.env' }); // In this example we will send a transaction. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL', 'MNEMONIC', 'EXPLORER_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], localPow: true, }); try { - if (!process.env.MNEMONIC) { - throw new Error('.env MNEMONIC is undefined, see .env.example'); - } - // Configure your own mnemonic in ".env". Since the output amount cannot be zero, the mnemonic must contain non-zero // balance const secretManager = { - mnemonic: process.env.MNEMONIC, + mnemonic: process.env.MNEMONIC as string, }; // We generate an address from our own mnemonic so that we send the funds to ourselves diff --git a/bindings/nodejs/examples/client/10-mqtt.ts b/bindings/nodejs/examples/client/10-mqtt.ts index 41c4e5ba55..77b095a02e 100644 --- a/bindings/nodejs/examples/client/10-mqtt.ts +++ b/bindings/nodejs/examples/client/10-mqtt.ts @@ -18,14 +18,16 @@ require('dotenv').config({ path: '.env' }); // In this example we will listen to MQTT topics and print the block and milestone payloads. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } // Connecting to a MQTT broker using raw ip doesn't work with TCP. This is a limitation of rustls. const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], }); // Array of topics to subscribe to diff --git a/bindings/nodejs/examples/client/11-build-output.ts b/bindings/nodejs/examples/client/11-build-output.ts index 882652d55f..8dbdd1f18e 100644 --- a/bindings/nodejs/examples/client/11-build-output.ts +++ b/bindings/nodejs/examples/client/11-build-output.ts @@ -24,13 +24,15 @@ require('dotenv').config({ path: '.env' }); // In this example we will build a basic output with various options. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], }); try { diff --git a/bindings/nodejs/examples/client/12-get-raw-block.ts b/bindings/nodejs/examples/client/12-get-raw-block.ts index 4f765a69f3..b461ff1d4c 100644 --- a/bindings/nodejs/examples/client/12-get-raw-block.ts +++ b/bindings/nodejs/examples/client/12-get-raw-block.ts @@ -10,13 +10,15 @@ require('dotenv').config({ path: '.env' }); // In this example we will get the raw bytes of a block. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], }); try { diff --git a/bindings/nodejs/examples/client/13-build-alias-output.ts b/bindings/nodejs/examples/client/13-build-alias-output.ts index b7585044d3..27fb2db0e6 100644 --- a/bindings/nodejs/examples/client/13-build-alias-output.ts +++ b/bindings/nodejs/examples/client/13-build-alias-output.ts @@ -21,13 +21,15 @@ require('dotenv').config({ path: '.env' }); // In this example we will build an alias output. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], }); try { diff --git a/bindings/nodejs/examples/client/14-build-foundry-output.ts b/bindings/nodejs/examples/client/14-build-foundry-output.ts index a6e58ac134..0665ee6638 100644 --- a/bindings/nodejs/examples/client/14-build-foundry-output.ts +++ b/bindings/nodejs/examples/client/14-build-foundry-output.ts @@ -16,20 +16,18 @@ require('dotenv').config({ path: '.env' }); // In this example we will build a foundry output. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL', 'MNEMONIC']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], }); try { - if (!process.env.MNEMONIC) { - throw new Error('.env MNEMONIC is undefined, see .env.example'); - } - const aliasId = '0xff311f59790ccb85343a36fbac2f06d233734794404142b308c13f2c616935b5'; diff --git a/bindings/nodejs/examples/client/15-build-nft-output.ts b/bindings/nodejs/examples/client/15-build-nft-output.ts index 161ce1f9d1..c484c7caed 100644 --- a/bindings/nodejs/examples/client/15-build-nft-output.ts +++ b/bindings/nodejs/examples/client/15-build-nft-output.ts @@ -22,13 +22,15 @@ require('dotenv').config({ path: '.env' }); // In this example we will build an NFT output. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], }); try { diff --git a/bindings/nodejs/examples/client/16-custom-plugin.ts b/bindings/nodejs/examples/client/16-custom-plugin.ts index ecf441d9c8..e92ab1b02f 100644 --- a/bindings/nodejs/examples/client/16-custom-plugin.ts +++ b/bindings/nodejs/examples/client/16-custom-plugin.ts @@ -10,13 +10,15 @@ require('dotenv').config({ path: '.env' }); // In this example we will get output from a known nft by calling the node endpoint using a "custom plugin" call. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], localPow: true, }); diff --git a/bindings/nodejs/examples/client/offline_signing/00-address-generation.ts b/bindings/nodejs/examples/client/offline_signing/00-address-generation.ts index 0c13301186..275e7efc61 100644 --- a/bindings/nodejs/examples/client/offline_signing/00-address-generation.ts +++ b/bindings/nodejs/examples/client/offline_signing/00-address-generation.ts @@ -19,14 +19,15 @@ const ADDRESS_FILE_NAME = 'offline-signing-address.json'; // In this example we will generate an address offline which will be used later to find inputs. async function run() { initLogger(); - - try { - if (!process.env.MNEMONIC) { - throw new Error('.env MNEMONIC is undefined, see .env.example'); + for (const envVar of ['MNEMONIC']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); } + } + try { const secretManager = new SecretManager({ - mnemonic: process.env.MNEMONIC, + mnemonic: process.env.MNEMONIC as string, }); // Generates an address offline. diff --git a/bindings/nodejs/examples/client/offline_signing/01-transaction-preparation.ts b/bindings/nodejs/examples/client/offline_signing/01-transaction-preparation.ts index fd01cdc3b7..150e00375e 100644 --- a/bindings/nodejs/examples/client/offline_signing/01-transaction-preparation.ts +++ b/bindings/nodejs/examples/client/offline_signing/01-transaction-preparation.ts @@ -16,13 +16,15 @@ const PREPARED_TRANSACTION_FILE_NAME = // In this example we will get inputs and prepare a transaction async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const onlineClient = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], localPow: true, }); diff --git a/bindings/nodejs/examples/client/offline_signing/02-transaction-signing.ts b/bindings/nodejs/examples/client/offline_signing/02-transaction-signing.ts index 66bd8fd172..0c338cbe7d 100644 --- a/bindings/nodejs/examples/client/offline_signing/02-transaction-signing.ts +++ b/bindings/nodejs/examples/client/offline_signing/02-transaction-signing.ts @@ -16,16 +16,17 @@ const SIGNED_TRANSACTION_FILE_NAME = 'offline-signing-signed-transaction.json'; // In this example we will sign the prepared transaction. async function run() { initLogger(); + for (const envVar of ['MNEMONIC']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } + } const offlineClient = new Client({}); try { - if (!process.env.MNEMONIC) { - throw new Error('.env MNEMONIC is undefined, see .env.example'); - } - const secretManager = { - mnemonic: process.env.MNEMONIC, + mnemonic: process.env.MNEMONIC as string, }; // Read in prepared transaction from example 2_transaction_preparation diff --git a/bindings/nodejs/examples/client/offline_signing/03-send-block.ts b/bindings/nodejs/examples/client/offline_signing/03-send-block.ts index e3410eff63..a6d52660cd 100644 --- a/bindings/nodejs/examples/client/offline_signing/03-send-block.ts +++ b/bindings/nodejs/examples/client/offline_signing/03-send-block.ts @@ -14,12 +14,14 @@ const SIGNED_TRANSACTION_FILE_NAME = 'offline-signing-signed-transaction.json'; // In this example we will send the signed transaction in a block. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL', 'EXPLORER_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const onlineClient = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], localPow: true, }); diff --git a/bindings/nodejs/examples/evm/send-evm-transaction.ts b/bindings/nodejs/examples/evm/send-evm-transaction.ts index ccc7450819..32e7b011c2 100644 --- a/bindings/nodejs/examples/evm/send-evm-transaction.ts +++ b/bindings/nodejs/examples/evm/send-evm-transaction.ts @@ -37,12 +37,14 @@ const TX_OPTIONS = { async function run(): Promise { const provider = new Web3(RPC_ENDPOINT); - try { - if (!process.env.MNEMONIC) { - throw new Error('.env MNEMONIC is undefined, see .env.example'); + for (const envVar of ['MNEMONIC']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); } + } + try { const mnemonicSecretManager = { - mnemonic: process.env.MNEMONIC, + mnemonic: process.env.MNEMONIC as string, }; const secretManager = new SecretManager(mnemonicSecretManager); diff --git a/bindings/nodejs/examples/exchange/3-check-balance.ts b/bindings/nodejs/examples/exchange/3-check-balance.ts index ba3deb9ad8..797346b58d 100644 --- a/bindings/nodejs/examples/exchange/3-check-balance.ts +++ b/bindings/nodejs/examples/exchange/3-check-balance.ts @@ -12,10 +12,12 @@ require('dotenv').config({ path: '.env' }); async function run() { try { - if (!process.env.WALLET_DB_PATH) { - throw new Error( - '.env WALLET_DB_PATH is undefined, see .env.example', - ); + for (const envVar of ['WALLET_DB_PATH']) { + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } } const wallet = new Wallet({ diff --git a/bindings/nodejs/examples/exchange/4-listen-events.ts b/bindings/nodejs/examples/exchange/4-listen-events.ts index 0ab9604732..d0a0cc600a 100644 --- a/bindings/nodejs/examples/exchange/4-listen-events.ts +++ b/bindings/nodejs/examples/exchange/4-listen-events.ts @@ -12,10 +12,12 @@ require('dotenv').config({ path: '.env' }); async function run() { try { - if (!process.env.WALLET_DB_PATH) { - throw new Error( - '.env WALLET_DB_PATH is undefined, see .env.example', - ); + for (const envVar of ['WALLET_DB_PATH']) { + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } } const wallet = new Wallet({ diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/check-balance.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/check-balance.ts index 042db1296a..8f7eec2249 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/check-balance.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/check-balance.ts @@ -12,8 +12,10 @@ require('dotenv').config({ path: '.env' }); // This example syncs the account and prints the balance. async function run() { initLogger(); - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); + for (const envVar of ['WALLET_DB_PATH']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } try { const wallet = new Wallet({ diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-accounts.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-accounts.ts index f3e5662372..e9bf5fa289 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-accounts.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-accounts.ts @@ -12,8 +12,10 @@ require('dotenv').config({ path: '.env' }); // This example lists all accounts in the wallet. async function run() { initLogger(); - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); + for (const envVar of ['WALLET_DB_PATH']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } try { const wallet = new Wallet({ diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-addresses.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-addresses.ts index 02e56eb9b5..47f8356e7e 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-addresses.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-addresses.ts @@ -12,8 +12,10 @@ require('dotenv').config({ path: '.env' }); // This example lists all addresses in the account. async function run() { initLogger(); - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); + for (const envVar of ['WALLET_DB_PATH']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } try { const wallet = new Wallet({ diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-outputs.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-outputs.ts index a3fe14be53..77a8bf5f51 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-outputs.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-outputs.ts @@ -12,8 +12,10 @@ require('dotenv').config({ path: '.env' }); // This example lists all outputs in the account. async function run() { initLogger(); - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); + for (const envVar of ['WALLET_DB_PATH']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } try { const wallet = new Wallet({ diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-transactions.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-transactions.ts index 0cfd55dd81..195d9a059b 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-transactions.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-transactions.ts @@ -12,8 +12,10 @@ require('dotenv').config({ path: '.env' }); // This example lists all transactions in the account. async function run() { initLogger(); - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); + for (const envVar of ['WALLET_DB_PATH']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } try { const wallet = new Wallet({ diff --git a/bindings/nodejs/examples/how_tos/advanced_transactions/advanced_transaction.ts b/bindings/nodejs/examples/how_tos/advanced_transactions/advanced_transaction.ts index 94b36a0298..97962a8d65 100644 --- a/bindings/nodejs/examples/how_tos/advanced_transactions/advanced_transaction.ts +++ b/bindings/nodejs/examples/how_tos/advanced_transactions/advanced_transaction.ts @@ -19,10 +19,16 @@ require('dotenv').config({ path: '.env' }); async function run() { initLogger(); try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); + for (const envVar of [ + 'WALLET_DB_PATH', + 'STRONGHOLD_PASSWORD', + 'EXPLORER_URL', + ]) { + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } } const wallet = new Wallet({ @@ -34,7 +40,9 @@ async function run() { await account.sync(); // To sign a transaction we need to unlock stronghold. - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); // Create an output with amount 1_000_000 and a timelock of 1 hour const in_an_hour = Math.floor(Date.now() / 1000) + 3600; diff --git a/bindings/nodejs/examples/how_tos/advanced_transactions/claim_transaction.ts b/bindings/nodejs/examples/how_tos/advanced_transactions/claim_transaction.ts index 0a37b082c5..c89d756e69 100644 --- a/bindings/nodejs/examples/how_tos/advanced_transactions/claim_transaction.ts +++ b/bindings/nodejs/examples/how_tos/advanced_transactions/claim_transaction.ts @@ -11,10 +11,16 @@ require('dotenv').config({ path: '.env' }); async function run() { initLogger(); try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); + for (const envVar of [ + 'WALLET_DB_PATH', + 'STRONGHOLD_PASSWORD', + 'EXPLORER_URL', + ]) { + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } } const wallet = new Wallet({ @@ -26,7 +32,9 @@ async function run() { await account.sync(); // To sign a transaction we need to unlock stronghold. - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); // Get all claimable outputs const output_ids = await account.claimableOutputs(OutputsToClaim.All); diff --git a/bindings/nodejs/examples/how_tos/advanced_transactions/send_micro_transaction.ts b/bindings/nodejs/examples/how_tos/advanced_transactions/send_micro_transaction.ts index 090ab1a8b4..8fe0853ec0 100644 --- a/bindings/nodejs/examples/how_tos/advanced_transactions/send_micro_transaction.ts +++ b/bindings/nodejs/examples/how_tos/advanced_transactions/send_micro_transaction.ts @@ -11,10 +11,16 @@ require('dotenv').config({ path: '.env' }); async function run() { initLogger(); try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); + for (const envVar of [ + 'WALLET_DB_PATH', + 'STRONGHOLD_PASSWORD', + 'EXPLORER_URL', + ]) { + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } } const wallet = new Wallet({ @@ -26,7 +32,9 @@ async function run() { await account.sync(); // To sign a transaction we need to unlock stronghold. - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); // Replace with the address of your choice! const address = diff --git a/bindings/nodejs/examples/how_tos/alias/create.ts b/bindings/nodejs/examples/how_tos/alias/create.ts index 7a69e07591..15c6ff77a0 100644 --- a/bindings/nodejs/examples/how_tos/alias/create.ts +++ b/bindings/nodejs/examples/how_tos/alias/create.ts @@ -17,13 +17,14 @@ require('dotenv').config({ path: '.env' }); async function run() { initLogger(); for (const envVar of [ - 'FAUCET_URL', 'WALLET_DB_PATH', 'STRONGHOLD_PASSWORD', - ]) + 'EXPLORER_URL', + ]) { if (!(envVar in process.env)) { throw new Error(`.env ${envVar} is undefined, see .env.example`); } + } try { // Create the wallet diff --git a/bindings/nodejs/examples/how_tos/alias/destroy.ts b/bindings/nodejs/examples/how_tos/alias/destroy.ts index 32d3ec9a7d..8bad0d47f0 100644 --- a/bindings/nodejs/examples/how_tos/alias/destroy.ts +++ b/bindings/nodejs/examples/how_tos/alias/destroy.ts @@ -13,13 +13,14 @@ require('dotenv').config({ path: '.env' }); async function run() { initLogger(); for (const envVar of [ - 'FAUCET_URL', 'WALLET_DB_PATH', 'STRONGHOLD_PASSWORD', - ]) + 'EXPLORER_URL', + ]) { if (!(envVar in process.env)) { throw new Error(`.env ${envVar} is undefined, see .env.example`); } + } try { // Create the wallet diff --git a/bindings/nodejs/examples/how_tos/alias/governance-transition.ts b/bindings/nodejs/examples/how_tos/alias/governance-transition.ts index 87a77deb54..636608cb74 100644 --- a/bindings/nodejs/examples/how_tos/alias/governance-transition.ts +++ b/bindings/nodejs/examples/how_tos/alias/governance-transition.ts @@ -20,13 +20,14 @@ require('dotenv').config({ path: '.env' }); async function run() { initLogger(); for (const envVar of [ - 'FAUCET_URL', 'WALLET_DB_PATH', 'STRONGHOLD_PASSWORD', - ]) + 'EXPLORER_URL', + ]) { if (!(envVar in process.env)) { throw new Error(`.env ${envVar} is undefined, see .env.example`); } + } try { // Create the wallet diff --git a/bindings/nodejs/examples/how_tos/alias/state-transition.ts b/bindings/nodejs/examples/how_tos/alias/state-transition.ts index d1b230504a..ba2fd75227 100644 --- a/bindings/nodejs/examples/how_tos/alias/state-transition.ts +++ b/bindings/nodejs/examples/how_tos/alias/state-transition.ts @@ -15,13 +15,14 @@ const NEW_STATE_METADATA = 'updated state metadata 1'; async function run() { initLogger(); for (const envVar of [ - 'FAUCET_URL', 'WALLET_DB_PATH', 'STRONGHOLD_PASSWORD', - ]) + 'EXPLORER_URL', + ]) { if (!(envVar in process.env)) { throw new Error(`.env ${envVar} is undefined, see .env.example`); } + } try { // Create the wallet diff --git a/bindings/nodejs/examples/how_tos/alias_wallet/request-funds.ts b/bindings/nodejs/examples/how_tos/alias_wallet/request-funds.ts index 534f723ce8..98cf5d1d2d 100644 --- a/bindings/nodejs/examples/how_tos/alias_wallet/request-funds.ts +++ b/bindings/nodejs/examples/how_tos/alias_wallet/request-funds.ts @@ -16,11 +16,13 @@ require('dotenv').config({ path: '.env' }); // In this example we request funds to an alias wallet. async function run() { initLogger(); - if (!process.env.FAUCET_URL) { - throw new Error('.env FAUCET_URL is undefined, see .env.example'); + for (const envVar of ['WALLET_DB_PATH', 'FAUCET_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } try { - const faucetUrl = process.env.FAUCET_URL; + const faucetUrl = process.env.FAUCET_URL as string; // Create the wallet const wallet = new Wallet({ diff --git a/bindings/nodejs/examples/how_tos/alias_wallet/transaction.ts b/bindings/nodejs/examples/how_tos/alias_wallet/transaction.ts index 0ffe4ef766..cdf35ec47c 100644 --- a/bindings/nodejs/examples/how_tos/alias_wallet/transaction.ts +++ b/bindings/nodejs/examples/how_tos/alias_wallet/transaction.ts @@ -17,10 +17,12 @@ require('dotenv').config({ path: '.env' }); async function run() { initLogger(); try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); + for (const envVar of ['WALLET_DB_PATH', 'STRONGHOLD_PASSWORD']) { + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } } const syncOptions = { @@ -35,7 +37,9 @@ async function run() { const account = await wallet.getAccount('Alice'); - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); const balance = await account.sync(syncOptions); diff --git a/bindings/nodejs/examples/how_tos/client/get-health.ts b/bindings/nodejs/examples/how_tos/client/get-health.ts index f42d21fd83..f99b3a6fcb 100644 --- a/bindings/nodejs/examples/how_tos/client/get-health.ts +++ b/bindings/nodejs/examples/how_tos/client/get-health.ts @@ -10,18 +10,22 @@ require('dotenv').config({ path: '.env' }); // In this example we will get the node health async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], localPow: true, }); try { - const isHealthy = await client.getHealth(process.env.NODE_URL); + const isHealthy = await client.getHealth( + process.env.NODE_URL as string, + ); console.log('Healthy: ', isHealthy); } catch (error) { console.error('Error: ', error); diff --git a/bindings/nodejs/examples/how_tos/client/get-info.ts b/bindings/nodejs/examples/how_tos/client/get-info.ts index 4c6c4188ff..82cd1281bf 100644 --- a/bindings/nodejs/examples/how_tos/client/get-info.ts +++ b/bindings/nodejs/examples/how_tos/client/get-info.ts @@ -10,13 +10,15 @@ require('dotenv').config({ path: '.env' }); // In this example we will get information about the node async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], localPow: true, }); diff --git a/bindings/nodejs/examples/how_tos/client/get-outputs.ts b/bindings/nodejs/examples/how_tos/client/get-outputs.ts index ebbef29b82..945bb167a9 100644 --- a/bindings/nodejs/examples/how_tos/client/get-outputs.ts +++ b/bindings/nodejs/examples/how_tos/client/get-outputs.ts @@ -10,13 +10,15 @@ require('dotenv').config({ path: '.env' }); // In this example we will get the outputs of a known address async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); + for (const envVar of ['NODE_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } } const client = new Client({ // Insert your node URL in the .env. - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], }); try { diff --git a/bindings/nodejs/examples/how_tos/native_tokens/burn.ts b/bindings/nodejs/examples/how_tos/native_tokens/burn.ts index 1d4ba6e527..55c0e1c4f6 100644 --- a/bindings/nodejs/examples/how_tos/native_tokens/burn.ts +++ b/bindings/nodejs/examples/how_tos/native_tokens/burn.ts @@ -18,6 +18,11 @@ const BURN_AMOUNT = BigInt(1); // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/native_tokens/burn.ts async function run() { + for (const envVar of ['EXPLORER_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } + } try { // Create the wallet const wallet = await getUnlockedWallet(); diff --git a/bindings/nodejs/examples/how_tos/native_tokens/create.ts b/bindings/nodejs/examples/how_tos/native_tokens/create.ts index 677020444e..ed639566eb 100644 --- a/bindings/nodejs/examples/how_tos/native_tokens/create.ts +++ b/bindings/nodejs/examples/how_tos/native_tokens/create.ts @@ -18,6 +18,11 @@ const MAXIMUM_SUPPLY = BigInt(100); // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/native_tokens/create.ts async function run() { + for (const envVar of ['EXPLORER_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } + } try { // Create the wallet const wallet = await getUnlockedWallet(); diff --git a/bindings/nodejs/examples/how_tos/native_tokens/destroy-foundry.ts b/bindings/nodejs/examples/how_tos/native_tokens/destroy-foundry.ts index 2e7040cd31..d0dd4aa68a 100644 --- a/bindings/nodejs/examples/how_tos/native_tokens/destroy-foundry.ts +++ b/bindings/nodejs/examples/how_tos/native_tokens/destroy-foundry.ts @@ -12,6 +12,11 @@ import { getUnlockedWallet } from '../../wallet/common'; // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/native_tokens/destroy-foundry.ts async function run() { + for (const envVar of ['EXPLORER_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } + } try { // Create the wallet const wallet = await getUnlockedWallet(); diff --git a/bindings/nodejs/examples/how_tos/native_tokens/melt.ts b/bindings/nodejs/examples/how_tos/native_tokens/melt.ts index 248aa25c3d..1078ce6ff3 100644 --- a/bindings/nodejs/examples/how_tos/native_tokens/melt.ts +++ b/bindings/nodejs/examples/how_tos/native_tokens/melt.ts @@ -14,6 +14,11 @@ const MELT_AMOUNT = BigInt(10); // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/native_tokens/melt.ts async function run() { + for (const envVar of ['EXPLORER_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } + } try { // Create the wallet const wallet = await getUnlockedWallet(); diff --git a/bindings/nodejs/examples/how_tos/native_tokens/mint.ts b/bindings/nodejs/examples/how_tos/native_tokens/mint.ts index 241b5c19c9..7778e7458e 100644 --- a/bindings/nodejs/examples/how_tos/native_tokens/mint.ts +++ b/bindings/nodejs/examples/how_tos/native_tokens/mint.ts @@ -14,6 +14,11 @@ const MINT_AMOUNT = BigInt(10); // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/native_tokens/mint.ts async function run() { + for (const envVar of ['EXPLORER_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } + } try { // Create the wallet const wallet = await getUnlockedWallet(); diff --git a/bindings/nodejs/examples/how_tos/native_tokens/send.ts b/bindings/nodejs/examples/how_tos/native_tokens/send.ts index 5dfbe6cb97..fbec4bf831 100644 --- a/bindings/nodejs/examples/how_tos/native_tokens/send.ts +++ b/bindings/nodejs/examples/how_tos/native_tokens/send.ts @@ -19,6 +19,11 @@ const RECV_ADDRESS = // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/native_tokens/send.ts async function run() { + for (const envVar of ['EXPLORER_URL']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } + } try { // Create the wallet const wallet = await getUnlockedWallet(); diff --git a/bindings/nodejs/examples/how_tos/nft_collection/00_mint_issuer_nft.ts b/bindings/nodejs/examples/how_tos/nft_collection/00_mint_issuer_nft.ts index 7df8cbfb94..2d49b19e49 100644 --- a/bindings/nodejs/examples/how_tos/nft_collection/00_mint_issuer_nft.ts +++ b/bindings/nodejs/examples/how_tos/nft_collection/00_mint_issuer_nft.ts @@ -22,10 +22,16 @@ require('dotenv').config({ path: '.env' }); // yarn run-example ./how_tos/nfts/00_mint_issuer_nft.ts async function run() { try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); + for (const envVar of [ + 'WALLET_DB_PATH', + 'STRONGHOLD_PASSWORD', + 'EXPLORER_URL', + ]) { + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } } // Create the wallet @@ -34,7 +40,9 @@ async function run() { }); // To sign a transaction we need to unlock stronghold. - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); // Get the account we generated with `01-create-wallet` const account = await wallet.getAccount('Alice'); diff --git a/bindings/nodejs/examples/how_tos/nft_collection/01_mint_collection_nft.ts b/bindings/nodejs/examples/how_tos/nft_collection/01_mint_collection_nft.ts index c78aeba3b7..e9e840b82e 100644 --- a/bindings/nodejs/examples/how_tos/nft_collection/01_mint_collection_nft.ts +++ b/bindings/nodejs/examples/how_tos/nft_collection/01_mint_collection_nft.ts @@ -18,10 +18,16 @@ const NUM_NFTS_MINTED_PER_TRANSACTION = 50; // yarn run-example ./how_tos/nfts/01_mint_collection_nft.ts async function run() { try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); + for (const envVar of [ + 'WALLET_DB_PATH', + 'STRONGHOLD_PASSWORD', + 'EXPLORER_URL', + ]) { + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } } // Create the wallet @@ -30,7 +36,9 @@ async function run() { }); // To sign a transaction we need to unlock stronghold. - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); // Get the account we generated with `how_tos/accounts_and_addresses/create-account` const account = await wallet.getAccount('Alice'); diff --git a/bindings/nodejs/examples/how_tos/nfts/burn_nft.ts b/bindings/nodejs/examples/how_tos/nfts/burn_nft.ts index 52f0e0eff0..45c5d42560 100644 --- a/bindings/nodejs/examples/how_tos/nfts/burn_nft.ts +++ b/bindings/nodejs/examples/how_tos/nfts/burn_nft.ts @@ -13,10 +13,16 @@ require('dotenv').config({ path: '.env' }); // yarn run-example ./how_tos/nfts/burn_nft.ts async function run() { try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); + for (const envVar of [ + 'WALLET_DB_PATH', + 'STRONGHOLD_PASSWORD', + 'EXPLORER_URL', + ]) { + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } } // Create the wallet @@ -28,7 +34,9 @@ async function run() { const account = await wallet.getAccount('Alice'); // We need to unlock stronghold. - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); // May want to ensure the account is synced before sending a transaction. let balance = await account.sync(); diff --git a/bindings/nodejs/examples/how_tos/nfts/mint_nft.ts b/bindings/nodejs/examples/how_tos/nfts/mint_nft.ts index d8853a5dca..a05c2b6fc5 100644 --- a/bindings/nodejs/examples/how_tos/nfts/mint_nft.ts +++ b/bindings/nodejs/examples/how_tos/nfts/mint_nft.ts @@ -33,11 +33,16 @@ const NFT2_AMOUNT = '1000000'; // yarn run-example ./how_tos/nfts/mint_nft.ts async function run() { try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } + for (const envVar of [ + 'STRONGHOLD_PASSWORD', + 'WALLET_DB_PATH', + 'EXPLORER_URL', + ]) + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } const wallet = new Wallet({ storagePath: process.env.WALLET_DB_PATH, @@ -49,7 +54,9 @@ async function run() { const senderAddress = (await account.addresses())[0].address; // We need to unlock stronghold. - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); const metadata = new Irc27Metadata( 'video/mp4', diff --git a/bindings/nodejs/examples/how_tos/nfts/send_nft.ts b/bindings/nodejs/examples/how_tos/nfts/send_nft.ts index e0ad2944b8..03ba0bd048 100644 --- a/bindings/nodejs/examples/how_tos/nfts/send_nft.ts +++ b/bindings/nodejs/examples/how_tos/nfts/send_nft.ts @@ -17,10 +17,16 @@ const RECV_ADDRESS = // yarn run-example ./how_tos/nfts/send_nft.ts async function run() { try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); + for (const envVar of [ + 'WALLET_DB_PATH', + 'STRONGHOLD_PASSWORD', + 'EXPLORER_URL', + ]) { + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } } const wallet = new Wallet({ @@ -31,7 +37,9 @@ async function run() { const account = await wallet.getAccount('Alice'); // We need to unlock stronghold. - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); // May want to ensure the account is synced before sending a transaction. const balance = await account.sync(); diff --git a/bindings/nodejs/examples/how_tos/sign_and_verify_ed25519/sign-ed25519.ts b/bindings/nodejs/examples/how_tos/sign_and_verify_ed25519/sign-ed25519.ts index 5b1e992e7b..acb827b9ae 100644 --- a/bindings/nodejs/examples/how_tos/sign_and_verify_ed25519/sign-ed25519.ts +++ b/bindings/nodejs/examples/how_tos/sign_and_verify_ed25519/sign-ed25519.ts @@ -30,12 +30,13 @@ async function run() { initLogger(); try { - for (const envVar of ['STRONGHOLD_PASSWORD', 'MNEMONIC']) + for (const envVar of ['STRONGHOLD_PASSWORD', 'MNEMONIC']) { if (!(envVar in process.env)) { throw new Error( `.env ${envVar} is undefined, see .env.example`, ); } + } const secretManager = new SecretManager({ stronghold: { diff --git a/bindings/nodejs/examples/how_tos/sign_secp256k1_ecdsa/sign-secp256k1_ecdsa.ts b/bindings/nodejs/examples/how_tos/sign_secp256k1_ecdsa/sign-secp256k1_ecdsa.ts index 333a5bd0ed..aed2553f09 100644 --- a/bindings/nodejs/examples/how_tos/sign_secp256k1_ecdsa/sign-secp256k1_ecdsa.ts +++ b/bindings/nodejs/examples/how_tos/sign_secp256k1_ecdsa/sign-secp256k1_ecdsa.ts @@ -24,12 +24,13 @@ async function run() { initLogger(); try { - for (const envVar of ['STRONGHOLD_PASSWORD', 'MNEMONIC']) + for (const envVar of ['STRONGHOLD_PASSWORD', 'MNEMONIC']) { if (!(envVar in process.env)) { throw new Error( `.env ${envVar} is undefined, see .env.example`, ); } + } const secretManager = new SecretManager({ stronghold: { diff --git a/bindings/nodejs/examples/how_tos/simple_transaction/request-funds.ts b/bindings/nodejs/examples/how_tos/simple_transaction/request-funds.ts index 2a86b934ef..ea51802304 100644 --- a/bindings/nodejs/examples/how_tos/simple_transaction/request-funds.ts +++ b/bindings/nodejs/examples/how_tos/simple_transaction/request-funds.ts @@ -12,11 +12,13 @@ require('dotenv').config({ path: '.env' }); // This example requests funds from the faucet async function run() { initLogger(); - if (!process.env.FAUCET_URL) { - throw new Error('.env FAUCET_URL is undefined, see .env.example'); + for (const envVar of ['FAUCET_URL', 'WALLET_DB_PATH']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is not defined`); + } } try { - const faucetUrl = process.env.FAUCET_URL; + const faucetUrl = process.env.FAUCET_URL as string; // Create the wallet const wallet = new Wallet({ diff --git a/bindings/nodejs/examples/how_tos/simple_transaction/simple-transaction.ts b/bindings/nodejs/examples/how_tos/simple_transaction/simple-transaction.ts index 78c4079e5b..c4ea523627 100644 --- a/bindings/nodejs/examples/how_tos/simple_transaction/simple-transaction.ts +++ b/bindings/nodejs/examples/how_tos/simple_transaction/simple-transaction.ts @@ -13,10 +13,14 @@ require('dotenv').config({ path: '.env' }); async function run() { initLogger(); try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); + for (const envVar of [ + 'STRONGHOLD_PASSWORD', + 'WALLET_DB_PATH', + 'EXPLORER_URL', + ]) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is not defined`); + } } const wallet = new Wallet({ @@ -28,7 +32,9 @@ async function run() { await account.sync(); // To sign a transaction we need to unlock stronghold. - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); // Replace with the address of your choice! const address = diff --git a/bindings/nodejs/examples/secret_manager/generate-addresses.ts b/bindings/nodejs/examples/secret_manager/generate-addresses.ts index 19ad35482f..ab5ab8c823 100644 --- a/bindings/nodejs/examples/secret_manager/generate-addresses.ts +++ b/bindings/nodejs/examples/secret_manager/generate-addresses.ts @@ -10,13 +10,14 @@ require('dotenv').config({ path: '.env' }); // In this example we will create addresses from a mnemonic defined in .env async function run() { initLogger(); - - try { - if (!process.env.MNEMONIC) { - throw new Error('.env MNEMONIC is undefined, see .env.example'); + for (const envVar of ['MNEMONIC']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); } + } + try { const mnemonicSecretManager = { - mnemonic: process.env.MNEMONIC, + mnemonic: process.env.MNEMONIC as string, }; const secretManager = new SecretManager(mnemonicSecretManager); diff --git a/bindings/nodejs/examples/wallet/06-send-micro-transaction.ts b/bindings/nodejs/examples/wallet/06-send-micro-transaction.ts index 0a69fab288..4ba7541d88 100644 --- a/bindings/nodejs/examples/wallet/06-send-micro-transaction.ts +++ b/bindings/nodejs/examples/wallet/06-send-micro-transaction.ts @@ -20,6 +20,13 @@ const RECV_ADDRESS = // yarn run-example ./wallet/06-send-micro-transaction.ts async function run() { try { + for (const envVar of ['EXPLORER_URL']) { + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } + } // Create the wallet const wallet = await getUnlockedWallet(); diff --git a/bindings/nodejs/examples/wallet/migrate-db-chrysalis-to-stardust.ts b/bindings/nodejs/examples/wallet/migrate-db-chrysalis-to-stardust.ts index 5fa766969c..236c407541 100644 --- a/bindings/nodejs/examples/wallet/migrate-db-chrysalis-to-stardust.ts +++ b/bindings/nodejs/examples/wallet/migrate-db-chrysalis-to-stardust.ts @@ -16,10 +16,11 @@ async function run() { levelFilter: 'debug', targetExclusions: ['h2', 'hyper', 'rustls'], }); - for (const envVar of ['NODE_URL', 'STRONGHOLD_PASSWORD']) + for (const envVar of ['NODE_URL', 'STRONGHOLD_PASSWORD']) { if (!(envVar in process.env)) { throw new Error(`.env ${envVar} is undefined, see .env.example`); } + } migrateDbChrysalisToStardust(walletDbPath, 'password'); diff --git a/bindings/nodejs/examples/wallet/migrate-stronghold-snapshot-v2-to-v3.ts b/bindings/nodejs/examples/wallet/migrate-stronghold-snapshot-v2-to-v3.ts index 0a3663a269..988d9749f2 100644 --- a/bindings/nodejs/examples/wallet/migrate-stronghold-snapshot-v2-to-v3.ts +++ b/bindings/nodejs/examples/wallet/migrate-stronghold-snapshot-v2-to-v3.ts @@ -16,10 +16,11 @@ const v3Path = './v3.stronghold'; // yarn run-example wallet/migrate-stronghold-snapshot-v2-to-v3.ts async function run() { - for (const envVar of ['NODE_URL', 'STRONGHOLD_PASSWORD']) + for (const envVar of ['NODE_URL', 'WALLET_DB_PATH']) { if (!(envVar in process.env)) { throw new Error(`.env ${envVar} is undefined, see .env.example`); } + } let walletOptions: WalletOptions = { storagePath: process.env.WALLET_DB_PATH,