How to interface nns ledger for local dev

for my frontend, user nid to login icp first then connect to nnsledger to get balance. i managed to deploy local ledger canister where candid file and corresponding js/ts interface file will be auto genreated based on dfx.json. now i want to connect to nns ledger from my local frontend canister to test. is it doable? can i just change the canister id to switch between my local ledger and nns ledger? can use same local ledger candid file and js/ts file for both? please help. thanks.

I’m confuse you deployed two ledgers? or what do you mean with “local ledger and nns ledger”?

In any case, few resources:

  1. If you want to interact through Icrc end points, you can use the @dfinity/ledger js libs (https://github.com/dfinity/ic-js/tree/main/packages/ledger)

  2. In @dfinity/nns there are some functions for the ICP ledger as well, notable for the account identifier (https://github.com/dfinity/ic-js/tree/main/packages/nns)

  3. In Juno I use the ICP / NNS ledger as well. I deploy it as you do and got the declarations locally too, so you can probably have a look at the source code to find the “get the account balance” part if it can be useful: https://github.com/buildwithjuno/juno. More precisely there is my function getBalance. I use the above @dfinity/ledger library to fetch it.

sorry for confusion. only one, i follow online guide to deploy ledger cansiter locally for dev purpose. the flow is local frontend → local ledger, but now i want to try local frontend → nns ledger. can it be done? any sample for reference for setup. thanks. i will study the resources you mentioned

So here with “nns ledger”, I understand “nns / icp ledger on mainnet”.

Can it be done? Yes. It’s basically the same but you have to set the host in agent-js to http://icp0.io, avoid to fetch root key and provide the effective canister ID on mainnet.

That said, not sure why you would call mainnet from local, I would suggest to stick to local.