# How to interface nns ledger for local dev

**URL:** <https://forum.dfinity.org/t/how-to-interface-nns-ledger-for-local-dev/21505>\
**Category:** JavaScript\
**Created:** [July 19, 2023, 1:52pm UTC](https://forum.dfinity.org/t/how-to-interface-nns-ledger-for-local-dev/21505 "2023-07-19T13:52:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dctech](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/dctech/32/10622_2.png) [@dctech](https://forum.dfinity.org/u/dctech)\
**Post date:** [July 19, 2023, 1:52pm UTC](https://forum.dfinity.org/t/how-to-interface-nns-ledger-for-local-dev/21505/1 "2023-07-19T13:52:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [July 19, 2023, 2:13pm UTC](https://forum.dfinity.org/t/how-to-interface-nns-ledger-for-local-dev/21505/2 "2023-07-19T14:13:41Z")

</div>

> [@dctech](#):
>
> 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?

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](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](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](https://github.com/buildwithjuno/juno). More precisely there is my function [getBalance](https://github.com/buildwithjuno/juno/blob/7b37d0655551d6824e167dc51cdae02508a605cd/src/frontend/src/lib/api/ledger.api.ts#L12). I use the above `@dfinity/ledger` library to fetch it.

---

<div class="post-metadata">

**Author:** ![dctech](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/dctech/32/10622_2.png) [@dctech](https://forum.dfinity.org/u/dctech)\
**Post date:** [July 19, 2023, 2:21pm UTC](https://forum.dfinity.org/t/how-to-interface-nns-ledger-for-local-dev/21505/3 "2023-07-19T14:21:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [July 19, 2023, 2:25pm UTC](https://forum.dfinity.org/t/how-to-interface-nns-ledger-for-local-dev/21505/4 "2023-07-19T14:25:27Z")

</div>

> [@dctech](#):
>
> but now i want to try local frontend → nns ledger. can it be done?

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.
