// Copyright 2021-2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 import { Client, initLogger } from '@iota/sdk'; require('dotenv').config({ path: '.env' }); // Run with command: // yarn run-example ./how_tos/client/get-outputs.ts // In this example we will get the outputs of a known address async function run() { initLogger(); 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 as string], }); try { // Get output ids of basic outputs that can be controlled by this address without further unlock constraints const outputIdsResponse = await client.basicOutputIds([ { address: 'rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy', }, { hasExpiration: false }, { hasTimelock: false }, { hasStorageDepositReturn: false }, ]); console.log('First output of query:'); console.log('ID: ', outputIdsResponse.items[0]); const outputs = await client.getOutputs(outputIdsResponse.items); console.log(outputs[0]); } catch (error) { console.error('Error: ', error); } } run().then(() => process.exit());