After spending some days battling to implement Phantom + Anchor I found out about Solana's Wallet adapter. I sighed in relief thinking the end was nigh but:
- The the wallet adapter for Solana Apps is broken out-of-the-box due to some webpack dependency
- I haven't been able to adapt the example to Anchor
My current insights are that the Wallet Adapter at its cleanest allows a simple:
const { connection } = useConnection();
const { publicKey, sendTransaction } = useWallet();
With Anchor, the client side can then become:
const { connection } = useConnection()
const wallet = useAnchorWallet()
This guide seems to point in the right direction, yet it doesn't obviously bridge these two parts, leaving the WalletContextProvider
component found in the Wallet Adapter unused.
Questions and some answers
Q: Where does Anchor document its client-side usage?
A: Nor their old documentation nor their future documentation covers this process. By googling "project-serum/anchor" and following the links I found a scary looking reference on their git's readme. Also, by diving into the repos of coral-xyz
I also found a Anchor by example repo. None of these seem helpful.
I plan to over haul my strategy so that in the future I give up sooner on the documentation and instead inspire myself through open source implementations.
Q: Why do I even need Anchor in the front-end?
A: I am not sure! I believe it helps with the invocation of Solana Program's an the translation of data. But I'd prefer being more sure in order to better trust this code dependency.
Q: Do I just use
useAnchorWallet
forgetting thisWalletContextProvider
component?
A: I also don't know, the wallet adapter FAQ seems to imply this with:
Use the useAnchorWallet() hook in the React package to easily
get an Anchor-compatible Wallet interface.
Q: Do I need to
useState
to keep track of something like my wallet's public key or should I drop it completely and instead access it through these functions?
A: ...
Q: What advice do you have to more proficiently learn the ecosystem? Am I using the wrong tool-set?
Elaboration: This might be a issue in my workflow or maybe I underestimated the process of learning Web3, anyhow I'd greatly appreciate feedback on how to become more proficient. At the same time, this and other experiences have making me doubt developing in Solana. If I am to spend 2 weeks with each tiny thing, not being able to tell if the bug is my fault or not, my progress will be very slow.
The question in the title:
Q: How do I adapt Solana's Wallet Adapter example to use Anchor?
A: Because I have managed to adapt the example, I will answer in a post, even though I am dissatisfied with my lack of understanding.