This content originally appeared on DEV Community and was authored by Sharathxct
Working of my project wallet adapter for a web based wallet app which is a submission for 100xdev x Superteam hackathon.
Overview of my web based wallet
My wallet is a nextjs web app (Not extension), where users can create their solana wallet by logging in using google, a wallet automatically gets generated for the user after logging in and user can access the wallet only if they are signed in.Live, Github
NOTE: Private keys are stored on the server.
Working of my wallet adapter
My wallet adapter is an npm package which will be integrated by dapps to connect to my wallet, this basically exports my WalletAdapter class which extends BaseSignInMessageSignerWalletAdapter which contains the methods to perform connect, signTransaction etc. Go through solana walletadapter standard to know more. As my wallet now is web app and cannot inject code into other websites unlike web extension, I need to figure out how to make a communication connection between my wallet and the Solana dapps so that I do not give dapps the whole access to wallet instead make them just able to request connection or request signing of transaction etc.
After researching a bit I found this open source repository torus solana embed it uses a popup window to open their wallet in the window and take input from user if the user wants to approve or reject the request made by dapp client and now my question was how the wallet communicates with the dapp if user approved or rejected? then I found out about window.postMessage(). Parent window and window popups and iframes can communicate in real time using postMessage() method.
First i tried to implement iframe method then found out google login from iframe is not possible then implemented window popup and it worked.
Take a look at the live working example of how dapps can connect to my wallet here
Thank you Harkirat sir for 100xdevs, web3 cohort and the guidance.
This content originally appeared on DEV Community and was authored by Sharathxct
Sharathxct | Sciencx (2024-09-04T03:09:16+00:00) Solana: Wallet adapter for a web based wallet. Retrieved from https://www.scien.cx/2024/09/04/solana-wallet-adapter-for-a-web-based-wallet/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.