I’m trying to get the account id of a user and getting different things with rust and dfx.
The use case is to get the user’s subaccount of canister to transfer ICP.
But I’m getting different account ids and I’m not sure why.
It is not that dfx uses a different implementation than yours to calculate subaccounts, it’s that dfx ledger account-id is the wrong command to produce that subaccount. You want account-id(principal1, principal2); that command generates account-id(principal1, account-id(principal2, 0)). The difference is that an account ID has been sha224 hashed already, so account-id(principal2, 0) consists of completely different bytes than principal2 does.
If you want to compute principal subaccounts on the command line, use icx principal-convert --to-hex $your_principal to turn them into hex (or you can just decode them yourself - the format is just base32).
I stumbled upon more problems with that dfx command indeed.
As you correctly guessed I’m looking for something like the following in the command line: