The getAccounts() method retrieves all DSA (DeFi Smart Account) instances that are owned by a specific authority address. This is useful for discovering all DSA accounts that a user controls.
The ethereum address or ENS name (e.g., “vitalik.eth”) of the authority whose DSA accounts you want to retrieve. If not provided, it will use the currently connected wallet address.
import DSA from "dsa-connect";import Web3 from "web3";const web3 = new Web3(window.ethereum);const dsa = new DSA(web3, 1); // 1 for Ethereum mainnet// Get all DSA accounts for a specific addressconst accounts = await dsa.getAccounts("0x1234...");console.log(`Found ${accounts.length} DSA accounts:`);accounts.forEach((account) => { console.log(`ID: ${account.id}`); console.log(`Address: ${account.address}`); console.log(`Version: ${account.version}`); console.log("---");});
// Get accounts for the currently connected walletconst userAddress = (await web3.eth.getAccounts())[0];const accounts = await dsa.getAccounts(userAddress);if (accounts.length === 0) { console.log("No DSA accounts found. Create one with dsa.build()");} else { console.log(`You have ${accounts.length} DSA account(s)`);}
// Get all accounts and set the first one as activeconst accounts = await dsa.getAccounts("0x...");if (accounts.length > 0) { // Set the first account as the active instance await dsa.setInstance(accounts[0].id); console.log(`Active DSA set to ID: ${accounts[0].id}`); console.log(`Active DSA address: ${accounts[0].address}`);}
// Get all accounts and filter by versionconst accounts = await dsa.getAccounts("0x...");// Get only version 2 accounts (recommended)const v2Accounts = accounts.filter((account) => account.version === 2);console.log(`Found ${v2Accounts.length} version 2 DSA accounts`);