I’ve been banging my head against a wall trying to get the sub-accounts of a principal in NodeJS using the agent-js lib. I feel like I’m missing something silly as this seems like it should be basic functionality.
I can get the account ID from a principal quite easy using
import { Principal } from "@dfinity/principal";
import { AccountIdentifier } from "@dfinity/nns";
let ID = "XXXXX-XXXXX-..."
const principal = Principal.from(ID);
const AI = AccountIdentifier.fromPrincipal({ principal });
const AC = AI.toHex();
console.log(AC);
I’m led to believe that you can add a sub-account parameter to .fromPrincipal({principal, subAccount}) I’ve tried every kind of data type for the subAccount parameter however keep getting the error “TypeError: r.toUint8Array is not a function or its return value is not iterable”
Does anyone have working JS code for getting the sub accounts from a principal?
Oh okay, thanks, I was just following this thread, I had installed the latest one, but have just switched to @dfinity/ledger-icp and it’s fixed now. Thank you!