I am creating a React app and I want to integrate a connect wallet button that can then return the users wallet address, similar to JPEG.store. What is the best way to approach this. I tried using Cardano connect with wallet https://github.com/cardano-foundation/cardano-connect-with-wallet but I cant figure out how to return the users address after they have signed in with their wallet. Any help is appreciated.
1 Answer
This could be solved by variety of tools:
- Using Lucid, you can first enable (connect) with wallet as outlined in this simple example. Then get address via
lucid.wallet.address()
(it returns aPromise
, so you might need to useasync / await
). This address is basically obtained from CIP-30's,getUsedAddresses()
's first element. - Like what you have shared in question, Mesh has a prebuilt component for it, which can be seen here. Once connected, you can get address as mentioned in this page.
- Regarding library in question, can use
decodeHexAddress
on browser wallet api's,getUsedAddresses()
's first element.