Skip to Content
This project is an early work in progress. Funded by Project Catalyst.

Treasury

The Treasury provides functionality for managing project treasury operations and funds. This enables secure handling of project finances, revenue collection, and fund distribution for project stakeholders.

Overview

Treasury manages UTXOs that hold project funds and assets in a dedicated treasury address. Each project has its own treasury address derived from the project NFT policy, providing centralized fund management with blockchain-enforced governance.

Methods

getAddress(projectNftPolicy)

Retrieves the treasury address for a specific project based on its NFT policy.

Syntax:

const address = await sdk.provider.core.course.treasury.getAddress(projectNftPolicy)

Parameters:

  • projectNftPolicy (string) - The NFT policy ID of the project

Returns:

  • Promise<string> - The treasury address for the project

Example:

try { const projectPolicy = "a1b2c3d4e5f6..."; const treasuryAddress = await sdk.provider.core.course.treasury.getAddress(projectPolicy); console.log('Project treasury address:', treasuryAddress); // Example output: addr1q9x2kw... } catch (error) { console.error('Failed to derive treasury address:', error); }

Throws:

  • SdkError - When address derivation fails

getUtxos(projectNftPolicy?, address?)

Retrieves UTXOs associated with a project’s treasury. Can use either a project policy to derive the address or a direct address.

Syntax:

const utxos = await sdk.provider.core.course.treasury.getUtxos(projectNftPolicy?, address?)

Parameters:

  • projectNftPolicy (string, optional) - The NFT policy ID of the project
  • address (string, optional) - Direct treasury address to query

Returns:

  • Promise<Utxo[]> - Array of treasury UTXOs containing project funds and assets

Example:

// Using project policy (address will be derived) try { const projectPolicy = "a1b2c3d4e5f6..."; const utxos = await sdk.provider.core.course.treasury.getUtxos(projectPolicy); console.log(`Found ${utxos.length} treasury UTXOs`); // Calculate total treasury balance const totalLovelace = utxos.reduce((sum, utxo) => sum + parseInt(utxo.parsedValued?.coin || '0'), 0); console.log(`Total treasury balance: ${totalLovelace / 1_000_000} ADA`); // List all treasury assets utxos.forEach((utxo, index) => { console.log(`UTXO ${index + 1}:`, utxo.parsedValued?.assets); }); } catch (error) { console.error('Failed to fetch treasury UTXOs:', error); } // Using direct address try { const treasuryAddress = "addr1q9x2kw..."; const utxos = await sdk.provider.core.course.treasury.getUtxos(undefined, treasuryAddress); console.log(`Found ${utxos.length} UTXOs at treasury address`); } catch (error) { console.error('Failed to fetch UTXOs:', error); } // Treasury fund analysis try { const projectPolicy = "a1b2c3d4e5f6..."; const utxos = await sdk.provider.core.course.treasury.getUtxos(projectPolicy); if (utxos.length === 0) { console.log('Treasury is empty'); } else { console.log('Treasury Analysis:'); console.log(`- Number of UTXOs: ${utxos.length}`); console.log(`- Total ADA: ${utxos.reduce((sum, utxo) => sum + parseInt(utxo.parsedValued?.coin || '0'), 0) / 1_000_000} ADA`); console.log('- Asset types:', new Set(utxos.flatMap(utxo => utxo.parsedValued?.assets?.map(asset => asset.policyId) || [])).size); } } catch (error) { console.error('Failed to analyze treasury:', error); }

Behavior:

  • If only projectNftPolicy is provided, derives the treasury address first
  • If address is provided, uses it directly for UTXO queries
  • At least one parameter must be provided

Throws:

  • SdkError - When neither parameter is provided or when UTXO fetching fails

Use Cases:

  • Monitoring project treasury balances
  • Analyzing fund distribution and asset holdings
  • Preparing treasury reports for stakeholders
  • Managing project financial operations
  • Tracking revenue and expenditure flows
Last updated on