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 8185522ea0..f1e080bbb4 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,6 +12,9 @@ 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'); + } try { const wallet = new Wallet({ storagePath: process.env.WALLET_DB_PATH, diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-address.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-address.ts index 2b7861dc44..63a74b82da 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-address.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-address.ts @@ -10,13 +10,15 @@ require('dotenv').config({ path: '.env' }); // This example creates an address async function run() { initLogger(); + if (!process.env.WALLET_DB_PATH) { + throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); + } + if (!process.env.STRONGHOLD_PASSWORD) { + throw new Error( + '.env STRONGHOLD_PASSWORD is undefined, see .env.example', + ); + } try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } - const wallet = new Wallet({ storagePath: process.env.WALLET_DB_PATH, }); 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 c1190a96ae..3f4022d12e 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 @@ -3,12 +3,18 @@ import { Wallet, initLogger } from '@iota/sdk'; +// This example uses secrets in environment variables for simplicity which should not be done in production. +require('dotenv').config({ path: '.env' }); + // Run with command: // yarn run-example ./how_tos/accounts_and_addresses/list-accounts.ts // 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'); + } try { const wallet = new Wallet({ storagePath: process.env.WALLET_DB_PATH, 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 20aa631eec..f5bb896677 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 @@ -3,12 +3,18 @@ import { Wallet, initLogger } from '@iota/sdk'; +// This example uses secrets in environment variables for simplicity which should not be done in production. +require('dotenv').config({ path: '.env' }); + // Run with command: // yarn run-example ./how_tos/accounts_and_addresses/list-addresses.ts // 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'); + } try { const wallet = new Wallet({ storagePath: process.env.WALLET_DB_PATH, 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 c64f2fa8eb..3902c322d4 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 @@ -3,12 +3,18 @@ import { Wallet, initLogger } from '@iota/sdk'; +// This example uses secrets in environment variables for simplicity which should not be done in production. +require('dotenv').config({ path: '.env' }); + // Run with command: // yarn run-example ./how_tos/accounts_and_addresses/list-outputs.ts // 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'); + } try { const wallet = new Wallet({ storagePath: process.env.WALLET_DB_PATH, 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 4e0fd758ba..8f77e0a7fd 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 @@ -3,12 +3,18 @@ import { Wallet, initLogger } from '@iota/sdk'; +// This example uses secrets in environment variables for simplicity which should not be done in production. +require('dotenv').config({ path: '.env' }); + // Run with command: // yarn run-example ./how_tos/accounts_and_addresses/list-transactions.ts // 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'); + } try { const wallet = new Wallet({ storagePath: process.env.WALLET_DB_PATH, diff --git a/bindings/nodejs/examples/how_tos/alias/create.ts b/bindings/nodejs/examples/how_tos/alias/create.ts index a71ff6da2b..f9a6b8cd42 100644 --- a/bindings/nodejs/examples/how_tos/alias/create.ts +++ b/bindings/nodejs/examples/how_tos/alias/create.ts @@ -15,6 +15,14 @@ async function run() { if (!process.env.FAUCET_URL) { throw new Error('.env FAUCET_URL is undefined, see .env.example'); } + if (!process.env.WALLET_DB_PATH) { + throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); + } + if (!process.env.STRONGHOLD_PASSWORD) { + throw new Error( + '.env STRONGHOLD_PASSWORD is undefined, see .env.example', + ); + } try { // Create the wallet const wallet = new Wallet({ @@ -27,12 +35,11 @@ async function run() { // May want to ensure the account is synced before sending a transaction. let balance = await account.sync(); - if (balance.aliases.length == 0) { - throw new Error(`No Alias available in account 'Alice'`); - } - console.log(`Aliases BEFORE:\n`, balance.aliases); + // To sign a transaction we need to unlock stronghold. + await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + console.log('Sending the create-alias transaction...'); // Create an alias diff --git a/bindings/nodejs/examples/how_tos/alias/destroy.ts b/bindings/nodejs/examples/how_tos/alias/destroy.ts index 3e99167dfd..0ba54d55fc 100644 --- a/bindings/nodejs/examples/how_tos/alias/destroy.ts +++ b/bindings/nodejs/examples/how_tos/alias/destroy.ts @@ -15,6 +15,14 @@ async function run() { if (!process.env.FAUCET_URL) { throw new Error('.env FAUCET_URL is undefined, see .env.example'); } + if (!process.env.WALLET_DB_PATH) { + throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); + } + if (!process.env.STRONGHOLD_PASSWORD) { + throw new Error( + '.env STRONGHOLD_PASSWORD is undefined, see .env.example', + ); + } try { // Create the wallet const wallet = new Wallet({ @@ -35,6 +43,10 @@ async function run() { const aliasId = balance.aliases[0]; console.log(`Aliases BEFORE destroying:\n`, balance.aliases); + + // To sign a transaction we need to unlock stronghold. + await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + console.log('Sending the destroy-alias transaction...'); // Destroy an alias